vhost_net: do not assume nvqs is always 2
authorJason Wang <jasowang@redhat.com>
Fri, 3 Sep 2021 09:10:15 +0000 (17:10 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Sat, 4 Sep 2021 21:34:05 +0000 (17:34 -0400)
This patch switches to initialize dev.nvqs from the VhostNetOptions
instead of assuming it was 2. This is useful for implementing control
virtqueue support which will be a single vhost_net structure with a
single cvq.

Note that nvqs is still set to 2 for all users and this patch does not
change functionality.

Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Eli Cohen <elic@nvidia.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20210903091031.47303-6-jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/net/vhost_net.c
include/net/vhost_net.h
net/tap.c
net/vhost-user.c
net/vhost-vdpa.c

index 6ed0c398369fa47f76ecba08e782953eafa0d781..386ec2eaa249f5790ff2d916bf2f2063da65257b 100644 (file)
@@ -165,9 +165,9 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
         goto fail;
     }
     net->nc = options->net_backend;
+    net->dev.nvqs = options->nvqs;
 
     net->dev.max_queues = 1;
-    net->dev.nvqs = 2;
     net->dev.vqs = net->vqs;
 
     if (backend_kernel) {
index 172b0051d8120cee3738e770e03cc330653ca0ad..fba40cf69509bc94637d79111977f373b9ad0e41 100644 (file)
@@ -14,6 +14,7 @@ typedef struct VhostNetOptions {
     VhostBackendType backend_type;
     NetClientState *net_backend;
     uint32_t busyloop_timeout;
+    unsigned int nvqs;
     void *opaque;
 } VhostNetOptions;
 
index f5686bbf771c4a6431d035172221674dba8e3c19..f716be3e3fba2383eddf8391c728ddc4938b6f17 100644 (file)
--- a/net/tap.c
+++ b/net/tap.c
@@ -749,6 +749,7 @@ static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
             qemu_set_nonblock(vhostfd);
         }
         options.opaque = (void *)(uintptr_t)vhostfd;
+        options.nvqs = 2;
 
         s->vhost_net = vhost_net_init(&options);
         if (!s->vhost_net) {
index 6adfcd623aa20a6d4a04ba6f59bc3fc06ca6036f..4a939124d247a307b4b7fab336480bf0ffec923f 100644 (file)
@@ -85,6 +85,7 @@ static int vhost_user_start(int queues, NetClientState *ncs[],
         options.net_backend = ncs[i];
         options.opaque      = be;
         options.busyloop_timeout = 0;
+        options.nvqs = 2;
         net = vhost_net_init(&options);
         if (!net) {
             error_report("failed to init vhost_net for queue %d", i);
index 72829884d740d055823c5f979054619091b11d24..395117debd57d6dbd2492182e9afa9f2e9df3aa9 100644 (file)
@@ -104,6 +104,7 @@ static int vhost_vdpa_add(NetClientState *ncs, void *be)
     options.net_backend = ncs;
     options.opaque      = be;
     options.busyloop_timeout = 0;
+    options.nvqs = 2;
 
     net = vhost_net_init(&options);
     if (!net) {