Skip to content

Commit 049eb15

Browse files
jasowangmstsirkin
authored andcommitted
vhost: record the last virtqueue index for the virtio device
This patch introduces a new field in the vhost_dev structure to record the last virtqueue index for the virtio device. This will be useful for the vhost backends with 1:N model to start or stop the device after all the vhost_dev structures were started or stopped. Signed-off-by: Jason Wang <[email protected]> Message-Id: <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 441537f commit 049eb15

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

hw/net/vhost_net.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,11 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
231231
return NULL;
232232
}
233233

234-
static void vhost_net_set_vq_index(struct vhost_net *net, int vq_index)
234+
static void vhost_net_set_vq_index(struct vhost_net *net, int vq_index,
235+
int last_index)
235236
{
236237
net->dev.vq_index = vq_index;
238+
net->dev.last_index = last_index;
237239
}
238240

239241
static int vhost_net_start_one(struct vhost_net *net,
@@ -324,9 +326,13 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
324326
VirtIONet *n = VIRTIO_NET(dev);
325327
int nvhosts = data_queue_pairs + cvq;
326328
struct vhost_net *net;
327-
int r, e, i;
329+
int r, e, i, last_index = data_qps * 2;
328330
NetClientState *peer;
329331

332+
if (!cvq) {
333+
last_index -= 1;
334+
}
335+
330336
if (!k->set_guest_notifiers) {
331337
error_report("binding does not support guest notifiers");
332338
return -ENOSYS;
@@ -341,7 +347,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
341347
}
342348

343349
net = get_vhost_net(peer);
344-
vhost_net_set_vq_index(net, i * 2);
350+
vhost_net_set_vq_index(net, i * 2, last_index);
345351

346352
/* Suppress the masking guest notifiers on vhost user
347353
* because vhost user doesn't interrupt masking/unmasking

include/hw/virtio/vhost.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ struct vhost_dev {
7474
unsigned int nvqs;
7575
/* the first virtqueue which would be used by this vhost dev */
7676
int vq_index;
77+
/* the last vq index for the virtio device (not vhost) */
78+
int last_index;
7779
/* if non-zero, minimum required value for max_queues */
7880
int num_queues;
7981
uint64_t features;

0 commit comments

Comments
 (0)