From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZCv9S-00062R-BO for qemu-devel@nongnu.org; Wed, 08 Jul 2015 15:37:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZCv9P-00031K-Ro for qemu-devel@nongnu.org; Wed, 08 Jul 2015 15:37:00 -0400 From: Kevin Wolf Date: Wed, 8 Jul 2015 21:36:41 +0200 Message-Id: <1436384203-10576-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1436384203-10576-1-git-send-email-kwolf@redhat.com> References: <1436384203-10576-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH for-2.4 3/5] block: Introduce bdrv_unref_child() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com 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 --- block.c | 23 +++++++++++++++++++++-- include/block/block.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 029feeb..b723cf2 100644 --- a/block.c +++ b/block.c @@ -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) { diff --git a/include/block/block.h b/include/block/block.h index 5048772..37916f7 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -513,6 +513,7 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs); void bdrv_ref(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); void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason); -- 1.8.3.1