[dpdk-dev] [RFC 07/24] vhost: move vhost_user_reconnect_init() into trans_af_unix.c

Stefan Hajnoczi stefanha at redhat.com
Fri Jan 19 14:44:27 CET 2018


The socket reconnection code is highly specific to AF_UNIX, so move the
remaining pieces of it into trans_af_unix.c.

Signed-off-by: Stefan Hajnoczi <stefanha at redhat.com>
---
 lib/librte_vhost/vhost.h         | 10 +++-------
 lib/librte_vhost/socket.c        |  4 ----
 lib/librte_vhost/trans_af_unix.c |  9 +++++++--
 3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index 734a8721d..8f18c1ed0 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -302,9 +302,9 @@ struct virtio_net {
 	int			slave_req_fd;
 } __rte_cache_aligned;
 
-/* The vhost_user, vhost_user_socket, and reconnect 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.
+/* 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
@@ -346,10 +346,6 @@ struct vhost_user {
 
 extern struct vhost_user vhost_user;
 
-extern pthread_t reconn_tid;
-
-int vhost_user_reconnect_init(void);
-
 #define VHOST_LOG_PAGE	4096
 
 /*
diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
index 4fd86fd5b..f9069fcb1 100644
--- a/lib/librte_vhost/socket.c
+++ b/lib/librte_vhost/socket.c
@@ -177,10 +177,6 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
 
 	if ((flags & RTE_VHOST_USER_CLIENT) != 0) {
 		vsocket->reconnect = !(flags & RTE_VHOST_USER_NO_RECONNECT);
-		if (vsocket->reconnect && reconn_tid == 0) {
-			if (vhost_user_reconnect_init() != 0)
-				goto out_free;
-		}
 	} else {
 		vsocket->is_server = true;
 	}
diff --git a/lib/librte_vhost/trans_af_unix.c b/lib/librte_vhost/trans_af_unix.c
index 747fd9690..ad07a8e24 100644
--- a/lib/librte_vhost/trans_af_unix.c
+++ b/lib/librte_vhost/trans_af_unix.c
@@ -347,7 +347,7 @@ struct vhost_user_reconnect_list {
 };
 
 static struct vhost_user_reconnect_list reconn_list;
-pthread_t reconn_tid;
+static pthread_t reconn_tid;
 
 static int
 vhost_user_connect_nonblock(int fd, struct sockaddr *un, size_t sz)
@@ -417,7 +417,7 @@ vhost_user_client_reconnect(void *arg __rte_unused)
 	return NULL;
 }
 
-int
+static int
 vhost_user_reconnect_init(void)
 {
 	int ret;
@@ -527,6 +527,11 @@ af_unix_socket_init(struct vhost_user_socket *vsocket,
 		container_of(vsocket, struct af_unix_socket, socket);
 	int ret;
 
+	if (vsocket->reconnect && reconn_tid == 0) {
+		if (vhost_user_reconnect_init() != 0)
+			return -1;
+	}
+
 	TAILQ_INIT(&s->conn_list);
 	ret = pthread_mutex_init(&s->conn_mutex, NULL);
 	if (ret) {
-- 
2.14.3



More information about the dev mailing list