[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 12/24] vhost-net: vhost-kernel: introduce vhost_net_virtqueue_
From: |
Kangjie Xu |
Subject: |
[PATCH v2 12/24] vhost-net: vhost-kernel: introduce vhost_net_virtqueue_restart() |
Date: |
Tue, 16 Aug 2022 09:06:24 +0800 |
Introduce vhost_net_virtqueue_restart(), which can restart the
virtqueue when the vhost net started running before. If it fails
to restart the virtqueue, the device will be stopped.
This patch only considers the case for vhost-kernel, when
NetClientDriver is NET_CLIENT_DRIVER_TAP.
Signed-off-by: Kangjie Xu <kangjie.xu@linux.alibaba.com>
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
hw/net/vhost_net.c | 48 +++++++++++++++++++++++++++++++++++++++++
include/net/vhost_net.h | 2 ++
2 files changed, 50 insertions(+)
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index aa60dd901c..2ab67e875e 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -535,3 +535,51 @@ void vhost_net_virtqueue_stop(VirtIODevice *vdev,
NetClientState *nc,
vhost_dev_virtqueue_stop(&net->dev, vdev, idx);
}
+
+int vhost_net_virtqueue_restart(VirtIODevice *vdev, NetClientState *nc,
+ int vq_index)
+{
+ VHostNetState *net = get_vhost_net(nc->peer);
+ const VhostOps *vhost_ops = net->dev.vhost_ops;
+ struct vhost_vring_file file = { };
+ int idx, r;
+
+ if (!net->dev.started) {
+ return 0;
+ }
+
+ assert(vhost_ops);
+
+ idx = vhost_ops->vhost_get_vq_index(&net->dev, vq_index);
+
+ r = vhost_dev_virtqueue_restart(&net->dev, vdev, idx);
+ if (r < 0) {
+ goto err_start;
+ }
+
+ if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
+ file.index = idx;
+ file.fd = net->backend;
+ r = vhost_net_set_backend(&net->dev, &file);
+ if (r < 0) {
+ r = -errno;
+ goto err_start;
+ }
+ }
+
+ return 0;
+
+err_start:
+ error_report("Error when restarting the queue.");
+
+ if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
+ file.fd = -1;
+ file.index = idx;
+ int r = vhost_net_set_backend(&net->dev, &file);
+ assert(r >= 0);
+ }
+
+ vhost_dev_stop(&net->dev, vdev);
+
+ return r;
+}
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index 9b3aaf3814..e11a297380 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -50,4 +50,6 @@ int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu);
void vhost_net_virtqueue_stop(VirtIODevice *vdev, NetClientState *nc,
int vq_index);
+int vhost_net_virtqueue_restart(VirtIODevice *vdev, NetClientState *nc,
+ int vq_index);
#endif
--
2.32.0
- Re: [PATCH v2 11/24] vhost-net: vhost-kernel: introduce vhost_net_virtqueue_stop(), (continued)
[PATCH v2 14/24] vhost-user: introduce vhost_reset_vring() interface, Kangjie Xu, 2022/08/15
[PATCH v2 05/24] virtio: core: vq reset feature negotation support, Kangjie Xu, 2022/08/15
[PATCH v2 02/24] virtio: introduce __virtio_queue_reset(), Kangjie Xu, 2022/08/15
[PATCH v2 12/24] vhost-net: vhost-kernel: introduce vhost_net_virtqueue_restart(),
Kangjie Xu <=
[PATCH v2 13/24] docs: vhost-user: add VHOST_USER_RESET_VRING message, Kangjie Xu, 2022/08/15
[PATCH v2 15/24] vhost-user: add op to enable or disable a single vring, Kangjie Xu, 2022/08/15