From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id F2AEEA0471 for ; Wed, 19 Jun 2019 17:22:18 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0AA111C410; Wed, 19 Jun 2019 17:16:32 +0200 (CEST) Received: from mx0.arrikto.com (mx0.arrikto.com [212.71.252.59]) by dpdk.org (Postfix) with ESMTP id 8C4B31C396 for ; Wed, 19 Jun 2019 17:15:43 +0200 (CEST) Received: from troi.prod.arr (mail.arr [10.99.0.5]) by mx0.arrikto.com (Postfix) with ESMTP id 59A8D182015; Wed, 19 Jun 2019 18:15:43 +0300 (EEST) Received: from localhost.localdomain (unknown [10.89.50.133]) by troi.prod.arr (Postfix) with ESMTPSA id D5FE732C; Wed, 19 Jun 2019 18:15:42 +0300 (EEST) From: Nikos Dragazis To: dev@dpdk.org Cc: Maxime Coquelin , Tiwei Bie , Zhihong Wang , Stefan Hajnoczi , Wei Wang , Stojaczyk Dariusz , Vangelis Koukis Date: Wed, 19 Jun 2019 18:14:42 +0300 Message-Id: <1560957293-17294-18-git-send-email-ndragazis@arrikto.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560957293-17294-1-git-send-email-ndragazis@arrikto.com> References: <1560957293-17294-1-git-send-email-ndragazis@arrikto.com> Subject: [dpdk-dev] [PATCH 17/28] vhost: support registering additional vhost-user transports X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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