DPDK patches and discussions
 help / color / mirror / Atom feed
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: dev@dpdk.org
Cc: huawei.xie@intel.com, Yuanhan Liu <yuanhan.liu@linux.intel.com>
Subject: [dpdk-dev] [PATCH 1/6] vhost: rename structs for enabling client mode
Date: Fri,  6 May 2016 23:40:19 -0700	[thread overview]
Message-ID: <1462603224-29510-2-git-send-email-yuanhan.liu@linux.intel.com> (raw)
In-Reply-To: <1462603224-29510-1-git-send-email-yuanhan.liu@linux.intel.com>

DPDK vhost-user just acts as server so far, so, using a struct named
as "vhost_server" is okay. However, if we add the support of DPDK
vhost-user acting as client, it doesn't make sense any more. Here
rename it to "vhost_user_socket".

There was too much wrong for "connfd_ctx", but I think it's obviously
better to rename it to "vhost_user_connection", as it does represent
a connection, a connection between the backend (DPDK) and the frontend
(QEMU).

Similarly, few more renames are taken, such as "vserver_new_vq_conn"
to "vhost_user_new_connection".

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
 lib/librte_vhost/vhost_user/vhost-net-user.c | 131 ++++++++++++++-------------
 lib/librte_vhost/vhost_user/vhost-net-user.h |   6 --
 2 files changed, 70 insertions(+), 67 deletions(-)

diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index 68fc9b9..f485a3b 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -51,32 +51,41 @@
 #include "vhost-net.h"
 #include "virtio-net-user.h"
 
-#define MAX_VIRTIO_BACKLOG 128
-
-static void vserver_new_vq_conn(int fd, void *data, int *remove);
-static void vserver_message_handler(int fd, void *dat, int *remove);
+/*
+ * Every time rte_vhost_driver_register() is invoked, an associated
+ * vhost_user_socket struct will be created.
+ */
+struct vhost_user_socket {
+	char *path;
+	int listenfd;
+};
 
