diff mbox

[1/3] virtio-9p-coth: add release function and fix init error path

Message ID 20151005090716.20420.21354.stgit@bahia.huguette.org
State New
Headers show

Commit Message

Greg Kurz Oct. 5, 2015, 9:07 a.m. UTC
This is preliminary work to support hotplug/unplug of virtio-9p-device.

Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
---
 hw/9pfs/virtio-9p-coth.c |   13 +++++++++----
 hw/9pfs/virtio-9p-coth.h |    1 +
 2 files changed, 10 insertions(+), 4 deletions(-)

Comments

Greg Kurz Oct. 6, 2015, 9:16 a.m. UTC | #1
On Mon, 05 Oct 2015 11:07:16 +0200
Greg Kurz <gkurz@linux.vnet.ibm.com> wrote:

> This is preliminary work to support hotplug/unplug of virtio-9p-device.
> 
> Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> ---

Hmm... still not good. Since this is shared by all virtio-9p devices, we need
at least a refcount.

>  hw/9pfs/virtio-9p-coth.c |   13 +++++++++----
>  hw/9pfs/virtio-9p-coth.h |    1 +
>  2 files changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/9pfs/virtio-9p-coth.c b/hw/9pfs/virtio-9p-coth.c
> index 8185c533c013..a4392586c9a2 100644
> --- a/hw/9pfs/virtio-9p-coth.c
> +++ b/hw/9pfs/virtio-9p-coth.c
> @@ -66,10 +66,7 @@ int v9fs_init_worker_threads(void)
>      }
>      p->completed = g_async_queue_new();
>      if (!p->completed) {
> -        /*
> -         * We are going to terminate.
> -         * So don't worry about cleanup
> -         */
> +        g_thread_pool_free(p->pool, true, true);
>          ret = -1;
>          goto err_out;
>      }
> @@ -80,3 +77,11 @@ err_out:
>      pthread_sigmask(SIG_SETMASK, &oldset, NULL);
>      return ret;
>  }
> +
> +int v9fs_release_worker_threads(void)
> +{
> +        V9fsThPool *p = &v9fs_pool;
> +
> +        g_thread_pool_free(p->pool, TRUE, TRUE);
> +        g_async_queue_unref(p->completed);
> +}
> diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
> index 4f51b250d1d4..6502e422cea8 100644
> --- a/hw/9pfs/virtio-9p-coth.h
> +++ b/hw/9pfs/virtio-9p-coth.h
> @@ -56,6 +56,7 @@ typedef struct V9fsThPool {
> 
>  extern void co_run_in_worker_bh(void *);
>  extern int v9fs_init_worker_threads(void);
> +extern int v9fs_release_worker_threads(void);
>  extern int v9fs_co_readlink(V9fsPDU *, V9fsPath *, V9fsString *);
>  extern int v9fs_co_readdir_r(V9fsPDU *, V9fsFidState *,
>                             struct dirent *, struct dirent **result);
> 
>
diff mbox

Patch

diff --git a/hw/9pfs/virtio-9p-coth.c b/hw/9pfs/virtio-9p-coth.c
index 8185c533c013..a4392586c9a2 100644
--- a/hw/9pfs/virtio-9p-coth.c
+++ b/hw/9pfs/virtio-9p-coth.c
@@ -66,10 +66,7 @@  int v9fs_init_worker_threads(void)
     }
     p->completed = g_async_queue_new();
     if (!p->completed) {
-        /*
-         * We are going to terminate.
-         * So don't worry about cleanup
-         */
+        g_thread_pool_free(p->pool, true, true);
         ret = -1;
         goto err_out;
     }
@@ -80,3 +77,11 @@  err_out:
     pthread_sigmask(SIG_SETMASK, &oldset, NULL);
     return ret;
 }
+
+int v9fs_release_worker_threads(void)
+{
+        V9fsThPool *p = &v9fs_pool;
+
+        g_thread_pool_free(p->pool, TRUE, TRUE);
+        g_async_queue_unref(p->completed);
+}
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 4f51b250d1d4..6502e422cea8 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -56,6 +56,7 @@  typedef struct V9fsThPool {
 
 extern void co_run_in_worker_bh(void *);
 extern int v9fs_init_worker_threads(void);
+extern int v9fs_release_worker_threads(void);
 extern int v9fs_co_readlink(V9fsPDU *, V9fsPath *, V9fsString *);
 extern int v9fs_co_readdir_r(V9fsPDU *, V9fsFidState *,
                            struct dirent *, struct dirent **result);