[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 07/12] raw-format: Fix open with 'file' in iothread
From: |
Kevin Wolf |
Subject: |
[PATCH 07/12] raw-format: Fix open with 'file' in iothread |
Date: |
Thu, 25 May 2023 14:47:08 +0200 |
When opening the 'file' child moves bs to an iothread, we need to hold
the AioContext lock of it before we can call raw_apply_options() (and
more specifically, bdrv_getlength() inside of it).
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/raw-format.c | 5 +++++
tests/unit/test-block-iothread.c | 3 ---
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/block/raw-format.c b/block/raw-format.c
index 918fe4fb7e..e4f35268e6 100644
--- a/block/raw-format.c
+++ b/block/raw-format.c
@@ -468,6 +468,7 @@ static int raw_open(BlockDriverState *bs, QDict *options,
int flags,
Error **errp)
{
BDRVRawState *s = bs->opaque;
+ AioContext *ctx;
bool has_size;
uint64_t offset, size;
BdrvChildRole file_role;
@@ -515,7 +516,11 @@ static int raw_open(BlockDriverState *bs, QDict *options,
int flags,
bs->file->bs->filename);
}
+ ctx = bdrv_get_aio_context(bs);
+ aio_context_acquire(ctx);
ret = raw_apply_options(bs, s, offset, has_size, size, errp);
+ aio_context_release(ctx);
+
if (ret < 0) {
return ret;
}
diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
index 1b40e65bad..f081c09729 100644
--- a/tests/unit/test-block-iothread.c
+++ b/tests/unit/test-block-iothread.c
@@ -833,12 +833,9 @@ static void test_attach_second_node(void)
qdict_put_str(options, "driver", "raw");
qdict_put_str(options, "file", "base");
- /* FIXME raw_open() should take ctx's lock internally */
- aio_context_acquire(ctx);
aio_context_acquire(main_ctx);
filter = bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort);
aio_context_release(main_ctx);
- aio_context_release(ctx);
g_assert(blk_get_aio_context(blk) == ctx);
g_assert(bdrv_get_aio_context(bs) == ctx);
--
2.40.1
- [PATCH 00/12] block: Fix blockdev-create with iothreads, Kevin Wolf, 2023/05/25
- [PATCH 01/12] block-coroutine-wrapper: Take AioContext lock in no_co_wrappers, Kevin Wolf, 2023/05/25
- [PATCH 03/12] block: Take main AioContext lock when calling bdrv_open(), Kevin Wolf, 2023/05/25
- [PATCH 05/12] mirror: Hold main AioContext lock for calling bdrv_open_backing_file(), Kevin Wolf, 2023/05/25
- [PATCH 07/12] raw-format: Fix open with 'file' in iothread,
Kevin Wolf <=
- [PATCH 12/12] iotests: Test blockdev-create in iothread, Kevin Wolf, 2023/05/25
- [PATCH 08/12] copy-before-write: Fix open with child in iothread, Kevin Wolf, 2023/05/25
- [PATCH 04/12] block-backend: Fix blk_new_open() for iothreads, Kevin Wolf, 2023/05/25
- [PATCH 02/12] block: Clarify locking rules for bdrv_open(_inherit)(), Kevin Wolf, 2023/05/25