From: Dietmar Maurer <dietmar@proxmox.com>
To: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: AIO_WAIT_WHILE questions
Date: Fri, 27 Mar 2020 17:36:23 +0100 (CET) [thread overview]
Message-ID: <1242491200.59.1585326983523@webmail.proxmox.com> (raw)
Hi all,
I have a question about AIO_WAIT_WHILE. The docs inside the code say:
* The caller's thread must be the IOThread that owns @ctx or the main loop
* thread (with @ctx acquired exactly once).
I wonder if that "with @ctx acquired exactly once" is always required?
I have done a quick test (see code below) and this reveals that the condition is not
always met.
Or is my test wrong (or the docs)?
---debug helper---
diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h
index afeeb18f95..cf78dca9f9 100644
--- a/include/block/aio-wait.h
+++ b/include/block/aio-wait.h
@@ -82,6 +82,8 @@ extern AioWait global_aio_wait;
atomic_inc(&wait_->num_waiters); \
if (ctx_ && in_aio_context_home_thread(ctx_)) { \
while ((cond)) { \
+ printf("AIO_WAIT_WHILE %p %d\n", ctx, ctx_->lock_count); \
+ assert(ctx_->lock_count == 1); \
aio_poll(ctx_, true); \
waited_ = true; \
} \
diff --git a/include/block/aio.h b/include/block/aio.h
index cb1989105a..51ef20e2f0 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -125,6 +125,7 @@ struct AioContext {
/* Used by AioContext users to protect from multi-threaded access. */
QemuRecMutex lock;
+ int lock_count;
/* The list of registered AIO handlers. Protected by ctx->list_lock. */
AioHandlerList aio_handlers;
diff --git a/util/async.c b/util/async.c
index b94518b948..9804c6c64f 100644
--- a/util/async.c
+++ b/util/async.c
@@ -594,9 +594,11 @@ void aio_context_unref(AioContext *ctx)
void aio_context_acquire(AioContext *ctx)
{
qemu_rec_mutex_lock(&ctx->lock);
+ ctx->lock_count++;
}
void aio_context_release(AioContext *ctx)
{
+ ctx->lock_count--;
qemu_rec_mutex_unlock(&ctx->lock);
}
next reply other threads:[~2020-03-27 16:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-27 16:36 Dietmar Maurer [this message]
2020-03-27 19:52 ` AIO_WAIT_WHILE questions no-reply
2020-03-27 20:51 ` no-reply
2020-03-30 8:09 ` Markus Armbruster
2020-03-30 9:08 ` Stefan Hajnoczi
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=1242491200.59.1585326983523@webmail.proxmox.com \
--to=dietmar@proxmox.com \
--cc=qemu-devel@nongnu.org \
/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).