From patchwork Tue Jul 14 15:39:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 495139 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0130A140280 for ; Wed, 15 Jul 2015 01:40:31 +1000 (AEST) Received: from localhost ([::1]:60128 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZF2Jp-0000Wu-4I for incoming@patchwork.ozlabs.org; Tue, 14 Jul 2015 11:40:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZF2JA-0007kK-9B for qemu-devel@nongnu.org; Tue, 14 Jul 2015 11:39:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZF2J7-0004qY-Rz for qemu-devel@nongnu.org; Tue, 14 Jul 2015 11:39:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49244) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZF2J5-0004nu-By; Tue, 14 Jul 2015 11:39:43 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id DBEC93B3C1; Tue, 14 Jul 2015 15:39:42 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-108.ams2.redhat.com [10.36.116.108]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6EFdYBm031466; Tue, 14 Jul 2015 11:39:41 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 14 Jul 2015 17:39:26 +0200 Message-Id: <1436888372-27871-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1436888372-27871-1-git-send-email-kwolf@redhat.com> References: <1436888372-27871-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 05/11] block: Introduce bdrv_unref_child() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Max Reitz --- 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);