[dpdk-dev] [PATCH 2/9] vhost: refactor Virtio ready check
Maxime Coquelin
maxime.coquelin at redhat.com
Thu May 14 10:02:11 CEST 2020
This patch is a small refactoring, as preliminary work
for adding support to Virtio status support.
No functionnal change here.
Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
---
lib/librte_vhost/vhost.c | 1 +
lib/librte_vhost/vhost_user.c | 40 +++++++++++++++++++++--------------
2 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 0266318440..fd8ba1be2d 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -716,6 +716,7 @@ vhost_enable_dequeue_zero_copy(int vid)
return;
dev->dequeue_zero_copy = 1;
+ VHOST_LOG_CONFIG(INFO, "dequeue zero copy is enabled\n");
}
void
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index 106b6d7609..f5800bd9c1 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -1315,6 +1315,9 @@ virtio_is_ready(struct virtio_net *dev)
struct vhost_virtqueue *vq;
uint32_t i;
+ if (dev->flags & VIRTIO_DEV_READY)
+ return 1;
+
if (dev->nr_vring == 0)
return 0;
@@ -1325,8 +1328,11 @@ virtio_is_ready(struct virtio_net *dev)
return 0;
}
+ dev->flags |= VIRTIO_DEV_READY;
+
VHOST_LOG_CONFIG(INFO,
"virtio is now ready for processing.\n");
+
return 1;
}
@@ -2606,7 +2612,6 @@ vhost_user_msg_handler(int vid, int fd)
struct virtio_net *dev;
struct VhostUserMsg msg;
struct rte_vdpa_device *vdpa_dev;
- int did = -1;
int ret;
int unlock_required = 0;
bool handled;
@@ -2784,30 +2789,33 @@ vhost_user_msg_handler(int vid, int fd)
return -1;
}
- if (!(dev->flags & VIRTIO_DEV_READY) && virtio_is_ready(dev)) {
- dev->flags |= VIRTIO_DEV_READY;
+ if (!virtio_is_ready(dev))
+ goto out;
- if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
- if (dev->dequeue_zero_copy) {
- VHOST_LOG_CONFIG(INFO,
- "dequeue zero copy is enabled\n");
- }
+ /*
+ * Virtio is now ready. If not done already, it is time
+ * to notify the application it can process the rings and
+ * configure the vDPA device if present.
+ */
- if (dev->notify_ops->new_device(dev->vid) == 0)
- dev->flags |= VIRTIO_DEV_RUNNING;
- }
+ if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
+ if (dev->notify_ops->new_device(dev->vid) == 0)
+ dev->flags |= VIRTIO_DEV_RUNNING;
}
- did = dev->vdpa_dev_id;
- vdpa_dev = rte_vdpa_get_device(did);
- if (vdpa_dev && virtio_is_ready(dev) &&
- !(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) &&
- msg.request.master == VHOST_USER_SET_VRING_CALL) {
+ vdpa_dev = rte_vdpa_get_device(dev->vdpa_dev_id);
+ if (!vdpa_dev)
+ goto out;
+
+ if (!(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) &&
+ request == VHOST_USER_SET_VRING_CALL) {
if (vdpa_dev->ops->dev_conf)
vdpa_dev->ops->dev_conf(dev->vid);
+
dev->flags |= VIRTIO_DEV_VDPA_CONFIGURED;
}
+out:
return 0;
}
--
2.25.4
More information about the dev
mailing list