diff options
author | Kevin Wolf <kwolf@redhat.com> | 2015-06-15 13:51:04 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2015-07-14 17:15:23 +0200 |
commit | 33a604075c51e5528eed970eeaeefe609ea2337d (patch) | |
tree | 52f4f7af38d22a372270cc25c3fd863970a341c2 /block.c | |
parent | b4b059f628173dd1d722ee8a9c592a80aec1fc2f (diff) |
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>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -1117,6 +1117,24 @@ static BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs, 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) { @@ -1884,11 +1902,12 @@ void bdrv_close(BlockDriverState *bs) BdrvChild *child, *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) { child->bs->inherits_from = NULL; } - QLIST_REMOVE(child, next); - g_free(child); + bdrv_detach_child(child); } if (bs->backing_hd) { |