From: Fiona Ebner <f.ebner@proxmox.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, vsementsov@yandex-team.ru,
jsnow@redhat.com, hreitz@redhat.com, kwolf@redhat.com,
pbonzini@redhat.com, t.lamprecht@proxmox.com
Subject: [PATCH 3/3] blockdev: mirror: avoid potential deadlock when using iothread
Date: Thu, 19 Oct 2023 15:19:36 +0200 [thread overview]
Message-ID: <20231019131936.414246-4-f.ebner@proxmox.com> (raw)
In-Reply-To: <20231019131936.414246-1-f.ebner@proxmox.com>
The bdrv_getlength() function is a generated co-wrapper and uses
AIO_WAIT_WHILE() to wait for the spawned coroutine. AIO_WAIT_WHILE()
expects the lock to be acquired exactly once.
This can happen when the source node is explicitly specified as the
@replaces parameter or if there is a filter on top of the source node.
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
blockdev.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index a01c62596b..877e3a26d4 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2968,6 +2968,7 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
if (replaces) {
BlockDriverState *to_replace_bs;
+ AioContext *aio_context;
AioContext *replace_aio_context;
int64_t bs_size, replace_size;
@@ -2982,10 +2983,19 @@ static void blockdev_mirror_common(const char *job_id, BlockDriverState *bs,
return;
}
+ aio_context = bdrv_get_aio_context(bs);
replace_aio_context = bdrv_get_aio_context(to_replace_bs);
- aio_context_acquire(replace_aio_context);
+ /*
+ * bdrv_getlength() is a co-wrapper and uses AIO_WAIT_WHILE. Be sure not
+ * to acquire the same AioContext twice.
+ */
+ if (replace_aio_context != aio_context) {
+ aio_context_acquire(replace_aio_context);
+ }
replace_size = bdrv_getlength(to_replace_bs);
- aio_context_release(replace_aio_context);
+ if (replace_aio_context != aio_context) {
+ aio_context_release(replace_aio_context);
+ }
if (replace_size < 0) {
error_setg_errno(errp, -replace_size,
--
2.39.2
next prev parent reply other threads:[~2023-10-19 13:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-19 13:19 [PATCH 0/3] fix a few blockjob-related deadlocks when using iothread Fiona Ebner
2023-10-19 13:19 ` [PATCH 1/3] blockjob: drop AioContext lock before calling bdrv_graph_wrlock() Fiona Ebner
2023-10-19 13:19 ` [PATCH 2/3] block: avoid potential deadlock during bdrv_graph_wrlock() in bdrv_close() Fiona Ebner
2023-10-19 13:19 ` Fiona Ebner [this message]
2023-10-20 8:46 ` [PATCH 3/3] blockdev: mirror: avoid potential deadlock when using iothread Fiona Ebner
2023-10-25 12:01 ` [PATCH 0/3] fix a few blockjob-related deadlocks " Kevin Wolf
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=20231019131936.414246-4-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=hreitz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=t.lamprecht@proxmox.com \
--cc=vsementsov@yandex-team.ru \
/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).