block: Unite remove_empty_child and child_free

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>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20211111120829.81329-4-hreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20211115145409.176785-4-kwolf@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
This commit is contained in:
Hanna Reitz 2021-11-15 15:53:59 +01:00
parent a225369bce
commit 04c9c3a52c
1 changed files with 13 additions and 13 deletions

26
block.c
View File

@ -2740,19 +2740,19 @@ static void bdrv_replace_child_noperm(BdrvChild *child,
} }
} }
static void bdrv_child_free(void *opaque) /**
{ * Free the given @child.
BdrvChild *c = opaque; *
* The child must be empty (i.e. `child->bs == NULL`) and it must be
g_free(c->name); * unused (i.e. not in a children list).
g_free(c); */
} static void bdrv_child_free(BdrvChild *child)
static void bdrv_remove_empty_child(BdrvChild *child)
{ {
assert(!child->bs); assert(!child->bs);
assert(!child->next.le_prev); /* not in children list */ assert(!child->next.le_prev); /* not in children list */
bdrv_child_free(child);
g_free(child->name);
g_free(child);
} }
typedef struct BdrvAttachChildCommonState { typedef struct BdrvAttachChildCommonState {
@ -2786,7 +2786,7 @@ static void bdrv_attach_child_common_abort(void *opaque)
} }
bdrv_unref(bs); bdrv_unref(bs);
bdrv_remove_empty_child(child); bdrv_child_free(child);
*s->child = NULL; *s->child = NULL;
} }
@ -2859,7 +2859,7 @@ static int bdrv_attach_child_common(BlockDriverState *child_bs,
if (ret < 0) { if (ret < 0) {
error_propagate(errp, local_err); error_propagate(errp, local_err);
bdrv_remove_empty_child(new_child); bdrv_child_free(new_child);
return ret; return ret;
} }
} }
@ -2925,7 +2925,7 @@ static void bdrv_detach_child(BdrvChild *child)
BlockDriverState *old_bs = child->bs; BlockDriverState *old_bs = child->bs;
bdrv_replace_child_noperm(child, NULL); bdrv_replace_child_noperm(child, NULL);
bdrv_remove_empty_child(child); bdrv_child_free(child);
if (old_bs) { if (old_bs) {
/* /*