[dpdk-dev] [PATCH 17/28] vhost: support registering additional vhost-user transports

Nikos Dragazis ndragazis at arrikto.com
Wed Jun 19 17:14:42 CEST 2019


This patch introduces a global transport map which will hold pointers to
the transport-specific operations of all the available transports.
The AF_UNIX transport is supported by default. More transports can be
hooked up by implementing struct vhost_transport_ops and registering
this structure to the global transport map table. A new transport can be
registered with rte_vhost_register_transport(), which is part of
librtre_vhost public API.

This patch also exports vhost.h and vhost_user.h and some private
functions as part of librte_vhost public API. This allows implementing
vhost-user transports outside of lib/librte_vhost/.

Signed-off-by: Nikos Dragazis <ndragazis at arrikto.com>
---
 lib/librte_vhost/Makefile              |  2 +-
 lib/librte_vhost/rte_vhost_version.map | 11 +++++++++++
 lib/librte_vhost/socket.c              | 26 +++++++++++++++++++++++++-
 lib/librte_vhost/vhost.h               | 22 ++++++++++++++++++++++
 4 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/lib/librte_vhost/Makefile b/lib/librte_vhost/Makefile
index 5ff5fb2..4f867ec 100644
--- a/lib/librte_vhost/Makefile
+++ b/lib/librte_vhost/Makefile
@@ -26,7 +26,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c iotlb.c socket.c vhost.c \
 					vhost_user.c virtio_net.c vdpa.c trans_af_unix.c
 
 # install includes
-SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_vhost.h rte_vdpa.h
+SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += vhost.h vhost_user.h rte_vhost.h rte_vdpa.h
 
 # only compile vhost crypto when cryptodev is enabled
 ifeq ($(CONFIG_RTE_LIBRTE_CRYPTODEV),y)
diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map
index 5f1d4a7..9eda81f 100644
--- a/lib/librte_vhost/rte_vhost_version.map
+++ b/lib/librte_vhost/rte_vhost_version.map
@@ -60,6 +60,17 @@ DPDK_18.02 {
 
 } DPDK_17.08;
 
+DPDK_19.05 {
+	global:
+
+	rte_vhost_register_transport;
+	vhost_destroy_device;
+	vhost_new_device;
+	vhost_set_ifname;
+	vhost_user_msg_handler;
+
+} DPDK_18.02;
+
 EXPERIMENTAL {
 	global:
 
diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
index fc78b63..fe1c78d 100644
--- a/lib/librte_vhost/socket.c
+++ b/lib/librte_vhost/socket.c
@@ -317,7 +317,17 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
 {
 	int ret = -1;
 	struct vhost_user_socket *vsocket;
-	const struct vhost_transport_ops *trans_ops = &af_unix_trans_ops;
+	const struct vhost_transport_ops *trans_ops;
+
+	/* Register the AF_UNIX vhost-user transport in the transport map.
+	 * The AF_UNIX transport is supported by default.
+	 */
+	if (g_transport_map[VHOST_TRANSPORT_UNIX] == NULL) {
+		if (rte_vhost_register_transport(VHOST_TRANSPORT_UNIX, &af_unix_trans_ops) < 0)
+			goto out;
+	}
+
+	trans_ops = g_transport_map[VHOST_TRANSPORT_UNIX];
 
 	if (!path)
 		return -1;
@@ -495,3 +505,17 @@ rte_vhost_driver_start(const char *path)
 
 	return vsocket->trans_ops->socket_start(vsocket);
 }
+
+int
+rte_vhost_register_transport(VhostUserTransport trans,
+		const struct vhost_transport_ops *trans_ops)
+{
+	if (trans >= VHOST_TRANSPORT_MAX) {
+		RTE_LOG(ERR, VHOST_CONFIG,
+			"Invalid vhost-user transport %d\n", trans);
+		return -1;
+	}
+
+	g_transport_map[trans] = trans_ops;
+	return 0;
+}
diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index f5d6dc8..aba8d9b 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -493,6 +493,28 @@ struct vhost_transport_ops {
 /** The traditional AF_UNIX vhost-user protocol transport. */
 extern const struct vhost_transport_ops af_unix_trans_ops;
 
+typedef enum VhostUserTransport {
+	VHOST_TRANSPORT_UNIX = 0,
+	VHOST_TRANSPORT_MAX = 1
+} VhostUserTransport;
+
+/* A list with all the available vhost-user transports. */
+const struct vhost_transport_ops *g_transport_map[VHOST_TRANSPORT_MAX];
+
+/**
+ * Register a new vhost-user transport in the transport map.
+ *
+ * @param trans
+ *  the transport that is going to be registered
+ * @param trans_ops
+ *  the transport operations supported by this transport
+ * @return
+ *  0 on success, -1 on failure
+ * */
+int
+rte_vhost_register_transport(VhostUserTransport trans,
+                const struct vhost_transport_ops *trans_ops);
+
 /**
  * Device structure contains all configuration information relating
  * to the device.
-- 
2.7.4



More information about the dev mailing list