[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 05/15] block: Allow inactivating already inactive nodes
From: |
Kevin Wolf |
Subject: |
[PATCH v2 05/15] block: Allow inactivating already inactive nodes |
Date: |
Thu, 30 Jan 2025 18:12:36 +0100 |
What we wanted to catch with the assertion is cases where the recursion
finds that a child was inactive before its parent. This should never
happen. But if the user tries to inactivate an image that is already
inactive, that's harmless and we don't want to fail the assertion.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/block.c b/block.c
index 94368a200e..be6b71c314 100644
--- a/block.c
+++ b/block.c
@@ -6960,7 +6960,8 @@ bdrv_has_bds_parent(BlockDriverState *bs, bool
only_active)
return false;
}
-static int GRAPH_RDLOCK bdrv_inactivate_recurse(BlockDriverState *bs)
+static int GRAPH_RDLOCK
+bdrv_inactivate_recurse(BlockDriverState *bs, bool top_level)
{
BdrvChild *child, *parent;
int ret;
@@ -6978,7 +6979,14 @@ static int GRAPH_RDLOCK
bdrv_inactivate_recurse(BlockDriverState *bs)
return 0;
}
- assert(!(bs->open_flags & BDRV_O_INACTIVE));
+ /*
+ * Inactivating an already inactive node on user request is harmless, but
if
+ * a child is already inactive before its parent, that's bad.
+ */
+ if (bs->open_flags & BDRV_O_INACTIVE) {
+ assert(top_level);
+ return 0;
+ }
/* Inactivate this node */
if (bs->drv->bdrv_inactivate) {
@@ -7015,7 +7023,7 @@ static int GRAPH_RDLOCK
bdrv_inactivate_recurse(BlockDriverState *bs)
/* Recursively inactivate children */
QLIST_FOREACH(child, &bs->children, next) {
- ret = bdrv_inactivate_recurse(child->bs);
+ ret = bdrv_inactivate_recurse(child->bs, false);
if (ret < 0) {
return ret;
}
@@ -7040,7 +7048,7 @@ int bdrv_inactivate_all(void)
if (bdrv_has_bds_parent(bs, false)) {
continue;
}
- ret = bdrv_inactivate_recurse(bs);
+ ret = bdrv_inactivate_recurse(bs, true);
if (ret < 0) {
bdrv_next_cleanup(&it);
break;
--
2.48.1
- [PATCH v2 01/15] block: Add 'active' field to BlockDeviceInfo, (continued)
- [PATCH v2 01/15] block: Add 'active' field to BlockDeviceInfo, Kevin Wolf, 2025/01/30
- [PATCH v2 02/15] block: Inactivate external snapshot overlays when necessary, Kevin Wolf, 2025/01/30
- [PATCH v2 03/15] migration/block-active: Remove global active flag, Kevin Wolf, 2025/01/30
- [PATCH v2 04/15] block: Don't attach inactive child to active node, Kevin Wolf, 2025/01/30
- [PATCH v2 06/15] block: Fix crash on block_resize on inactive node, Kevin Wolf, 2025/01/30
- [PATCH v2 05/15] block: Allow inactivating already inactive nodes,
Kevin Wolf <=
- [PATCH v2 07/15] block: Add option to create inactive nodes, Kevin Wolf, 2025/01/30
- [PATCH v2 08/15] block: Add blockdev-set-active QMP command, Kevin Wolf, 2025/01/30
- [PATCH v2 09/15] block: Support inactive nodes in blk_insert_bs(), Kevin Wolf, 2025/01/30
- [PATCH v2 10/15] block/export: Don't ignore image activation error in blk_exp_add(), Kevin Wolf, 2025/01/31
- [PATCH v2 11/15] block/export: Add option to allow export of inactive nodes, Kevin Wolf, 2025/01/31