From patchwork Fri Sep 18 15:22:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 519382 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 2909A140E52 for ; Sat, 19 Sep 2015 01:30:05 +1000 (AEST) Received: from localhost ([::1]:39659 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zcxbv-00082Q-57 for incoming@patchwork.ozlabs.org; Fri, 18 Sep 2015 11:30:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38448) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcxWS-0007QI-SE for qemu-devel@nongnu.org; Fri, 18 Sep 2015 11:24:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZcxWS-00065s-3i for qemu-devel@nongnu.org; Fri, 18 Sep 2015 11:24:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41374) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcxWK-00063U-GT; Fri, 18 Sep 2015 11:24:16 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 2B0C66E; Fri, 18 Sep 2015 15:24:16 +0000 (UTC) Received: from localhost (ovpn-116-139.ams2.redhat.com [10.36.116.139]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8IFOEmU023966 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 18 Sep 2015 11:24:15 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 18 Sep 2015 17:22:56 +0200 Message-Id: <1442589793-7105-22-git-send-email-mreitz@redhat.com> In-Reply-To: <1442589793-7105-1-git-send-email-mreitz@redhat.com> References: <1442589793-7105-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 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 v5 21/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 33145f8..652385e 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -314,6 +314,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 52e35a1..9306a52 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);