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 4067DA0471 for ; Wed, 19 Jun 2019 17:16:23 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 143141C39B; Wed, 19 Jun 2019 17:15:45 +0200 (CEST) Received: from mx0.arrikto.com (mx0.arrikto.com [212.71.252.59]) by dpdk.org (Postfix) with ESMTP id 9E8871C387 for ; Wed, 19 Jun 2019 17:15:37 +0200 (CEST) Received: from troi.prod.arr (mail.arr [10.99.0.5]) by mx0.arrikto.com (Postfix) with ESMTP id 56EE8182007; Wed, 19 Jun 2019 18:15:37 +0300 (EEST) Received: from localhost.localdomain (unknown [10.89.50.133]) by troi.prod.arr (Postfix) with ESMTPSA id D5A9D2B2; Wed, 19 Jun 2019 18:15:36 +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:28 +0300 Message-Id: <1560957293-17294-4-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 03/28] vhost: allocate per-socket transport state 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" From: Stefan Hajnoczi vhost-user transports have per-socket state (like file descriptors). Make it possible for transports to keep state beyond what is included in struct vhost_user_socket. This patch makes it possible to move AF_UNIX-specific fields from struct vhost_user_socket into trans_af_unix.c in later patches. Signed-off-by: Stefan Hajnoczi --- lib/librte_vhost/socket.c | 6 ++++-- lib/librte_vhost/trans_af_unix.c | 5 +++++ lib/librte_vhost/vhost.h | 9 +++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index a993b67..60d3546 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -316,6 +316,7 @@ 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; if (!path) return -1; @@ -328,10 +329,11 @@ rte_vhost_driver_register(const char *path, uint64_t flags) goto out; } - vsocket = malloc(sizeof(struct vhost_user_socket)); + vsocket = malloc(trans_ops->socket_size); if (!vsocket) goto out; - memset(vsocket, 0, sizeof(struct vhost_user_socket)); + memset(vsocket, 0, trans_ops->socket_size); + vsocket->trans_ops = trans_ops; vsocket->path = strdup(path); if (vsocket->path == NULL) { RTE_LOG(ERR, VHOST_CONFIG, diff --git a/lib/librte_vhost/trans_af_unix.c b/lib/librte_vhost/trans_af_unix.c index 89a5b7d..4de2579 100644 --- a/lib/librte_vhost/trans_af_unix.c +++ b/lib/librte_vhost/trans_af_unix.c @@ -13,6 +13,10 @@ #define MAX_VIRTIO_BACKLOG 128 +struct af_unix_socket { + struct vhost_user_socket socket; /* must be the first field! */ +}; + static void vhost_user_read_cb(int connfd, void *dat, int *remove); /* @@ -501,5 +505,6 @@ af_unix_vring_call(struct virtio_net *dev __rte_unused, } const struct vhost_transport_ops af_unix_trans_ops = { + .socket_size = sizeof(struct af_unix_socket), .vring_call = af_unix_vring_call, }; diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index c363369..9615392 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -296,6 +296,9 @@ struct virtio_net; * A structure containing function pointers for transport-specific operations. */ struct vhost_transport_ops { + /** Size of struct vhost_user_socket-derived per-socket state */ + size_t socket_size; + /** * Notify the guest that used descriptors have been added to the vring. * The VRING_AVAIL_F_NO_INTERRUPT flag and event idx have already been checked @@ -374,6 +377,11 @@ TAILQ_HEAD(vhost_user_connection_list, vhost_user_connection); /* * Every time rte_vhost_driver_register() is invoked, an associated * vhost_user_socket struct will be created. + * + * Transport-specific per-socket state can be kept by embedding this struct at + * the beginning of a transport-specific struct. Set + * vhost_transport_ops->socket_size to the size of the transport-specific + * struct. */ struct vhost_user_socket { struct vhost_user_connection_list conn_list; @@ -407,6 +415,7 @@ struct vhost_user_socket { int vdpa_dev_id; struct vhost_device_ops const *notify_ops; + struct vhost_transport_ops const *trans_ops; }; struct vhost_user_connection { -- 2.7.4