From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 677111B319 for ; Fri, 19 Jan 2018 14:45:21 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C275C85A04; Fri, 19 Jan 2018 13:45:20 +0000 (UTC) Received: from localhost (ovpn-116-254.ams2.redhat.com [10.36.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8A277FD56; Fri, 19 Jan 2018 13:45:00 +0000 (UTC) From: Stefan Hajnoczi To: dev@dpdk.org Cc: maxime.coquelin@redhat.com, Yuanhan Liu , wei.w.wang@intel.com, mst@redhat.com, zhiyong.yang@intel.com, jasowang@redhat.com, Stefan Hajnoczi Date: Fri, 19 Jan 2018 13:44:23 +0000 Message-Id: <20180119134444.24927-4-stefanha@redhat.com> In-Reply-To: <20180119134444.24927-1-stefanha@redhat.com> References: <20180119134444.24927-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 19 Jan 2018 13:45:20 +0000 (UTC) Subject: [dpdk-dev] [RFC 03/24] 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: , X-List-Received-Date: Fri, 19 Jan 2018 13:45:21 -0000 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/vhost.h | 9 +++++++++ lib/librte_vhost/socket.c | 6 ++++-- lib/librte_vhost/trans_af_unix.c | 5 +++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 8c6d6e524..e5279a572 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -210,6 +210,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 has already been checked so this @@ -273,6 +276,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; @@ -296,6 +304,7 @@ struct vhost_user_socket { uint64_t features; struct vhost_device_ops const *notify_ops; + struct vhost_transport_ops const *trans_ops; }; struct vhost_user_connection { diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index d681f9cae..fffffc663 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -128,6 +128,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; @@ -140,10 +141,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 636f69916..5e3c5ab2a 100644 --- a/lib/librte_vhost/trans_af_unix.c +++ b/lib/librte_vhost/trans_af_unix.c @@ -42,6 +42,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); /* return bytes# of read on success or negative val on failure. */ @@ -496,5 +500,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, }; -- 2.14.3