From patchwork Wed Jun 3 19:44:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 480122 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 435E11401DA for ; Thu, 4 Jun 2015 05:59:40 +1000 (AEST) Received: from localhost ([::1]:37621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0Ep8-0000vN-Gj for incoming@patchwork.ozlabs.org; Wed, 03 Jun 2015 15:59:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0EbQ-0001VM-5g for qemu-devel@nongnu.org; Wed, 03 Jun 2015 15:45:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z0EbP-00010s-4T for qemu-devel@nongnu.org; Wed, 03 Jun 2015 15:45:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32783) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z0EbJ-0000xP-E6; Wed, 03 Jun 2015 15:45:21 -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 0BDACBC911; Wed, 3 Jun 2015 19:45:21 +0000 (UTC) Received: from localhost (ovpn-116-32.ams2.redhat.com [10.36.116.32]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t53JjIe4001252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 3 Jun 2015 15:45:20 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 3 Jun 2015 21:44:01 +0200 Message-Id: <1433360659-1915-21-git-send-email-mreitz@redhat.com> In-Reply-To: <1433360659-1915-1-git-send-email-mreitz@redhat.com> References: <1433360659-1915-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 , qemu-devel@nongnu.org, Markus Armbruster , Stefan Hajnoczi , Max Reitz , John Snow Subject: [Qemu-devel] [PATCH v3 20/38] block: Add blk_insert_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 associates the given BlockDriverState with the given BlockBackend. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- block/block-backend.c | 16 ++++++++++++++++ include/sysemu/block-backend.h | 1 + 2 files changed, 17 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 57302f8..4d6532f 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -312,6 +312,22 @@ void blk_hide_on_behalf_of_hmp_drive_del(BlockBackend *blk) } /* + * Associates a new BlockDriverState with @blk. + */ +void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) +{ + if (bs->blk == blk) { + return; + } + + assert(!blk->bs); + assert(!bs->blk); + bdrv_ref(bs); + blk->bs = bs; + bs->blk = blk; +} + +/* * Attach device model @dev to @blk. * Return 0 on success, -EBUSY when a device model is attached already. */ diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index b98a86e..8561380 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_insert_bs(BlockBackend *blk, BlockDriverState *bs); void blk_hide_on_behalf_of_hmp_drive_del(BlockBackend *blk);