From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQIGo-0007PU-7I for qemu-devel@nongnu.org; Tue, 24 Feb 2015 11:23:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQIGk-0006tq-Sx for qemu-devel@nongnu.org; Tue, 24 Feb 2015 11:23:38 -0500 From: Max Reitz Date: Tue, 24 Feb 2015 11:23:13 -0500 Message-Id: <1424795000-26494-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1424795000-26494-1-git-send-email-mreitz@redhat.com> References: <1424795000-26494-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 2/9] block: Add blk_next_inserted() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: Kevin Wolf , Markus Armbruster , Stefan Hajnoczi , Max Reitz This function skips to the next BlockBackend for which blk_is_inserted() is true. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/block-backend.c | 15 +++++++++++++++ include/sysemu/block-backend.h | 1 + 2 files changed, 16 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index e2e70d2..ab3affa 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -236,6 +236,21 @@ BlockBackend *blk_next(BlockBackend *blk) } /* + * Like blk_next(), but skips all non-inserted BlockBackends (that is, + * BlockBackends for which blk_is_inserted() returns false) + */ +BlockBackend *blk_next_inserted(BlockBackend *blk) +{ + while ((blk = blk_next(blk)) != NULL) { + if (blk_is_inserted(blk)) { + break; + } + } + + return blk; +} + +/* * Return @blk's name, a non-null string. * Wart: the name is empty iff @blk has been hidden with * blk_hide_on_behalf_of_do_drive_del(). diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index b9eae9b..8b4a9ec 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -72,6 +72,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); +BlockBackend *blk_next_inserted(BlockBackend *blk); BlockDriverState *blk_bs(BlockBackend *blk); void blk_remove_bs(BlockBackend *blk); -- 2.1.0