[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 4/6] block.c: add subtree_drains where needed
From: |
Emanuele Giuseppe Esposito |
Subject: |
[RFC PATCH 4/6] block.c: add subtree_drains where needed |
Date: |
Mon, 13 Dec 2021 05:40:12 -0500 |
Protect bdrv_replace_child_noperm, as it modifies the
graph by adding/removing elements to .children and .parents
list of a bs.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/block.c b/block.c
index 3c3c90704c..1aa9e51a98 100644
--- a/block.c
+++ b/block.c
@@ -2369,7 +2369,11 @@ static void bdrv_replace_child_abort(void *opaque)
* So whether new_bs was NULL or not, we cannot pass s->childp here; and in
* any case, there is no reason to pass it anyway.
*/
+ bdrv_subtree_drained_begin_unlocked(s->child->bs);
+ bdrv_subtree_drained_begin_unlocked(s->old_bs);
bdrv_replace_child_noperm(&s->child, s->old_bs, true);
+ bdrv_subtree_drained_end_unlocked(s->old_bs);
+ bdrv_subtree_drained_end_unlocked(s->child->bs);
/*
* The child was pre-existing, so s->old_bs must be non-NULL, and
* s->child thus must not have been freed
@@ -2427,13 +2431,20 @@ static void bdrv_replace_child_tran(BdrvChild **childp,
if (new_bs) {
bdrv_ref(new_bs);
+ bdrv_subtree_drained_begin_unlocked(new_bs);
}
/*
* Pass free_empty_child=false, we will free the child (if
* necessary) in bdrv_replace_child_commit() (if our
* @free_empty_child parameter was true).
*/
+ bdrv_subtree_drained_begin_unlocked(s->old_bs);
bdrv_replace_child_noperm(childp, new_bs, false);
+ bdrv_subtree_drained_end_unlocked(s->old_bs);
+
+ if (new_bs) {
+ bdrv_subtree_drained_end_unlocked(new_bs);
+ }
/* old_bs reference is transparently moved from *childp to @s */
}
@@ -2951,7 +2962,9 @@ static void bdrv_attach_child_common_abort(void *opaque)
* need to keep it as an empty shell (after this function, it will
* not be attached to any parent, and it will not have a .bs).
*/
+ bdrv_subtree_drained_begin_unlocked(bs);
bdrv_replace_child_noperm(s->child, NULL, false);
+ bdrv_subtree_drained_end_unlocked(bs);
if (bdrv_get_aio_context(bs) != s->old_child_ctx) {
bdrv_try_set_aio_context(bs, s->old_child_ctx, &error_abort);
@@ -3051,7 +3064,10 @@ static int bdrv_attach_child_common(BlockDriverState
*child_bs,
}
bdrv_ref(child_bs);
+
+ bdrv_subtree_drained_begin_unlocked(child_bs);
bdrv_replace_child_noperm(&new_child, child_bs, true);
+ bdrv_subtree_drained_end_unlocked(child_bs);
/* child_bs was non-NULL, so new_child must not have been freed */
assert(new_child != NULL);
@@ -3114,8 +3130,16 @@ static void bdrv_detach_child(BdrvChild **childp)
BlockDriverState *old_bs = (*childp)->bs;
assert(qemu_in_main_thread());
+ if (old_bs) {
+ bdrv_subtree_drained_begin(old_bs);
+ }
+
bdrv_replace_child_noperm(childp, NULL, true);
+ if (old_bs) {
+ bdrv_subtree_drained_end(old_bs);
+ }
+
if (old_bs) {
/*
* Update permissions for old node. We're just taking a parent away, so
--
2.31.1
- [RFC PATCH 0/6] Removal of Aiocontext lock and usage of subtree drains in aborted transactions, Emanuele Giuseppe Esposito, 2021/12/13
- [RFC PATCH 2/6] introduce BDRV_POLL_WHILE_UNLOCKED, Emanuele Giuseppe Esposito, 2021/12/13
- [RFC PATCH 3/6] block/io.c: introduce bdrv_subtree_drained_{begin/end}_unlocked, Emanuele Giuseppe Esposito, 2021/12/13
- [RFC PATCH 1/6] tests/unit/test-bdrv-drain.c: graph setup functions can't run in coroutines, Emanuele Giuseppe Esposito, 2021/12/13
- [RFC PATCH 5/6] test-bdrv-drain.c: adapt test to the new subtree drains, Emanuele Giuseppe Esposito, 2021/12/13
- [RFC PATCH 4/6] block.c: add subtree_drains where needed,
Emanuele Giuseppe Esposito <=
- [RFC PATCH 6/6] block/io.c: enable assert_bdrv_graph_writable, Emanuele Giuseppe Esposito, 2021/12/13
- Re: [RFC PATCH 0/6] Removal of Aiocontext lock and usage of subtree drains in aborted transactions, Stefan Hajnoczi, 2021/12/13
- Re: [RFC PATCH 0/6] Removal of Aiocontext lock and usage of subtree drains in aborted transactions, Stefan Hajnoczi, 2021/12/14