From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvzbE-0004Pr-Us for qemu-devel@nongnu.org; Mon, 09 Nov 2015 22:28:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZvzbE-0006L7-4N for qemu-devel@nongnu.org; Mon, 09 Nov 2015 22:28:00 -0500 From: Max Reitz Date: Tue, 10 Nov 2015 04:27:43 +0100 Message-Id: <1447126069-6185-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1447126069-6185-1-git-send-email-mreitz@redhat.com> References: <1447126069-6185-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v2 2/8] block: Add blk_next_inserted() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: Kevin Wolf , qemu-devel@nongnu.org, 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 7128adc..ef387f8 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -252,6 +252,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_hmp_drive_del(). diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 0593231..967c768 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); +BlockBackend *blk_next_inserted(BlockBackend *blk); BlockDriverState *blk_bs(BlockBackend *blk); void blk_remove_bs(BlockBackend *blk); -- 2.6.2