[22/28] vhost: add flag for choosing vhost-user transport

Message ID 1560957293-17294-23-git-send-email-ndragazis@arrikto.com
State New
Delegated to: Maxime Coquelin
Headers show
Series
  • vhost: add virtio-vhost-user transport
Related show

Checks

Context Check Description
ci/Intel-compilation fail Compilation issues
ci/checkpatch warning coding style issues

Commit Message

Nikos Dragazis June 19, 2019, 3:14 p.m.
Extend the <rte_vhost.h> API to support the virtio-vhost-user transport
as an alternative to the AF_UNIX transport.  The caller provides a PCI
DomBDF address:

  rte_vhost_driver_register("0000:00:04.0",
                            RTE_VHOST_USER_VIRTIO_TRANSPORT);

Signed-off-by: Nikos Dragazis <ndragazis@arrikto.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 drivers/virtio_vhost_user/trans_virtio_vhost_user.c |  4 ++++
 lib/librte_vhost/rte_vhost.h                        |  1 +
 lib/librte_vhost/socket.c                           | 19 ++++++++++++++++++-
 lib/librte_vhost/vhost.h                            |  6 +++++-
 4 files changed, 28 insertions(+), 2 deletions(-)

Patch

diff --git a/drivers/virtio_vhost_user/trans_virtio_vhost_user.c b/drivers/virtio_vhost_user/trans_virtio_vhost_user.c
index 45863bd..04dbbb1 100644
--- a/drivers/virtio_vhost_user/trans_virtio_vhost_user.c
+++ b/drivers/virtio_vhost_user/trans_virtio_vhost_user.c
@@ -979,6 +979,10 @@  vvu_pci_init(void)
 	}
 
 	rte_pci_register(&vvu_pci_driver);
+	if (rte_vhost_register_transport(VHOST_TRANSPORT_VVU, &virtio_vhost_user_trans_ops) < 0) {
+		RTE_LOG(ERR, VHOST_CONFIG,
+				"Registration of vhost-user transport (%d) failed\n", VHOST_TRANSPORT_VVU);
+	}
 }
 
 static int
diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h
index 0226b3e..0573238 100644
--- a/lib/librte_vhost/rte_vhost.h
+++ b/lib/librte_vhost/rte_vhost.h
@@ -29,6 +29,7 @@  extern "C" {
 #define RTE_VHOST_USER_DEQUEUE_ZERO_COPY	(1ULL << 2)
 #define RTE_VHOST_USER_IOMMU_SUPPORT	(1ULL << 3)
 #define RTE_VHOST_USER_POSTCOPY_SUPPORT		(1ULL << 4)
+#define RTE_VHOST_USER_VIRTIO_TRANSPORT	(1ULL << 5)
 
 /** Protocol features. */
 #ifndef VHOST_USER_PROTOCOL_F_MQ
diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
index fe1c78d..1295fdd 100644
--- a/lib/librte_vhost/socket.c
+++ b/lib/librte_vhost/socket.c
@@ -327,7 +327,16 @@  rte_vhost_driver_register(const char *path, uint64_t flags)
 			goto out;
 	}
 
-	trans_ops = g_transport_map[VHOST_TRANSPORT_UNIX];
+	if (flags & RTE_VHOST_USER_VIRTIO_TRANSPORT) {
+		trans_ops = g_transport_map[VHOST_TRANSPORT_VVU];
+		if (trans_ops == NULL) {
+			RTE_LOG(ERR, VHOST_CONFIG,
+					"virtio-vhost-user transport is not supported\n");
+			goto out;
+		}
+	} else {
+		trans_ops = g_transport_map[VHOST_TRANSPORT_UNIX];
+	}
 
 	if (!path)
 		return -1;
@@ -400,6 +409,14 @@  rte_vhost_driver_register(const char *path, uint64_t flags)
 			"Postcopy requested but not compiled\n");
 		ret = -1;
 		goto out_free;
+#else
+		if (flags & RTE_VHOST_USER_VIRTIO_TRANSPORT) {
+			RTE_LOG(ERR, VHOST_CONFIG,
+				"Postcopy requested but not supported "
+				"by the virtio-vhost-user transport\n");
+			ret = -1;
+			goto out_free;
+		}
 #endif
 	}
 
diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index 2e7eabe..a6131da 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -494,9 +494,13 @@  struct vhost_transport_ops {
 /** The traditional AF_UNIX vhost-user protocol transport. */
 extern const struct vhost_transport_ops af_unix_trans_ops;
 
+/** The virtio-vhost-user PCI vhost-user protocol transport. */
+extern const struct vhost_transport_ops virtio_vhost_user_trans_ops;
+
 typedef enum VhostUserTransport {
 	VHOST_TRANSPORT_UNIX = 0,
-	VHOST_TRANSPORT_MAX = 1
+	VHOST_TRANSPORT_VVU = 1,
+	VHOST_TRANSPORT_MAX = 2
 } VhostUserTransport;
 
 /* A list with all the available vhost-user transports. */