[dpdk-dev] [PATCH v2] vhost: provide vhost API to unregister vhost unix domain socket
rte_vhost_driver_unregister will remove the listenfd from event list, and then close it. Signed-off-by: Huawei Xie Signed-off-by: Peng Sun --- 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); - 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.ser
[dpdk-dev] [PATCH v2] vhost: provide vhost API to unregister vhost unix domain socket
On 6/5/2015 10:49 AM, Xie, Huawei wrote: > rte_vhost_driver_unregister will remove the listenfd from event list, and > then close it. > > Signed-off-by: Huawei Xie > Signed-off-by: Peng Sun > --- The v2 patch just fixes two lines of code style issue.
[dpdk-dev] [PATCH v2] vhost: provide vhost API to unregister vhost unix domain socket
rte_vhost_driver_unregister will remove the listenfd from event list, and then close it. Signed-off-by: Huawei Xie Signed-off-by: Peng Sun --- 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); - 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.ser
[dpdk-dev] [PATCH v2] vhost: provide vhost API to unregister vhost unix domain socket
Sorry, forget the --in-reply-to, please ignore this thread. On 6/5/2015 10:49 AM, Xie, Huawei wrote: > rte_vhost_driver_unregister will remove the listenfd from event list, and > then close it. > > Signed-off-by: Huawei Xie > Signed-off-by: Peng Sun > --- >
[dpdk-dev] [PATCH v2] vhost: provide vhost API to unregister vhost unix domain socket
> -Original Message- > From: Xie, Huawei > Sent: Friday, June 05, 2015 4:26 AM > To: dev at dpdk.org > Cc: Loftus, Ciara; Xie, Huawei; Sun, Peng A > Subject: [PATCH v2] vhost: provide vhost API to unregister vhost unix domain > socket > > rte_vhost_driver_unregister will remove the listenfd from event list, and > then close it. > > Signed-off-by: Huawei Xie > Signed-off-by: Peng Sun > --- > 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); > > - 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); >
[dpdk-dev] [PATCH v2] vhost: provide vhost API to unregister vhost unix domain socket
On 6/5/2015 5:04 PM, Loftus, Ciara wrote: > >> -Original Message- >> From: Xie, Huawei >> Sent: Friday, June 05, 2015 4:26 AM >> To: dev at dpdk.org >> Cc: Loftus, Ciara; Xie, Huawei; Sun, Peng A >> Subject: [PATCH v2] vhost: provide vhost API to unregister vhost unix domain >> socket >> >> rte_vhost_driver_unregister will remove the listenfd from event list, and >> then close it. >> >> Signed-off-by: Huawei Xie >> Signed-off-by: Peng Sun >> --- >> 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(-) >> >> > Acked-by: Ciara Loftus > > > Thomas: Comments to this patch? This patch will remove the socket file and associated listen fd. In future, I would also look at whether there is opportunity to attach a id to each vhost user net interface from QEMU. Currently DPDK OVS creates a socket file for each virtio device and use the file path as the id for the port. /huawei
[dpdk-dev] [PATCH v2] vhost: provide vhost API to unregister vhost unix domain socket
On 6/8/15 11:38 AM, Xie, Huawei wrote: > On 6/5/2015 5:04 PM, Loftus, Ciara wrote: >> >>> -Original Message- >>> From: Xie, Huawei >>> Sent: Friday, June 05, 2015 4:26 AM >>> To: dev at dpdk.org >>> Cc: Loftus, Ciara; Xie, Huawei; Sun, Peng A >>> Subject: [PATCH v2] vhost: provide vhost API to unregister vhost unix domain >>> socket >>> >>> rte_vhost_driver_unregister will remove the listenfd from event list, and >>> then close it. >>> >>> Signed-off-by: Huawei Xie >>> Signed-off-by: Peng Sun >>> --- >>> 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(-) >>> >>> >> Acked-by: Ciara Loftus >> >> >> > Thomas: > Comments to this patch? After reading the patch, it looks straight forward. I want to compile and run OVS/DPDK with vhost-user patch linked with DPDK with this patch applied first. I will respond when that is complete. > This patch will remove the socket file and associated listen fd. > In future, I would also look at whether there is opportunity to attach a > id to each vhost user net interface from QEMU. > Currently DPDK OVS creates a socket file for each virtio device and use > the file path as the id for the port. > > /huawei > >
[dpdk-dev] [PATCH v2] vhost: provide vhost API to unregister vhost unix domain socket
On 6/5/2015 5:04 PM, Loftus, Ciara wrote: > >> -Original Message- >> From: Xie, Huawei >> Sent: Friday, June 05, 2015 4:26 AM >> To: dev at dpdk.org >> Cc: Loftus, Ciara; Xie, Huawei; Sun, Peng A >> Subject: [PATCH v2] vhost: provide vhost API to unregister vhost unix domain >> socket >> >> rte_vhost_driver_unregister will remove the listenfd from event list, and >> then close it. >> >> Signed-off-by: Huawei Xie >> Signed-off-by: Peng Sun >> --- >> 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(-) >> [...] > Acked-by: Ciara Loftus Thomas: Comments to this patch?
[dpdk-dev] [PATCH v2] vhost: provide vhost API to unregister vhost unix domain socket
On 06/08/2015 06:38 PM, Xie, Huawei wrote: > On 6/5/2015 5:04 PM, Loftus, Ciara wrote: >> >>> -Original Message- >>> From: Xie, Huawei >>> Sent: Friday, June 05, 2015 4:26 AM >>> To: dev at dpdk.org >>> Cc: Loftus, Ciara; Xie, Huawei; Sun, Peng A >>> Subject: [PATCH v2] vhost: provide vhost API to unregister vhost unix domain >>> socket >>> >>> rte_vhost_driver_unregister will remove the listenfd from event list, and >>> then close it. >>> >>> Signed-off-by: Huawei Xie >>> Signed-off-by: Peng Sun >>> --- >>> 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(-) >>> You need to update the symbol version map when adding new public APIs. Something like: --- a/lib/librte_vhost/rte_vhost_version.map +++ b/lib/librte_vhost/rte_vhost_version.map @@ -13,3 +13,11 @@ DPDK_2.0 { local: *; }; + +DPDK_2.1 { + global: + + rte_vhost_driver_unregister; + + local: *; +}; - Panu -
[dpdk-dev] [PATCH v2] vhost: provide vhost API to unregister vhost unix domain socket
2015-06-05 11:26, Huawei Xie: > rte_vhost_driver_unregister will remove the listenfd from event list, and > then close it. > > Signed-off-by: Huawei Xie > Signed-off-by: Peng Sun > --- > 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 +- A function is added to the API without update of the .map file? Could it be used in a test or an example? It would prevent to break it or forget to add it in the .map.
[dpdk-dev] [PATCH v2] vhost: provide vhost API to unregister vhost unix domain socket
On 6/18/2015 5:02 AM, Thomas Monjalon wrote: > 2015-06-05 11:26, Huawei Xie: >> rte_vhost_driver_unregister will remove the listenfd from event list, and >> then close it. >> >> Signed-off-by: Huawei Xie >> Signed-off-by: Peng Sun >> --- >> 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 +- > A function is added to the API without update of the .map file? Get the comment from Panu. Would submit v3 patch. > > Could it be used in a test or an example? It would prevent to break > it or forget to add it in the .map. > Now in vhost example, we only register one socket and never unregister it. Would evaluate calling this API in vhost example in future. > >