Update vhost_net_virtqueue_reset() for vhost-user scenario.
In order to reuse some functions, we process the idx for
vhost-user scenario because vhost_get_vq_index behave
differently for vhost-user.
Signed-off-by: Kangjie Xu <kangjie.xu@linux.alibaba.com>
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
hw/net/vhost_net.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index c0c1456172..8ad5743f7c 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -522,19 +522,28 @@ void vhost_net_virtqueue_reset(VirtIODevice *vdev, NetClientState *nc,
VHostNetState *net = get_vhost_net(nc->peer);
const VhostOps *vhost_ops = net->dev.vhost_ops;
struct vhost_vring_file file = { .fd = -1 };
- int idx;
+ struct vhost_vring_state state;
+ int idx, r;
/* should only be called after backend is connected */
assert(vhost_ops);
idx = vhost_ops->vhost_get_vq_index(&net->dev, vq_index);
+ if (net->nc->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
+ idx -= net->dev.vq_index;
+ }
if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
file.index = idx;
- int r = vhost_net_set_backend(&net->dev, &file);
+ r = vhost_net_set_backend(&net->dev, &file);
assert(r >= 0);
}
+ if (vhost_ops->vhost_reset_vring) {
+ state.index = net->dev.vq_index + idx;
+ r = vhost_ops->vhost_reset_vring(&net->dev, &state);
+ }
+
vhost_virtqueue_unmap(&net->dev, vdev, net->dev.vqs + idx, idx);
}
--
2.32.0