[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 04/11] block: Fix AioContext locking in bdrv_open_child()
From: |
Kevin Wolf |
Subject: |
[PATCH 04/11] block: Fix AioContext locking in bdrv_open_child() |
Date: |
Wed, 31 May 2023 13:02:24 +0200 |
bdrv_attach_child() requires that the caller holds the AioContext lock
for the new child node. Take it in bdrv_open_child() and document that
the caller must not hold any AioContext apart from the main AioContext.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/block.c b/block.c
index dae629075c..3ed943467a 100644
--- a/block.c
+++ b/block.c
@@ -3654,6 +3654,7 @@ done:
*
* The BlockdevRef will be removed from the options QDict.
*
+ * The caller must hold the lock of the main AioContext and no other
AioContext.
* @parent can move to a different AioContext in this function. Callers must
* make sure that their AioContext locking is still correct after this.
*/
@@ -3665,6 +3666,8 @@ BdrvChild *bdrv_open_child(const char *filename,
bool allow_none, Error **errp)
{
BlockDriverState *bs;
+ BdrvChild *child;
+ AioContext *ctx;
GLOBAL_STATE_CODE();
@@ -3674,13 +3677,19 @@ BdrvChild *bdrv_open_child(const char *filename,
return NULL;
}
- return bdrv_attach_child(parent, bs, bdref_key, child_class, child_role,
- errp);
+ ctx = bdrv_get_aio_context(bs);
+ aio_context_acquire(ctx);
+ child = bdrv_attach_child(parent, bs, bdref_key, child_class, child_role,
+ errp);
+ aio_context_release(ctx);
+
+ return child;
}
/*
* Wrapper on bdrv_open_child() for most popular case: open primary child of
bs.
*
+ * The caller must hold the lock of the main AioContext and no other
AioContext.
* @parent can move to a different AioContext in this function. Callers must
* make sure that their AioContext locking is still correct after this.
*/
--
2.40.1
- [PATCH 00/11] block: Re-enable the graph lock, Kevin Wolf, 2023/05/31
- [PATCH 09/11] blockjob: Fix AioContext locking in block_job_add_bdrv(), Kevin Wolf, 2023/05/31
- [PATCH 02/11] qdev-properties-system: Lock AioContext for blk_insert_bs(), Kevin Wolf, 2023/05/31
- [PATCH 03/11] test-block-iothread: Lock AioContext for blk_insert_bs(), Kevin Wolf, 2023/05/31
- [PATCH 05/11] block: Fix AioContext locking in bdrv_attach_child_common(), Kevin Wolf, 2023/05/31
- [PATCH 10/11] graph-lock: Unlock the AioContext while polling, Kevin Wolf, 2023/05/31
- [PATCH 01/11] iotests: Test active commit with iothread and background I/O, Kevin Wolf, 2023/05/31
- [PATCH 06/11] block: Fix AioContext locking in bdrv_reopen_parse_file_or_backing(), Kevin Wolf, 2023/05/31
- [PATCH 11/11] Revert "graph-lock: Disable locking for now", Kevin Wolf, 2023/05/31
- [PATCH 08/11] block: Fix AioContext locking in bdrv_open_backing_file(), Kevin Wolf, 2023/05/31
- [PATCH 04/11] block: Fix AioContext locking in bdrv_open_child(),
Kevin Wolf <=
- [PATCH 07/11] block: Fix AioContext locking in bdrv_open_inherit(), Kevin Wolf, 2023/05/31