[dpdk-dev] [RFC 1/2] vhost-user: don't allocate new queue once device is running

Maxime Coquelin maxime.coquelin at redhat.com
Fri Jan 12 16:50:15 CET 2018


Once the device is created, it is not possible to hot-add new
queues. If it happens, it could confuse the application, as
the new queue might not be initialized but nr_vring is
incremented.

Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
---
 lib/librte_vhost/vhost_user.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index e54795a41..f94fd16cf 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -1220,13 +1220,23 @@ vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, VhostUserMsg *msg)
 	if (vring_idx >= VHOST_MAX_VRING) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"invalid vring index: %u\n", vring_idx);
-		return -1;
+		return -EINVAL;
 	}
 
 	if (dev->virtqueue[vring_idx])
 		return 0;
 
-	return alloc_vring_queue(dev, vring_idx);
+	/* Queues cannot be added dynamically */
+	if (dev->flags & VIRTIO_DEV_RUNNING) {
+		RTE_LOG(DEBUG, VHOST_CONFIG,
+				"Cannot allocate new queue, device is running\n");
+		return -EPERM;
+	}
+
+	if (alloc_vring_queue(dev, vring_idx) < 0)
+		return -ENOMEM;
+
+	return 0;
 }
 
 int
@@ -1274,7 +1284,10 @@ vhost_user_msg_handler(int vid, int fd)
 			vhost_message_str[msg.request.master]);
 
 	ret = vhost_user_check_and_alloc_queue_pair(dev, &msg);
-	if (ret < 0) {
+	if (ret == -EPERM) {
+		RTE_LOG(DEBUG, VHOST_CONFIG, "Skipping message\n");
+			goto out;
+	} else if (ret < 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"failed to alloc queue\n");
 		return -1;
@@ -1383,6 +1396,7 @@ vhost_user_msg_handler(int vid, int fd)
 
 	}
 
+out:
 	if (msg.flags & VHOST_USER_NEED_REPLY) {
 		msg.payload.u64 = !!ret;
 		msg.size = sizeof(msg.payload.u64);
-- 
2.14.3



More information about the dev mailing list