From 981f4f578e6a0dfb2d02384941ea17f7ea1a14ec Mon Sep 17 00:00:00 2001 From: Max Reitz Date: Wed, 16 Mar 2016 19:54:42 +0100 Subject: block: Add blk_next_root_bs() 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 Signed-off-by: Kevin Wolf --- block/block-backend.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'block') diff --git a/block/block-backend.c b/block/block-backend.c index b3c3d39db8..7818aa2634 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -249,6 +249,30 @@ BlockBackend *blk_next(BlockBackend *blk) : QTAILQ_FIRST(&monitor_block_backends); } +/* + * 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, with * the given @name acting as the handle for the monitor. -- cgit debian/1.2.3+git2.25.1-1-2-gaceb0