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 7C1BF1B349 for ; Fri, 19 Jan 2018 14:45:58 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D646880478; Fri, 19 Jan 2018 13:45:57 +0000 (UTC) Received: from localhost (ovpn-116-254.ams2.redhat.com [10.36.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 671805D6B2; Fri, 19 Jan 2018 13:45:57 +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:28 +0000 Message-Id: <20180119134444.24927-9-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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 19 Jan 2018 13:45:57 +0000 (UTC) Subject: [dpdk-dev] [RFC 08/24] vhost: move vhost_user.fdset to trans_af_unix.c 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:59 -0000 The fdset is used by the AF_UNIX transport code but other transports may not need it. Move it to trans_af_unix.c and then make struct vhost_user private again since nothing outside socket.c needs it. Signed-off-by: Stefan Hajnoczi --- lib/librte_vhost/vhost.h | 15 --------------- lib/librte_vhost/socket.c | 21 +++++++-------------- lib/librte_vhost/trans_af_unix.c | 25 +++++++++++++++++++++---- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index 8f18c1ed0..45167b6a7 100644 --- a/lib/librte_vhost/vhost.h +++ b/lib/librte_vhost/vhost.h @@ -19,7 +19,6 @@ #include #include -#include "fd_man.h" #include "rte_vhost.h" /* Used to indicate that the device is running on a data core */ @@ -302,10 +301,6 @@ struct virtio_net { int slave_req_fd; } __rte_cache_aligned; -/* The vhost_user and vhost_user_socket declarations are temporary measures for - * moving AF_UNIX code into trans_af_unix.c. They will be cleaned up as - * socket.c is untangled from trans_af_unix.c. - */ /* * Every time rte_vhost_driver_register() is invoked, an associated * vhost_user_socket struct will be created. @@ -336,16 +331,6 @@ struct vhost_user_socket { struct vhost_transport_ops const *trans_ops; }; -#define MAX_VHOST_SOCKET 1024 -struct vhost_user { - struct vhost_user_socket *vsockets[MAX_VHOST_SOCKET]; - struct fdset fdset; - int vsocket_cnt; - pthread_mutex_t mutex; -}; - -extern struct vhost_user vhost_user; - #define VHOST_LOG_PAGE 4096 /* diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index f9069fcb1..c46328950 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -20,12 +20,14 @@ #include "vhost.h" #include "vhost_user.h" +#define MAX_VHOST_SOCKET 1024 +struct vhost_user { + struct vhost_user_socket *vsockets[MAX_VHOST_SOCKET]; + int vsocket_cnt; + pthread_mutex_t mutex; +}; + struct vhost_user vhost_user = { - .fdset = { - .fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} }, - .fd_mutex = PTHREAD_MUTEX_INITIALIZER, - .num = 0 - }, .vsocket_cnt = 0, .mutex = PTHREAD_MUTEX_INITIALIZER, }; @@ -265,7 +267,6 @@ int rte_vhost_driver_start(const char *path) { struct vhost_user_socket *vsocket; - static pthread_t fdset_tid; pthread_mutex_lock(&vhost_user.mutex); vsocket = find_vhost_user_socket(path); @@ -274,13 +275,5 @@ rte_vhost_driver_start(const char *path) if (!vsocket) return -1; - if (fdset_tid == 0) { - int ret = pthread_create(&fdset_tid, NULL, fdset_event_dispatch, - &vhost_user.fdset); - if (ret != 0) - RTE_LOG(ERR, VHOST_CONFIG, - "failed to create fdset handling thread"); - } - return vsocket->trans_ops->socket_start(vsocket); } diff --git a/lib/librte_vhost/trans_af_unix.c b/lib/librte_vhost/trans_af_unix.c index ad07a8e24..54c1b2db3 100644 --- a/lib/librte_vhost/trans_af_unix.c +++ b/lib/librte_vhost/trans_af_unix.c @@ -39,11 +39,18 @@ #include +#include "fd_man.h" #include "vhost.h" #include "vhost_user.h" #define MAX_VIRTIO_BACKLOG 128 +static struct fdset af_unix_fdset = { + .fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} }, + .fd_mutex = PTHREAD_MUTEX_INITIALIZER, + .num = 0 +}; + TAILQ_HEAD(vhost_user_connection_list, vhost_user_connection); struct vhost_user_connection { @@ -195,7 +202,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket) conn->connfd = fd; conn->vsocket = vsocket; conn->vid = vid; - ret = fdset_add(&vhost_user.fdset, fd, vhost_user_read_cb, + ret = fdset_add(&af_unix_fdset, fd, vhost_user_read_cb, NULL, conn); if (ret < 0) { RTE_LOG(ERR, VHOST_CONFIG, @@ -316,7 +323,7 @@ vhost_user_start_server(struct vhost_user_socket *vsocket) if (ret < 0) goto err; - ret = fdset_add(&vhost_user.fdset, fd, vhost_user_server_new_connection, + ret = fdset_add(&af_unix_fdset, fd, vhost_user_server_new_connection, NULL, vsocket); if (ret < 0) { RTE_LOG(ERR, VHOST_CONFIG, @@ -551,7 +558,7 @@ af_unix_socket_cleanup(struct vhost_user_socket *vsocket) struct vhost_user_connection *conn, *next; if (vsocket->is_server) { - fdset_del(&vhost_user.fdset, s->socket_fd); + fdset_del(&af_unix_fdset, s->socket_fd); close(s->socket_fd); unlink(vsocket->path); } else if (vsocket->reconnect) { @@ -564,7 +571,7 @@ af_unix_socket_cleanup(struct vhost_user_socket *vsocket) conn = next) { next = TAILQ_NEXT(conn, next); - fdset_del(&vhost_user.fdset, conn->connfd); + fdset_del(&af_unix_fdset, conn->connfd); RTE_LOG(INFO, VHOST_CONFIG, "free connfd = %d for device '%s'\n", conn->connfd, vsocket->path); @@ -581,6 +588,16 @@ af_unix_socket_cleanup(struct vhost_user_socket *vsocket) static int af_unix_socket_start(struct vhost_user_socket *vsocket) { + static pthread_t fdset_tid; + + if (fdset_tid == 0) { + int ret = pthread_create(&fdset_tid, NULL, fdset_event_dispatch, + &af_unix_fdset); + if (ret != 0) + RTE_LOG(ERR, VHOST_CONFIG, + "failed to create fdset handling thread"); + } + if (vsocket->is_server) return vhost_user_start_server(vsocket); else -- 2.14.3