DPDK patches and discussions
 help / color / mirror / Atom feed
From: Huawei Xie <huawei.xie@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [RFC PATCH v2 13/14] multiple socket support
Date: Mon, 26 Jan 2015 11:20:39 +0800	[thread overview]
Message-ID: <1422242440-28948-14-git-send-email-huawei.xie@intel.com> (raw)
In-Reply-To: <1422242440-28948-1-git-send-email-huawei.xie@intel.com>


Signed-off-by: Huawei Xie <huawei.xie@intel.com>
---
 lib/librte_vhost/vhost_user/vhost-net-user.c | 57 +++++++++++++++++++---------
 lib/librte_vhost/vhost_user/vhost-net-user.h |  1 -
 2 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index 71e5bbd..3a45a5e 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -54,7 +54,18 @@ static void vserver_new_vq_conn(int fd, void *data);
 static void vserver_message_handler(int fd, void *dat);
 struct vhost_net_device_ops const *ops;
 
-static struct vhost_server *g_vhost_server;
+struct connfd_ctx {
+	struct vhost_server *vserver;
+	uint32_t fh;
+};
+
+#define MAX_VHOST_SERVER 1024
+static struct {
+	struct vhost_server *server[MAX_VHOST_SERVER];
+	struct fdset fdset;	/**< The fd list this vhost server manages. */
+} g_vhost_server;
+
+static int vserver_idx;
 
 static const char *vhost_message_str[VHOST_USER_MAX] = {
 	[VHOST_USER_NONE] = "VHOST_USER_NONE",
@@ -251,6 +262,7 @@ vserver_new_vq_conn(int fd, void *dat)
 {
 	struct vhost_server *vserver = (struct vhost_server *)dat;
 	int conn_fd;
+	struct connfd_ctx *ctx;
 	int fh;
 	struct vhost_device_ctx vdev_ctx = { 0 };
 
@@ -260,15 +272,24 @@ vserver_new_vq_conn(int fd, void *dat)
 	if (conn_fd < 0)
 		return;
 
+	ctx = calloc(1, sizeof(*ctx));
+	if (ctx == NULL) {
+		close(conn_fd);
+		return;
+	}
+
 	fh = ops->new_device(vdev_ctx);
 	if (fh == -1) {
+		free(ctx);
 		close(conn_fd);
 		return;
 	}
 	RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", fh);
 
-	fdset_add(&vserver->fdset,
-		conn_fd, vserver_message_handler, NULL, (void *)fh);
+	ctx->vserver = vserver;
+	ctx->fh = fh;
+	fdset_add(&g_vhost_server.fdset,
+		conn_fd, vserver_message_handler, NULL, ctx);
 }
 
 /* callback when there is message on the connfd */
@@ -276,19 +297,20 @@ static void
 vserver_message_handler(int connfd, void *dat)
 {
 	struct vhost_device_ctx ctx;
-	uint32_t fh = (uint32_t)dat;
+	struct connfd_ctx *cfd_ctx = (struct connfd_ctx *)dat;
 	struct VhostUserMsg msg;
 	uint64_t features;
 	int ret;
 
-	ctx.fh = fh;
+	ctx.fh = cfd_ctx->fh;
 	ret = read_vhost_message(connfd, &msg);
 	if (ret < 0) {
 		RTE_LOG(ERR, VHOST_CONFIG,
 			"vhost read message failed\n");
 
 		close(connfd);
-		fdset_del(&g_vhost_server->fdset, connfd);
+		fdset_del(&g_vhost_server.fdset, connfd);
+		free(cfd_ctx);
 		user_destroy_device(ctx);
 		ops->destroy_device(ctx);
 
@@ -298,7 +320,8 @@ vserver_message_handler(int connfd, void *dat)
 			"vhost peer closed\n");
 
 		close(connfd);
-		fdset_del(&g_vhost_server->fdset, connfd);
+		fdset_del(&g_vhost_server.fdset, connfd);
+		free(cfd_ctx);
 		user_destroy_device(ctx);
 		ops->destroy_device(ctx);
 
@@ -309,7 +332,8 @@ vserver_message_handler(int connfd, void *dat)
 			"vhost read incorrect message\n");
 
 		close(connfd);
-		fdset_del(&g_vhost_server->fdset, connfd);
+		fdset_del(&g_vhost_server.fdset, connfd);
+		free(cfd_ctx);
 		user_destroy_device(ctx);
 		ops->destroy_device(ctx);
 
@@ -390,18 +414,19 @@ vserver_message_handler(int connfd, void *dat)
 int
 rte_vhost_driver_register(const char *path)
 {
-
 	struct vhost_server *vserver;
 
-	if (g_vhost_server != NULL)
+	if (vserver_idx == 0) {
+		fdset_init(&g_vhost_server.fdset);
+		ops = get_virtio_net_callbacks();
+	}
+	if (vserver_idx == MAX_VHOST_SERVER)
 		return -1;
 
 	vserver = calloc(sizeof(struct vhost_server), 1);
 	if (vserver == NULL)
 		return -1;
 
-	fdset_init(&vserver->fdset);
-
 	unlink(path);
 
 	vserver->listenfd = uds_socket(path);
@@ -411,13 +436,11 @@ rte_vhost_driver_register(const char *path)
 	}
 	vserver->path = path;
 
-	fdset_add(&vserver->fdset, vserver->listenfd,
+	fdset_add(&g_vhost_server.fdset, vserver->listenfd,
 		vserver_new_vq_conn, NULL,
 		vserver);
 
-	ops = get_virtio_net_callbacks();
-
-	g_vhost_server = vserver;
+	g_vhost_server.server[vserver_idx++] = vserver;
 
 	return 0;
 }
@@ -426,7 +449,7 @@ rte_vhost_driver_register(const char *path)
 int
 rte_vhost_driver_session_start(void)
 {
-	fdset_event_dispatch(&g_vhost_server->fdset);
+	fdset_event_dispatch(&g_vhost_server.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 91e8fc3..e2a91a9 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.h
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.h
@@ -43,7 +43,6 @@
 struct vhost_server {
 	const char *path; /**< The path the uds is bind to. */
 	int listenfd;     /**< The listener sockfd. */
-	struct fdset fdset; /**< The fd list this vhost server manages. */
 };
 
 /* refer to hw/virtio/vhost-user.c */
-- 
1.8.1.4

  parent reply	other threads:[~2015-01-26  3:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-26  3:20 [dpdk-dev] [RFC PATCH v2 00/14] qemu vhost-user support Huawei Xie
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 01/14] enable VIRTIO_NET_F_CTRL_RX VIRTIO_NET_F_CTRL_RX is dependant on VIRTIO_NET_F_CTRL_VQ. Observed that virtio-net driver in guest would crash with only CTRL_RX enabled Huawei Xie
2015-01-30 11:59   ` Linhaifeng
2015-01-31 15:24     ` Xie, Huawei
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 02/14] create vhost_cuse sub-directory create vhost_cuse directory move vhost-net-cdev.c to vhost_cuse directory Huawei Xie
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 03/14] rename vhost-net-cdev.h to vhost-net.h Huawei Xie
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 04/14] consistent print style Huawei Xie
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 05/14] implement eventfd copying(from fd in qemu process to fd in vhost process) in vhost-net-cdev.c Huawei Xie
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 06/14] copy host_memory_map from virtio-net.c to a new file virtio-net-cdev.c Huawei Xie
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 07/14] host_memory_map Huawei Xie
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 08/14] split set_memory_table into two parts Huawei Xie
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 09/14] add select based event driven fd management logic Huawei Xie
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 10/14] vhost user support Huawei Xie
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 11/14] vhost user memory region map Huawei Xie
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 12/14] cleanup when vhost user connection is closed Huawei Xie
2015-01-26  3:20 ` Huawei Xie [this message]
2015-01-26  3:20 ` [dpdk-dev] [RFC PATCH v2 14/14] vhost user ifr_name support Huawei Xie
2015-02-09  7:52 ` [dpdk-dev] [RFC PATCH v2 00/14] qemu vhost-user support Linhaifeng

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=1422242440-28948-14-git-send-email-huawei.xie@intel.com \
    --to=huawei.xie@intel.com \
    --cc=dev@dpdk.org \
    /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).