qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] libvhost-user-glib: fix VugDev main fd cleanup


From: Marc-André Lureau
Subject: Re: [Qemu-devel] [PATCH] libvhost-user-glib: fix VugDev main fd cleanup
Date: Tue, 27 Aug 2019 14:47:48 +0400

Hi

On Tue, Aug 27, 2019 at 12:32 PM Johannes Berg
<address@hidden> wrote:
>
> From: Johannes Berg <address@hidden>
>
> If you try to make a device implementation that can handle multiple
> connections and allow disconnections (which requires overriding the
> VHOST_USER_NONE handling), then glib will warn that we remove a src
> while it's still on the mainloop, and will poll() an FD that doesn't
> exist anymore.
>
> Fix this by just using the internal add_watch() function that has
> all necessary cleanups built in via the hashtable, rather than
> treating the "main" fd of a device specially.

It would be easier to see a backtrace of the error (under gdb with
G_DEBUG=fatal_criticals)

>
> Fixes: 8bb7ddb78a1c ("libvhost-user: add glib source helper")
> Signed-off-by: Johannes Berg <address@hidden>
> ---
>  contrib/libvhost-user/libvhost-user-glib.c | 3 +--
>  contrib/libvhost-user/libvhost-user-glib.h | 1 -
>  2 files changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/contrib/libvhost-user/libvhost-user-glib.c 
> b/contrib/libvhost-user/libvhost-user-glib.c
> index 99edd2f3de45..a092a55c1d57 100644
> --- a/contrib/libvhost-user/libvhost-user-glib.c
> +++ b/contrib/libvhost-user/libvhost-user-glib.c
> @@ -146,7 +146,7 @@ vug_init(VugDev *dev, uint16_t max_queues, int socket,
>      dev->fdmap = g_hash_table_new_full(NULL, NULL, NULL,
>                                         (GDestroyNotify) g_source_destroy);
>
> -    dev->src = vug_source_new(dev, socket, G_IO_IN, vug_watch, NULL);
> +    set_watch(&dev->parent, socket, VU_WATCH_IN, vug_watch, NULL);
>
>      return true;
>  }
> @@ -157,5 +157,4 @@ vug_deinit(VugDev *dev)
>      g_assert(dev);
>
>      g_hash_table_unref(dev->fdmap);
> -    g_source_unref(dev->src);

I think the main problem here is that src is not owned, since
vug_source_new() does g_source_unref(). This is looks unfortunate.

However, the source should be destroyed (detached from the main
context). I think this is ultimately what your change is about.

Imho, we should change the behaviour of the function to return a ref
source. This needs fixing the hashtable destroy callback. It will be
more consistent with other usages of the functions that also need
fixing in contrib/vhost-user-input/main.c for example.


>  }
> diff --git a/contrib/libvhost-user/libvhost-user-glib.h 
> b/contrib/libvhost-user/libvhost-user-glib.h
> index 64d539d93aba..32a6ec6df063 100644
> --- a/contrib/libvhost-user/libvhost-user-glib.h
> +++ b/contrib/libvhost-user/libvhost-user-glib.h
> @@ -22,7 +22,6 @@ typedef struct VugDev {
>      VuDev parent;
>
>      GHashTable *fdmap; /* fd -> gsource */
> -    GSource *src;
>  } VugDev;
>
>  bool vug_init(VugDev *dev, uint16_t max_queues, int socket,
> --
> 2.23.0
>
>


-- 
Marc-André Lureau



reply via email to

[Prev in Thread] Current Thread [Next in Thread]