[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/7] block: Unite remove_empty_child and child_free
From: |
Hanna Reitz |
Subject: |
[PATCH 3/7] block: Unite remove_empty_child and child_free |
Date: |
Thu, 4 Nov 2021 11:38:45 +0100 |
Now that bdrv_remove_empty_child() no longer removes the child from the
parent's children list but only checks that it is not in such a list, it
is only a wrapper around bdrv_child_free() that checks that the child is
empty and unused. That should apply to all children that we free, so
put those checks into bdrv_child_free() and drop
bdrv_remove_empty_child().
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
---
block.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/block.c b/block.c
index 243ae206b5..b95f8dcf8f 100644
--- a/block.c
+++ b/block.c
@@ -2740,19 +2740,19 @@ static void bdrv_replace_child_noperm(BdrvChild *child,
}
}
-static void bdrv_child_free(void *opaque)
-{
- BdrvChild *c = opaque;
-
- g_free(c->name);
- g_free(c);
-}
-
-static void bdrv_remove_empty_child(BdrvChild *child)
+/**
+ * Free the given @child.
+ *
+ * The child must be empty (i.e. `child->bs == NULL`) and it must be
+ * unused (i.e. not in a children list).
+ */
+static void bdrv_child_free(BdrvChild *child)
{
assert(!child->bs);
assert(!child->next.le_prev); /* not in children list */
- bdrv_child_free(child);
+
+ g_free(child->name);
+ g_free(child);
}
typedef struct BdrvAttachChildCommonState {
@@ -2786,7 +2786,7 @@ static void bdrv_attach_child_common_abort(void *opaque)
}
bdrv_unref(bs);
- bdrv_remove_empty_child(child);
+ bdrv_child_free(child);
*s->child = NULL;
}
@@ -2859,7 +2859,7 @@ static int bdrv_attach_child_common(BlockDriverState
*child_bs,
if (ret < 0) {
error_propagate(errp, local_err);
- bdrv_remove_empty_child(new_child);
+ bdrv_child_free(new_child);
return ret;
}
}
@@ -2930,7 +2930,7 @@ static void bdrv_detach_child(BdrvChild *child)
BlockDriverState *old_bs = child->bs;
bdrv_replace_child_noperm(child, NULL);
- bdrv_remove_empty_child(child);
+ bdrv_child_free(child);
if (old_bs) {
/*
--
2.33.1
- [PATCH 0/7] block: Attempt on fixing 030-reported errors, Hanna Reitz, 2021/11/04
- [PATCH 1/7] stream: Traverse graph after modification, Hanna Reitz, 2021/11/04
- [PATCH 2/7] block: Manipulate children list in .attach/.detach, Hanna Reitz, 2021/11/04
- [PATCH 3/7] block: Unite remove_empty_child and child_free,
Hanna Reitz <=
- [PATCH 4/7] block: Drop detached child from ignore list, Hanna Reitz, 2021/11/04
- [PATCH 5/7] block: Pass BdrvChild ** to replace_child_noperm, Hanna Reitz, 2021/11/04
- [PATCH 7/7] iotests/030: Unthrottle parallel jobs in reverse, Hanna Reitz, 2021/11/04
- [PATCH 6/7] block: Let replace_child_noperm free children, Hanna Reitz, 2021/11/04