Received: from eggs.gnu.org ([2001:4830:134:3::10]:45207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1avPOc-0005e3-IC for qemu-devel@nongnu.org; Wed, 27 Apr 2016 09:20:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1avPOZ-0000yJ-BG for qemu-devel@nongnu.org; Wed, 27 Apr 2016 09:20:50 -0400 From: Kevin Wolf Date: Wed, 27 Apr 2016 15:20:28 +0200 Message-Id: <1461763231-17598-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1461763231-17598-1-git-send-email-kwolf@redhat.com> References: <1461763231-17598-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH v2 6/9] block: Add bdrv_has_blk() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, mreitz@redhat.com, jcody@redhat.com, armbru@redhat.com, eblake@redhat.com, qemu-devel@nongnu.org In many cases we just want to know whether a BDS has at least one BB attached, without needing to know the exact BB that is attached. In contrast to bs->blk, this is still a valid question when more than one BB can be attached, so just answer it by checking the parents list. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/block-backend.c | 17 +++++++++++++++++ include/sysemu/block-backend.h | 1 + 2 files changed, 18 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index d1974f5..bd1bf14 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -395,6 +395,23 @@ BlockDriverState *blk_bs(BlockBackend *blk) } /* + * Returns true if @bs has an associated BlockBackend. + */ +bool bdrv_has_blk(BlockDriverState *bs) +{ + BdrvChild *child; + QLIST_FOREACH(child, &bs->parents, next_parent) { + if (child->role == &child_root) { + assert(bs->blk); + return true; + } + } + + assert(!bs->blk); + return false; +} + +/* * Return @blk's DriveInfo if any, else null. */ DriveInfo *blk_legacy_dinfo(BlockBackend *blk) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 8285c97..60db46c 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -99,6 +99,7 @@ BlockBackend *blk_by_public(BlockBackendPublic *public); BlockDriverState *blk_bs(BlockBackend *blk); void blk_remove_bs(BlockBackend *blk); void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs); +bool bdrv_has_blk(BlockDriverState *bs); void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow); void blk_iostatus_enable(BlockBackend *blk); -- 1.8.3.1