From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiS6o-0000pp-8Q for qemu-devel@nongnu.org; Tue, 22 Mar 2016 15:36:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aiS6l-0003Bw-0z for qemu-devel@nongnu.org; Tue, 22 Mar 2016 15:36:54 -0400 From: Kevin Wolf Date: Tue, 22 Mar 2016 20:36:33 +0100 Message-Id: <1458675397-24956-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1458675397-24956-1-git-send-email-kwolf@redhat.com> References: <1458675397-24956-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 5/9] block: Avoid BDS.blk in bdrv_next() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com We just want to know whether a BDS has at least one BB attached in order to avoid enumerating it twice. This doesn't depend on the exact BB that is attached and 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 --- block.c | 4 ++-- block/block-backend.c | 17 +++++++++++++++++ include/sysemu/block-backend.h | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 4cc117d..66f918e 100644 --- a/block.c +++ b/block.c @@ -2904,7 +2904,7 @@ BlockDriverState *bdrv_next_node(BlockDriverState *bs) * the monitor or attached to a BlockBackend */ BlockDriverState *bdrv_next(BlockDriverState *bs) { - if (!bs || bs->blk) { + if (!bs || bdrv_has_blk(bs)) { bs = blk_next_root_bs(bs); if (bs) { return bs; @@ -2915,7 +2915,7 @@ BlockDriverState *bdrv_next(BlockDriverState *bs) * handled by the above block already */ do { bs = bdrv_next_monitor_owned(bs); - } while (bs && bs->blk); + } while (bs && bdrv_has_blk(bs)); return bs; } diff --git a/block/block-backend.c b/block/block-backend.c index dfc11b5..fdd1727 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -434,6 +434,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 1ae1ac9..bd68a17 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