-struct connfd_ctx {
-	struct vhost_server *vserver;
+struct vhost_user_connection {
+	struct vhost_user_socket *vsocket;
 	int vid;
 };
 
-#define MAX_VHOST_SERVER 1024
-struct _vhost_server {
-	struct vhost_server *server[MAX_VHOST_SERVER];
+#define MAX_VHOST_SOCKET 1024
+struct vhost_user {
+	struct vhost_user_socket *vsockets[MAX_VHOST_SOCKET];
 	struct fdset fdset;
-	int vserver_cnt;
-	pthread_mutex_t server_mutex;
+	int vsocket_cnt;
+	pthread_mutex_t mutex;
 };
 
-static struct _vhost_server g_vhost_server = {
+#define MAX_VIRTIO_BACKLOG 128
+
+static void vhost_user_new_connection(int fd, void *data, int *remove);
+static void vhost_user_msg_handler(int fd, void *dat, int *remove);
+
+static struct vhost_user vhost_user = {
 	.fdset = {
 		.fd = { [0 ... MAX_FDS - 1] = {-1, NULL, NULL, NULL, 0} },
 		.fd_mutex = PTHREAD_MUTEX_INITIALIZER,
 		.num = 0
 	},
-	.vserver_cnt = 0,
-	.server_mutex = PTHREAD_MUTEX_INITIALIZER,
+	.vsocket_cnt = 0,
+	.mutex = PTHREAD_MUTEX_INITIALIZER,
 };
 
 static const char *vhost_message_str[VHOST_USER_MAX] = {
@@ -278,13 +287,13 @@ send_vhost_message(int sockfd, struct VhostUserMsg *msg)
 	return ret;
 }
 
-/* call back when there is new virtio connection.  */
+/* call back when there is new vhost-user connection.  */
 static void
-vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
+vhost_user_new_connection(int fd, void *dat, int *remove __rte_unused)
 {
-	struct vhost_server *vserver = (struct vhost_server *)dat;
+	struct vhost_user_socket *vsocket = dat;
 	int conn_fd;
-	struct connfd_ctx *ctx;
+	struct vhost_user_connection *conn;
 	int vid;
 	unsigned int size;
 
@@ -294,41 +303,41 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
 	if (conn_fd < 0)
 		return;
 
-	ctx = calloc(1, sizeof(*ctx));
-	if (ctx == NULL) {
+	conn = calloc(1, sizeof(*conn));
+	if (conn == NULL) {
 		close(conn_fd);
 		return;
 	}
 
 	vid = vhost_new_device();
 	if (vid == -1) {
-		free(ctx);
+		free(conn);
 		close(conn_fd);
 		return;
 	}
 
-	size = strnlen(vserver->path, PATH_MAX);
-	vhost_set_ifname(vid, vserver->path, size);
+	size = strnlen(vsocket->path, PATH_MAX);
+	vhost_set_ifname(vid, vsocket->path, size);
 
 	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid);
 
-	ctx->vserver = vserver;
-	ctx->vid = vid;
-	fdset_add(&g_vhost_server.fdset,
-		conn_fd, vserver_message_handler, NULL, ctx);
+	conn->vsocket = vsocket;
+	conn->vid = vid;
+	fdset_add(&vhost_user.fdset,
+		conn_fd, vhost_user_msg_handler, NULL, conn);
 }
 
 /* callback when there is message on the connfd */
 static void
-vserver_message_handler(int connfd, void *dat, int *remove)
+vhost_user_msg_handler(int connfd, void *dat, int *remove)
 {
 	int vid;
-	struct connfd_ctx *cfd_ctx = (struct connfd_ctx *)dat;
+	struct vhost_user_connection *conn = dat;
 	struct VhostUserMsg msg;
 	uint64_t features;
 	int ret;
 
-	vid = cfd_ctx->vid;
+	vid = conn->vid;
 	ret = read_vhost_message(connfd, &msg);
 	if (ret <= 0 || msg.request >= VHOST_USER_MAX) {
 		if (ret < 0)
@@ -343,7 +352,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 
 		close(connfd);
 		*remove = 1;
-		free(cfd_ctx);
+		free(conn);
 		vhost_destroy_device(vid);
 
 		return;
@@ -449,37 +458,37 @@ vserver_message_handler(int connfd, void *dat, int *remove)
 int
 rte_vhost_driver_register(const char *path)
 {
-	struct vhost_server *vserver;
+	struct vhost_user_socket *vsocket;
 
-	pthread_mutex_lock(&g_vhost_server.server_mutex);
+	pthread_mutex_lock(&vhost_user.mutex);
 
-	if (g_vhost_server.vserver_cnt == MAX_VHOST_SERVER) {
+	if (vhost_user.vsocket_cnt == MAX_VHOST_SOCKET) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"error: the number of servers reaches maximum\n");
-		pthread_mutex_unlock(&g_vhost_server.server_mutex);
+		pthread_mutex_unlock(&vhost_user.mutex);
 		return -1;
 	}
 
-	vserver = calloc(sizeof(struct vhost_server), 1);
-	if (vserver == NULL) {
-		pthread_mutex_unlock(&g_vhost_server.server_mutex);
+	vsocket = calloc(sizeof(struct vhost_user_socket), 1);
+	if (vsocket == NULL) {
+		pthread_mutex_unlock(&vhost_user.mutex);
 		return -1;
 	}
 
-	vserver->listenfd = uds_socket(path);
-	if (vserver->listenfd < 0) {
-		free(vserver);
-		pthread_mutex_unlock(&g_vhost_server.server_mutex);
+	vsocket->listenfd = uds_socket(path);
+	if (vsocket->listenfd < 0) {
+		free(vsocket);
+		pthread_mutex_unlock(&vhost_user.mutex);
 		return -1;
 	}
 
-	vserver->path = strdup(path);
+	vsocket->path = strdup(path);
 
-	fdset_add(&g_vhost_server.fdset, vserver->listenfd,
-		vserver_new_vq_conn, NULL, vserver);
+	fdset_add(&vhost_user.fdset, vsocket->listenfd,
+		vhost_user_new_connection, NULL, vsocket);
 
-	g_vhost_server.server[g_vhost_server.vserver_cnt++] = vserver;
-	pthread_mutex_unlock(&g_vhost_server.server_mutex);
+	vhost_user.vsockets[vhost_user.vsocket_cnt++] = vsocket;
+	pthread_mutex_unlock(&vhost_user.mutex);
 
 	return 0;
 }
@@ -494,28 +503,28 @@ rte_vhost_driver_unregister(const char *path)
 	int i;
 	int count;
 
-	pthread_mutex_lock(&g_vhost_server.server_mutex);
+	pthread_mutex_lock(&vhost_user.mutex);
 
-	for (i = 0; i < g_vhost_server.vserver_cnt; i++) {
-		if (!strcmp(g_vhost_server.server[i]->path, path)) {
-			fdset_del(&g_vhost_server.fdset,
-				g_vhost_server.server[i]->listenfd);
+	for (i = 0; i < vhost_user.vsocket_cnt; i++) {
+		if (!strcmp(vhost_user.vsockets[i]->path, path)) {
+			fdset_del(&vhost_user.fdset,
+				vhost_user.vsockets[i]->listenfd);
 
-			close(g_vhost_server.server[i]->listenfd);
-			free(g_vhost_server.server[i]->path);
-			free(g_vhost_server.server[i]);
+			close(vhost_user.vsockets[i]->listenfd);
+			free(vhost_user.vsockets[i]->path);
+			free(vhost_user.vsockets[i]);
 
 			unlink(path);
 
-			count = --g_vhost_server.vserver_cnt;
-			g_vhost_server.server[i] = g_vhost_server.server[count];
-			g_vhost_server.server[count] = NULL;
-			pthread_mutex_unlock(&g_vhost_server.server_mutex);
+			count = --vhost_user.vsocket_cnt;
+			vhost_user.vsockets[i] = vhost_user.vsockets[count];
+			vhost_user.vsockets[count] = NULL;
+			pthread_mutex_unlock(&vhost_user.mutex);
 
 			return 0;
 		}
 	}
-	pthread_mutex_unlock(&g_vhost_server.server_mutex);
+	pthread_mutex_unlock(&vhost_user.mutex);
 
 	return -1;
 }
@@ -523,6 +532,6 @@ rte_vhost_driver_unregister(const char *path)
 int
 rte_vhost_driver_session_start(void)
 {
-	fdset_event_dispatch(&g_vhost_server.fdset);
+	fdset_event_dispatch(&vhost_user.fdset);
 	return 0;
 }
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.h b/lib/librte_vhost/vhost_user/vhost-net-user.h
index e3bb413..d902595 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.h
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.h
@@ -38,12 +38,6 @@
 #include <linux/vhost.h>
 
 #include "rte_virtio_net.h"
-#include "fd_man.h"
-
-struct vhost_server {
-	char *path; /**< The path the uds is bind to. */
-	int listenfd;     /**< The listener sockfd. */
-};
 
 /* refer to hw/virtio/vhost-user.c */
 
-- 
1.9.0

  reply	other threads:[~2016-05-07  6:36 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-07  6:40 [dpdk-dev] [PATCH 0/6] vhost: add vhost-user client mode and reconnect ability Yuanhan Liu
2016-05-07  6:40 ` Yuanhan Liu [this message]
2016-05-07  6:40 ` [dpdk-dev] [PATCH 2/6] vhost: add vhost-user client mode Yuanhan Liu
2016-05-09 10:33   ` Victor Kaplansky
2016-05-09 20:33     ` Yuanhan Liu
2016-05-09 20:30       ` Michael S. Tsirkin
2016-05-07  6:40 ` [dpdk-dev] [PATCH 3/6] vhost: add reconnect ability Yuanhan Liu
2016-05-09 16:47   ` Xie, Huawei
2016-05-09 18:12     ` Yuanhan Liu
2016-05-10  7:24       ` Xie, Huawei
2016-05-10  7:54         ` Michael S. Tsirkin
2016-05-10  8:07           ` Xie, Huawei
2016-05-10  8:42             ` Michael S. Tsirkin
2016-05-10  9:00               ` Xie, Huawei
2016-05-10  9:17                 ` Michael S. Tsirkin
2016-05-10 17:17                   ` Loftus, Ciara
2016-05-11 21:46                     ` Michael S. Tsirkin
2016-05-07  6:40 ` [dpdk-dev] [PATCH 4/6] vhost: workaround stale vring base Yuanhan Liu
2016-05-09 10:45   ` Victor Kaplansky
2016-05-09 13:39     ` Xie, Huawei
2016-05-09 18:23       ` Yuanhan Liu
2016-05-09 12:19   ` Michael S. Tsirkin
2016-05-09 16:25   ` Xie, Huawei
2016-05-09 18:22     ` Yuanhan Liu
2016-06-13 20:47       ` Michael S. Tsirkin
2016-05-10  8:21   ` Xie, Huawei
2016-05-07  6:40 ` [dpdk-dev] [PATCH 5/6] examples/vhost: add client and reconnect option Yuanhan Liu
2016-05-09 10:47   ` Victor Kaplansky
2016-05-07  6:40 ` [dpdk-dev] [PATCH 6/6] vhost: add pmd " Yuanhan Liu
2016-05-09 10:54   ` Victor Kaplansky
2016-05-09 18:26     ` Yuanhan Liu
2016-05-10  3:23 ` [dpdk-dev] [PATCH 0/6] vhost: add vhost-user client mode and reconnect ability Xu, Qian Q
2016-05-10 17:41   ` Yuanhan Liu
2016-05-13  6:16 ` [dpdk-dev] [PATCH v2 " Yuanhan Liu
2016-05-13  6:16   ` [dpdk-dev] [PATCH v2 1/6] vhost: rename structs for enabling client mode Yuanhan Liu
2016-05-13  6:16   ` [dpdk-dev] [PATCH v2 2/6] vhost: add vhost-user " Yuanhan Liu
2016-05-13  6:16   ` [dpdk-dev] [PATCH v2 3/6] vhost: add reconnect ability Yuanhan Liu
2016-05-13  6:16   ` [dpdk-dev] [PATCH v2 4/6] vhost: workaround stale vring base Yuanhan Liu
2016-05-13  6:16   ` [dpdk-dev] [PATCH v2 5/6] examples/vhost: add client and reconnect option Yuanhan Liu
2016-05-13  6:16   ` [dpdk-dev] [PATCH v2 6/6] vhost: add pmd " Yuanhan Liu
2016-05-25 17:45     ` Rich Lane
2016-05-26  8:01       ` Yuanhan Liu
2016-06-07  4:05   ` [dpdk-dev] [PATCH v3 0/6] vhost: add vhost-user client mode and reconnect ability Yuanhan Liu
2016-06-07  4:05     ` [dpdk-dev] [PATCH v3 1/6] vhost: rename structs for enabling client mode Yuanhan Liu
2016-06-07  4:05     ` [dpdk-dev] [PATCH v3 2/6] vhost: add vhost-user " Yuanhan Liu
2016-06-07  4:05     ` [dpdk-dev] [PATCH v3 3/6] vhost: add reconnect ability Yuanhan Liu
2016-06-07  4:05     ` [dpdk-dev] [PATCH v3 4/6] vhost: workaround stale vring base Yuanhan Liu
2016-06-07  4:05     ` [dpdk-dev] [PATCH v3 5/6] examples/vhost: add client option Yuanhan Liu
2016-06-07  4:05     ` [dpdk-dev] [PATCH v3 6/6] vhost: add pmd " Yuanhan Liu
2016-06-14 12:00     ` [dpdk-dev] [PATCH v3 0/6] vhost: add vhost-user client mode and reconnect ability Yuanhan Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462603224-29510-2-git-send-email-yuanhan.liu@linux.intel.com \
    --to=yuanhan.liu@linux.intel.com \
    --cc=dev@dpdk.org \
    --cc=huawei.xie@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).