Received: from eggs.gnu.org ([2001:4830:134:3::10]:42592) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnNLj-0003GG-J4 for qemu-devel@nongnu.org; Fri, 23 Sep 2016 06:04:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bnNLd-00071x-Gn for qemu-devel@nongnu.org; Fri, 23 Sep 2016 06:04:54 -0400 Received: from m15-112.126.com ([220.181.15.112]:35646) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnNLc-0006zU-4s for qemu-devel@nongnu.org; Fri, 23 Sep 2016 06:04:49 -0400 From: Chen Hanxiao Date: Fri, 23 Sep 2016 18:04:06 +0800 Message-Id: <1474625046-19127-1-git-send-email-chen_han_xiao@126.com> Subject: [Qemu-devel] [PATCH v2] vhost_net: don't enable vring if backend lack this feature List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org, Jason Wang , Chen Hanxiao From: Chen Hanxiao If backend(such as dpdk) lack the feather, don't assume it in vring_enable. Or we may fail in vhost_net_start, then we can't use vhost. This will bring compat issue with old version backend. Signed-off-by: Chen Hanxiao --- v2: return 0 there if protocol features aren't negotiated. hw/net/vhost_net.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index f2d49ad..a1b796a 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -425,11 +425,17 @@ int vhost_set_vring_enable(NetClientState *nc, int enable) { VHostNetState *net = get_vhost_net(nc); const VhostOps *vhost_ops = net->dev.vhost_ops; - - nc->vring_enable = enable; + int ret; if (vhost_ops && vhost_ops->vhost_set_vring_enable) { - return vhost_ops->vhost_set_vring_enable(&net->dev, enable); + ret = vhost_ops->vhost_set_vring_enable(&net->dev, enable); + /* + * Try to enable vring feature. + * If protocol features aren't negotiated, return 0 for back compat. + */ + if (ret == 0) { + nc->vring_enable = enable; + } } return 0; -- 1.8.3.1