mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-09-06 18:05:37 +00:00
block: Introduce bdrv_unref_child()
This is the counterpart for bdrv_open_child(). It decreases the reference count of the child BDS and removes it from the list of children of the given parent BDS. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
b4b059f628
commit
33a604075c
23
block.c
23
block.c
|
@ -1117,6 +1117,24 @@ static BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bdrv_detach_child(BdrvChild *child)
|
||||||
|
{
|
||||||
|
QLIST_REMOVE(child, next);
|
||||||
|
g_free(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child)
|
||||||
|
{
|
||||||
|
BlockDriverState *child_bs = child->bs;
|
||||||
|
|
||||||
|
if (child->bs->inherits_from == parent) {
|
||||||
|
child->bs->inherits_from = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bdrv_detach_child(child);
|
||||||
|
bdrv_unref(child_bs);
|
||||||
|
}
|
||||||
|
|
||||||
void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
|
void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1884,11 +1902,12 @@ void bdrv_close(BlockDriverState *bs)
|
||||||
BdrvChild *child, *next;
|
BdrvChild *child, *next;
|
||||||
|
|
||||||
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
|
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
|
||||||
|
/* TODO Remove bdrv_unref() from drivers' close function and use
|
||||||
|
* bdrv_unref_child() here */
|
||||||
if (child->bs->inherits_from == bs) {
|
if (child->bs->inherits_from == bs) {
|
||||||
child->bs->inherits_from = NULL;
|
child->bs->inherits_from = NULL;
|
||||||
}
|
}
|
||||||
QLIST_REMOVE(child, next);
|
bdrv_detach_child(child);
|
||||||
g_free(child);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bs->backing_hd) {
|
if (bs->backing_hd) {
|
||||||
|
|
|
@ -513,6 +513,7 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);
|
||||||
|
|
||||||
void bdrv_ref(BlockDriverState *bs);
|
void bdrv_ref(BlockDriverState *bs);
|
||||||
void bdrv_unref(BlockDriverState *bs);
|
void bdrv_unref(BlockDriverState *bs);
|
||||||
|
void bdrv_unref_child(BlockDriverState *parent, BdrvChild *child);
|
||||||
|
|
||||||
bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp);
|
bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp);
|
||||||
void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason);
|
void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason);
|
||||||
|
|
Loading…
Reference in a new issue