From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PULL 4/5] block: Dec. drained_end_counter before bdrv_wakeup
Date: Mon, 22 Jul 2019 19:26:15 +0200 [thread overview]
Message-ID: <20190722172616.28797-5-mreitz@redhat.com> (raw)
In-Reply-To: <20190722172616.28797-1-mreitz@redhat.com>
Decrementing drained_end_counter after bdrv_dec_in_flight() (which in
turn invokes bdrv_wakeup() and thus aio_wait_kick()) is not very clever.
We should decrement it beforehand, so that any waiting aio_poll() that
is woken by bdrv_dec_in_flight() sees the decremented
drained_end_counter.
Because the time window between decrementing drained_end_counter and
aio_wait_kick() is very small, I cannot supply a reliable regression
test. However, running e.g. the /bdrv-drain/blockjob/iothread/drain_all
test in test-bdrv-drain has a small chance of hanging without this
patch (about 1/200 or so; it gets to nearly 100 % if you add e.g. an
fputc(' ', stderr); after the bdrv_dec_in_flight()).
Fixes: e037c09c78520cbdb6da7cfc6ad0256d5870b814
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20190722133054.21781-2-mreitz@redhat.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/io.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/block/io.c b/block/io.c
index b89e155d21..06305c6ea6 100644
--- a/block/io.c
+++ b/block/io.c
@@ -217,13 +217,12 @@ static void coroutine_fn bdrv_drain_invoke_entry(void *opaque)
bs->drv->bdrv_co_drain_end(bs);
}
- /* Set data->done before reading bs->wakeup. */
+ /* Set data->done and decrement drained_end_counter before bdrv_wakeup() */
atomic_mb_set(&data->done, true);
- bdrv_dec_in_flight(bs);
-
if (!data->begin) {
atomic_dec(data->drained_end_counter);
}
+ bdrv_dec_in_flight(bs);
g_free(data);
}
--
2.21.0
next prev parent reply other threads:[~2019-07-22 17:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-22 17:26 [Qemu-devel] [PULL 0/5] Block patches for 4.1.0-rc2 Max Reitz
2019-07-22 17:26 ` [Qemu-devel] [PULL 1/5] block/nvme: fix doorbell stride Max Reitz
2019-07-22 17:26 ` [Qemu-devel] [PULL 2/5] block/nvme: support larger that 512 bytes sector devices Max Reitz
2019-07-29 13:16 ` Peter Maydell
2019-07-29 13:25 ` Max Reitz
2019-07-29 15:01 ` Maxim Levitsky
2019-07-29 14:50 ` [Qemu-devel] [Qemu-block] " Maxim Levitsky
2019-07-22 17:26 ` [Qemu-devel] [PULL 3/5] block/nvme: don't touch the completion entries Max Reitz
2019-07-22 17:26 ` Max Reitz [this message]
2019-07-22 17:26 ` [Qemu-devel] [PULL 5/5] block: Only the main loop can change AioContexts Max Reitz
2019-07-23 9:51 ` [Qemu-devel] [PULL 0/5] Block patches for 4.1.0-rc2 Peter Maydell
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=20190722172616.28797-5-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--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).