On Tue, Sep 26, 2017 at 07:13:43PM +0800, Fam Zheng wrote: > On Tue, 09/26 17:11, Peter Xu wrote: > void aio_context_unref(AioContext *ctx) > { > + assert(ctx->refcnt > 0); > + if (--ctx->refcnt == 0) { > + aio_set_event_notifier(ctx, &ctx->notifier, false, NULL, NULL); > + }
This isn't a general solution because Linux AIO also has a file descriptor that is removed in aio_ctx_finalize(). Here is a different approach. Does it work for you? BTW I'm not a glib expert so maybe we're abusing the API and missing the obvious way to structure our code :). diff --git a/util/aio-posix.c b/util/aio-posix.c index 2d51239ec6..5946ac09f0 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -223,7 +223,14 @@ void aio_set_fd_handler(AioContext *ctx, return; } - g_source_remove_poll(&ctx->source, &node->pfd); + /* If the GSource is in the process of being destroyed then + * g_source_remove_poll() causes an assertion failure. Skip + * removal in that case, because glib cleans up its state during + * destruction anyway. + */ + if (!g_source_is_destroyed(&ctx->source)) { + g_source_remove_poll(&ctx->source, &node->pfd); + } /* If the lock is held, just mark the node as deleted */ if (qemu_lockcnt_count(&ctx->list_lock)) {