From patchwork Mon Oct 26 20:39:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 536194 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 1A4951412FD for ; Tue, 27 Oct 2015 07:40:03 +1100 (AEDT) Received: from localhost ([::1]:55079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqoYj-0008Ay-1M for incoming@patchwork.ozlabs.org; Mon, 26 Oct 2015 16:40:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqoYD-0007Pq-8E for qemu-devel@nongnu.org; Mon, 26 Oct 2015 16:39:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZqoYC-00042x-0n for qemu-devel@nongnu.org; Mon, 26 Oct 2015 16:39:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50951) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZqoY9-000403-Jr; Mon, 26 Oct 2015 16:39:25 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 395F291E86; Mon, 26 Oct 2015 20:39:25 +0000 (UTC) Received: from localhost (ovpn-116-20.ams2.redhat.com [10.36.116.20]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9QKdMfM012204 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 26 Oct 2015 16:39:24 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 26 Oct 2015 21:39:05 +0100 Message-Id: <1445891959-27432-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1445891959-27432-1-git-send-email-mreitz@redhat.com> References: <1445891959-27432-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Alberto Garcia , Markus Armbruster , qemu-devel@nongnu.org, Max Reitz , John Snow , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v8 01/15] block: Add blk_remove_bs() 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 function removes the BlockDriverState associated with the given BlockBackend from that BB and sets the BDS pointer in the BB to NULL. Signed-off-by: Max Reitz --- block/block-backend.c | 12 ++++++++++++ include/sysemu/block-backend.h | 1 + 2 files changed, 13 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 19fdaae..878c448 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -334,6 +334,18 @@ void blk_hide_on_behalf_of_hmp_drive_del(BlockBackend *blk) } /* + * Disassociates the currently associated BlockDriverState from @blk. + */ +void blk_remove_bs(BlockBackend *blk) +{ + blk_update_root_state(blk); + + blk->bs->blk = NULL; + bdrv_unref(blk->bs); + blk->bs = NULL; +} + +/* * Associates a new BlockDriverState with @blk. */ void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 9306a52..14a6d32 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -72,6 +72,7 @@ BlockBackend *blk_by_name(const char *name); BlockBackend *blk_next(BlockBackend *blk); BlockDriverState *blk_bs(BlockBackend *blk); +void blk_remove_bs(BlockBackend *blk); void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs); void blk_hide_on_behalf_of_hmp_drive_del(BlockBackend *blk);