[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 04/12] block.c: bdrv_replace_child_noperm: first call ->attach(),
From: |
Emanuele Giuseppe Esposito |
Subject: |
[PATCH 04/12] block.c: bdrv_replace_child_noperm: first call ->attach(), and then add child |
Date: |
Tue, 18 Jan 2022 11:27:30 -0500 |
Doing the opposite can make adding the child node to a non-drained node,
as apply_subtree_drain is only done in ->attach() and thus make
assert_bdrv_graph_writable fail.
This can happen for example during a transaction rollback (test 245,
test_io_with_graph_changes):
1. a node is removed from the graph, thus it is undrained
2. then something happens, and we need to roll back the transactions
through tran_abort()
3. at this point, the current code would first attach the undrained node
to the graph via QLIST_INSERT_HEAD, and then call ->attach() that
will take care of restoring the drain with apply_subtree_drain(),
leaving the node undrained between the two operations.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/block.c b/block.c
index 29de2b62b5..fb5bc3077a 100644
--- a/block.c
+++ b/block.c
@@ -2879,8 +2879,6 @@ static void bdrv_replace_child_noperm(BdrvChild **childp,
}
if (new_bs) {
- assert_bdrv_graph_writable(new_bs);
- QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent);
/*
* Detaching the old node may have led to the new node's
@@ -2897,6 +2895,10 @@ static void bdrv_replace_child_noperm(BdrvChild **childp,
if (child->klass->attach) {
child->klass->attach(child);
}
+
+ assert_bdrv_graph_writable(new_bs);
+ QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent);
+
}
/*
--
2.31.1
- [PATCH 08/12] reopen: add a transaction to drain_end nodes picked in bdrv_reopen_parse_file_or_backing, (continued)
- [PATCH 08/12] reopen: add a transaction to drain_end nodes picked in bdrv_reopen_parse_file_or_backing, Emanuele Giuseppe Esposito, 2022/01/18
- [PATCH 10/12] block.c: add subtree_drains where needed, Emanuele Giuseppe Esposito, 2022/01/18
- [PATCH 12/12] block.c: additional assert qemu in main tread, Emanuele Giuseppe Esposito, 2022/01/18
- [PATCH 06/12] test-bdrv-drain.c: remove test_detach_by_parent_cb(), Emanuele Giuseppe Esposito, 2022/01/18
- [PATCH 03/12] block.c: bdrv_replace_child_noperm: first remove the child, and then call ->detach(), Emanuele Giuseppe Esposito, 2022/01/18
- [PATCH 02/12] block/io.c: make bdrv_do_drained_begin_quiesce static and introduce bdrv_drained_begin_no_poll, Emanuele Giuseppe Esposito, 2022/01/18
- [PATCH 04/12] block.c: bdrv_replace_child_noperm: first call ->attach(), and then add child,
Emanuele Giuseppe Esposito <=
- [PATCH 07/12] block/io.c: introduce bdrv_subtree_drained_{begin/end}_unlocked, Emanuele Giuseppe Esposito, 2022/01/18
- [PATCH 11/12] block/io.c: fully enable assert_bdrv_graph_writable, Emanuele Giuseppe Esposito, 2022/01/18
- Re: [PATCH 00/12] Removal of Aiocontext lock through drains: protect bdrv_replace_child_noperm., Paolo Bonzini, 2022/01/19
- Re: [PATCH 00/12] Removal of Aiocontext lock through drains: protect bdrv_replace_child_noperm., Stefan Hajnoczi, 2022/01/26