From: Thomas Monjalon <thomas.monjalon@6wind.com>
To: "Xie, Huawei" <huawei.xie@intel.com>
Cc: dev@dpdk.org
Subject: Re: [dpdk-dev] [PATCH v3 1/2] vhost: vhost unix domain socket cleanup
Date: Mon, 29 Jun 2015 23:02:26 +0200 [thread overview]
Message-ID: <4036087.qsYtaox4HE@xps13> (raw)
In-Reply-To: <C37D651A908B024F974696C65296B57B0F5467C9@SHSMSX101.ccr.corp.intel.com>
Huawei,
I don't understand this reply. You forgot quoting, you didn't remove useless lines,
and you seem to reply to yourself.
Should this patch be applied?
2015-06-29 18:28, Xie, Huawei:
> On 6/19/2015 1:40 AM, Huawei Xie wrote:
>
> rte_vhost_driver_unregister API will remove the listenfd for the specified path from event processing list, and then close it.
>
> v2 changes:
> -minor code style fix: remove unnecessary new line
>
> Signed-off-by: Huawei Xie <huawei.xie@intel.com><mailto:huawei.xie@intel.com>
> Signed-off-by: Peng Sun <peng.a.sun@intel.com><mailto:peng.a.sun@intel.com>
> ---
> lib/librte_vhost/rte_virtio_net.h | 3 ++
> lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 9 ++++
> lib/librte_vhost/vhost_user/vhost-net-user.c | 68 +++++++++++++++++++++++-----
> lib/librte_vhost/vhost_user/vhost-net-user.h | 2 +-
> 4 files changed, 69 insertions(+), 13 deletions(-)
>
> diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
> index 5d38185..5630fbc 100644
> --- a/lib/librte_vhost/rte_virtio_net.h
> +++ b/lib/librte_vhost/rte_virtio_net.h
> @@ -188,6 +188,9 @@ int rte_vhost_enable_guest_notification(struct virtio_net *dev, uint16_t queue_i
> /* Register vhost driver. dev_name could be different for multiple instance support. */
> int rte_vhost_driver_register(const char *dev_name);
>
> +/* Unregister vhost driver. This is only meaningful to vhost user. */
> +int rte_vhost_driver_unregister(const char *dev_name);
> +
> /* Register callbacks. */
> int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * const);
> /* Start vhost driver session blocking loop. */
> diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
> index 6b68abf..1ae7c49 100644
> --- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
> +++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
> @@ -405,6 +405,15 @@ rte_vhost_driver_register(const char *dev_name)
> }
>
> /**
> + * An empty function for unregister
> + */
> +int
> +rte_vhost_driver_unregister(const char *dev_name __rte_unused)
> +{
> + return 0;
> +}
> +
> +/**
> * The CUSE session is launched allowing the application to receive open,
> * release and ioctl calls.
> */
> diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
> index 31f1215..87a4711 100644
> --- a/lib/librte_vhost/vhost_user/vhost-net-user.c
> +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
> @@ -66,6 +66,8 @@ struct connfd_ctx {
> struct _vhost_server {
> struct vhost_server *server[MAX_VHOST_SERVER];
> struct fdset fdset;
> + int vserver_cnt;
> + pthread_mutex_t server_mutex;
> };
>
> static struct _vhost_server g_vhost_server = {
> @@ -74,10 +76,10 @@ static struct _vhost_server g_vhost_server = {
> .fd_mutex = PTHREAD_MUTEX_INITIALIZER,
> .num = 0
> },
> + .vserver_cnt = 0,
> + .server_mutex = PTHREAD_MUTEX_INITIALIZER,
> };
>
> -static int vserver_idx;
> -
> static const char *vhost_message_str[VHOST_USER_MAX] = {
> [VHOST_USER_NONE] = "VHOST_USER_NONE",
> [VHOST_USER_GET_FEATURES] = "VHOST_USER_GET_FEATURES",
> @@ -427,7 +429,6 @@ vserver_message_handler(int connfd, void *dat, int *remove)
> }
> }
>
> -
> /**
> * Creates and initialise the vhost server.
> */
> @@ -436,34 +437,77 @@ rte_vhost_driver_register(const char *path)
> {
> struct vhost_server *vserver;
>
> - if (vserver_idx == 0)
> + pthread_mutex_lock(&g_vhost_server.server_mutex);
> + if (ops == NULL)
> ops = get_virtio_net_callbacks();
> - if (vserver_idx == MAX_VHOST_SERVER)
> +
> + if (g_vhost_server.vserver_cnt == MAX_VHOST_SERVER) {
> + RTE_LOG(ERR, VHOST_CONFIG,
> + "error: the number of servers reaches maximum\n");
> + pthread_mutex_unlock(&g_vhost_server.server_mutex);
> return -1;
> + }
>
> vserver = calloc(sizeof(struct vhost_server), 1);
> - if (vserver == NULL)
> + if (vserver == NULL) {
> + pthread_mutex_unlock(&g_vhost_server.server_mutex);
> return -1;
> -
> - unlink(path);
> + }
>
> vserver->listenfd = uds_socket(path);
> if (vserver->listenfd < 0) {
> free(vserver);
> + pthread_mutex_unlock(&g_vhost_server.server_mutex);
> return -1;
> }
> - vserver->path = path;
> +
> + vserver->path = strdup(path);
>
> fdset_add(&g_vhost_server.fdset, vserver->listenfd,
> - vserver_new_vq_conn, NULL,
> - vserver);
> + vserver_new_vq_conn, NULL, vserver);
>
>
> In fd_man.c, in the event handler for connection fd, the fd could be closed when receives no data.
> Before the following code snippet, as it isn't protected, there is chance we register the listenfd with the value of the just closed fd.
> so the following fdset_del could wrongly remove the new listenfd.
> would use fdset_del_slot to delete entry at fixed slot.
>
> if (remove1 || remove2)
> fdset_del(pfdset, fd);
>
>
> another thing is when select is blocked, rte_vhost_driver_unregister/register could remove/refill entries of some listenfd(s!!!).
> There is potential unwanted call on new listenfds, it is not a issue. would add comment to emphasize that.
>
>
>
>
>
>
> - g_vhost_server.server[vserver_idx++] = vserver;
> + g_vhost_server.server[g_vhost_server.vserver_cnt++] = vserver;
> + pthread_mutex_unlock(&g_vhost_server.server_mutex);
>
> return 0;
> }
>
>
> +/**
> + * Unregister the specified vhost server
> + */
> +int
> +rte_vhost_driver_unregister(const char *path)
> +{
> + int i;
> + int count;
> +
> + pthread_mutex_lock(&g_vhost_server.server_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);
> +
> + close(g_vhost_server.server[i]->listenfd);
> + free(g_vhost_server.server[i]->path);
> + free(g_vhost_server.server[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);
> +
> + return 0;
> + }
> + }
> + pthread_mutex_unlock(&g_vhost_server.server_mutex);
> +
> + return -1;
> +}
> +
> int
> rte_vhost_driver_session_start(void)
> {
> diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.h b/lib/librte_vhost/vhost_user/vhost-net-user.h
> index 1b6be6c..2e72f3c 100644
> --- a/lib/librte_vhost/vhost_user/vhost-net-user.h
> +++ b/lib/librte_vhost/vhost_user/vhost-net-user.h
> @@ -41,7 +41,7 @@
> #include "fd_man.h"
>
> struct vhost_server {
> - const char *path; /**< The path the uds is bind to. */
> + char *path; /**< The path the uds is bind to. */
> int listenfd; /**< The listener sockfd. */
> };
>
>
>
next prev parent reply other threads:[~2015-06-29 21:03 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-02 1:50 [dpdk-dev] [PATCH] vhost: provide vhost API to unregister vhost unix domain socket Huawei Xie
2015-06-03 9:42 ` Loftus, Ciara
2015-06-03 12:55 ` Ouyang, Changchun
2015-06-03 19:03 ` Xie, Huawei
2015-06-05 3:26 ` [dpdk-dev] [PATCH v2] " Huawei Xie
2015-06-05 9:04 ` Loftus, Ciara
2015-06-08 15:38 ` Xie, Huawei
2015-06-08 20:25 ` Thomas F Herbert
2015-06-17 8:10 ` Panu Matilainen
2015-06-17 3:33 ` Xie, Huawei
2015-06-17 20:59 ` Thomas Monjalon
2015-06-18 1:40 ` Xie, Huawei
2015-06-18 17:40 ` [dpdk-dev] [PATCH v3 0/2] vhost: vhost unix domain socket cleanup Huawei Xie
2015-06-18 17:40 ` [dpdk-dev] [PATCH v3 1/2] " Huawei Xie
2015-06-29 18:28 ` Xie, Huawei
2015-06-29 21:02 ` Thomas Monjalon [this message]
2015-06-30 6:19 ` Xie, Huawei
2015-06-30 9:20 ` [dpdk-dev] [PATCH v4 0/4] " Huawei Xie
2015-06-30 9:20 ` [dpdk-dev] [PATCH v4 1/4] vhost: call fdset_del_slot to remove connection fd Huawei Xie
2015-07-01 2:14 ` Ouyang, Changchun
2015-06-30 9:20 ` [dpdk-dev] [PATCH v4 2/4] vhost: vhost unix domain socket cleanup Huawei Xie
2015-07-01 2:14 ` Ouyang, Changchun
2015-06-30 9:20 ` [dpdk-dev] [PATCH v4 3/4] vhost: version map file update Huawei Xie
2015-07-01 2:15 ` Ouyang, Changchun
2015-06-30 9:20 ` [dpdk-dev] [PATCH v4 4/4] vhost: add comment for potential unwanted callback on listenfds Huawei Xie
2015-07-01 2:15 ` Ouyang, Changchun
2015-06-30 15:55 ` [dpdk-dev] [PATCH v4 0/4] vhost: vhost unix domain socket cleanup Thomas Monjalon
2015-06-18 17:41 ` [dpdk-dev] [PATCH v3 2/2] vhost: version map file update Huawei Xie
2015-06-17 4:17 ` [dpdk-dev] [PATCH] vhost: provide vhost API to unregister vhost unix domain socket Tetsuya Mukawa
2015-06-17 11:05 ` Xie, Huawei
2015-06-18 1:00 ` Tetsuya Mukawa
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=4036087.qsYtaox4HE@xps13 \
--to=thomas.monjalon@6wind.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).