diff mbox

[v2] vhost_net: don't enable vring if backend lack this feature

Message ID 1474625046-19127-1-git-send-email-chen_han_xiao@126.com
State New
Headers show

Commit Message

Chen Hanxiao Sept. 23, 2016, 10:04 a.m. UTC
From: Chen Hanxiao <chenhanxiao@gmail.com>

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 <chenhanxiao@gmail.com>
---
v2: return 0 there if protocol features aren't negotiated.

 hw/net/vhost_net.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Michael S. Tsirkin Sept. 23, 2016, 3:33 p.m. UTC | #1
On Fri, Sep 23, 2016 at 06:04:06PM +0800, Chen Hanxiao wrote:
> From: Chen Hanxiao <chenhanxiao@gmail.com>
> 
> If backend(such as dpdk) lack the feather,

Sorry, I don't understand what does this mean.

> 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 <chenhanxiao@gmail.com>
> ---
> 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.

What does this mean?

> +         * If protocol features aren't negotiated, return 0 for back compat.

How do you mean "for back compat"?

> +         */
> +        if (ret == 0) {
> +            nc->vring_enable = enable;
> +        }
>      }


This clearly does not set vring_enable if vhost_set_vring_enable is
NULL.

>  
>      return 0;
> -- 
> 1.8.3.1
>
diff mbox

Patch

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;