qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: Stefan Hajnoczi <stefanha@gmail.com>,
	QEMU Devel Mailing List <qemu-devel@nongnu.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] A glib warning encountered with internal iothread
Date: Tue, 26 Sep 2017 19:13:43 +0800	[thread overview]
Message-ID: <20170926111343.GE31924@lemon.lan> (raw)
In-Reply-To: <20170926091150.GC3828@pxdev.xzpeter.org>

On Tue, 09/26 17:11, Peter Xu wrote:
> If glib unset the flag after calling the destructor, it'll be fine.
> But it's not doing it that way.  And with above implementation of
> glib, I don't see a good way to solve this problem via ordering of
> glib calls... :(

Does this work?

---

diff --git a/include/block/aio.h b/include/block/aio.h
index e9aeeaec94..3237d2be7c 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -147,6 +147,9 @@ struct AioContext {
     int epollfd;
     bool epoll_enabled;
     bool epoll_available;
+
+    /* Protected by BQL */
+    int refcnt;
 };
 
 /**
diff --git a/util/async.c b/util/async.c
index 355af73ee7..c5464611e3 100644
--- a/util/async.c
+++ b/util/async.c
@@ -293,7 +293,6 @@ aio_ctx_finalize(GSource     *source)
     }
     qemu_lockcnt_unlock(&ctx->list_lock);
 
-    aio_set_event_notifier(ctx, &ctx->notifier, false, NULL, NULL);
     event_notifier_cleanup(&ctx->notifier);
     qemu_rec_mutex_destroy(&ctx->lock);
     qemu_lockcnt_destroy(&ctx->list_lock);
@@ -429,6 +428,8 @@ AioContext *aio_context_new(Error **errp)
     ctx->poll_grow = 0;
     ctx->poll_shrink = 0;
 
+    ctx->refcnt = 1;
+
     return ctx;
 fail:
     g_source_destroy(&ctx->source);
@@ -476,11 +477,17 @@ void aio_co_enter(AioContext *ctx, struct Coroutine *co)
 
 void aio_context_ref(AioContext *ctx)
 {
+    assert(ctx->refcnt > 0);
+    ctx->refcnt++;
     g_source_ref(&ctx->source);
 }
 
 void aio_context_unref(AioContext *ctx)
 {
+    assert(ctx->refcnt > 0);
+    if (--ctx->refcnt == 0) {
+        aio_set_event_notifier(ctx, &ctx->notifier, false, NULL, NULL);
+    }
     g_source_unref(&ctx->source);
 }
 

  reply	other threads:[~2017-09-26 11:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-26  5:44 [Qemu-devel] A glib warning encountered with internal iothread Peter Xu
2017-09-26  8:43 ` Stefan Hajnoczi
2017-09-26  9:11   ` Peter Xu
2017-09-26 11:13     ` Fam Zheng [this message]
2017-09-27  4:09       ` Peter Xu
2017-09-27 12:17       ` Stefan Hajnoczi
2017-09-27 12:36         ` Fam Zheng
2017-09-27 13:14           ` Paolo Bonzini
2017-09-28  2:43             ` Peter Xu

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=20170926111343.GE31924@lemon.lan \
    --to=famz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=stefanha@redhat.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).