From patchwork Mon Jan 26 03:20:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huawei Xie X-Patchwork-Id: 2513 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id B0F405AC5; Mon, 26 Jan 2015 04:21:50 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id CFE8D5ACD for ; Mon, 26 Jan 2015 04:21:46 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 25 Jan 2015 19:17:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,466,1418112000"; d="scan'208";a="642452782" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga001.jf.intel.com with ESMTP; 25 Jan 2015 19:21:45 -0800 Received: from shecgisg003.sh.intel.com (shecgisg003.sh.intel.com [10.239.29.90]) by shvmail01.sh.intel.com with ESMTP id t0Q3Lgjt015691; Mon, 26 Jan 2015 11:21:42 +0800 Received: from shecgisg003.sh.intel.com (localhost [127.0.0.1]) by shecgisg003.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t0Q3Lels029074; Mon, 26 Jan 2015 11:21:42 +0800 Received: (from hxie5@localhost) by shecgisg003.sh.intel.com (8.13.6/8.13.6/Submit) id t0Q3LexA029070; Mon, 26 Jan 2015 11:21:40 +0800 From: Huawei Xie To: dev@dpdk.org Date: Mon, 26 Jan 2015 11:20:39 +0800 Message-Id: <1422242440-28948-14-git-send-email-huawei.xie@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1422242440-28948-1-git-send-email-huawei.xie@intel.com> References: <1422242440-28948-1-git-send-email-huawei.xie@intel.com> Subject: [dpdk-dev] [RFC PATCH v2 13/14] multiple socket support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Signed-off-by: Huawei Xie --- 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 */