Received: from eggs.gnu.org ([2001:4830:134:3::10]:45324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVk3a-0008WE-FF for qemu-devel@nongnu.org; Tue, 16 Feb 2016 13:09:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVk3Z-0005dj-FC for qemu-devel@nongnu.org; Tue, 16 Feb 2016 13:09:02 -0500 From: Max Reitz Date: Tue, 16 Feb 2016 19:08:23 +0100 Message-Id: <1455646106-2047-12-git-send-email-mreitz@redhat.com> In-Reply-To: <1455646106-2047-1-git-send-email-mreitz@redhat.com> References: <1455646106-2047-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v3 11/14] block: Add blk_next_root_bs() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: Kevin Wolf , Markus Armbruster , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz This function iterates over all BDSs attached to a BB. We are going to need it when rewriting bdrv_next() so it no longer uses bdrv_states. Signed-off-by: Max Reitz --- block/block-backend.c | 24 ++++++++++++++++++++++++ include/sysemu/block-backend.h | 1 + 2 files changed, 25 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index a918c35..d1621ec 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -269,6 +269,30 @@ BlockBackend *blk_next(BlockBackend *blk) } /* + * Iterates over all BlockDriverStates which are attached to a BlockBackend. + * This function is for use by bdrv_next(). + * + * @bs must be NULL or a BDS that is attached to a BB. + */ +BlockDriverState *blk_next_root_bs(BlockDriverState *bs) +{ + BlockBackend *blk; + + if (bs) { + assert(bs->blk); + blk = bs->blk; + } else { + blk = NULL; + } + + do { + blk = blk_all_next(blk); + } while (blk && !blk->bs); + + return blk ? blk->bs : NULL; +} + +/* * Add a BlockBackend into the list of backends referenced by the monitor. * Strictly for use by blockdev.c. */ diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 3a47982..5ac9bd2 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -73,6 +73,7 @@ const char *blk_name(BlockBackend *blk); BlockBackend *blk_by_name(const char *name); bool blk_name_taken(const char *name); BlockBackend *blk_next(BlockBackend *blk); +BlockDriverState *blk_next_root_bs(BlockDriverState *bs); void monitor_add_blk(BlockBackend *blk); void monitor_remove_blk(BlockBackend *blk); -- 2.7.1