From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKtEh-0004M7-0k for qemu-devel@nongnu.org; Mon, 09 Feb 2015 13:39:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YKtEa-0005Yq-LW for qemu-devel@nongnu.org; Mon, 09 Feb 2015 13:39:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45584) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKtEa-0005Xy-6M for qemu-devel@nongnu.org; Mon, 09 Feb 2015 13:39:00 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t19IcxfM026522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 9 Feb 2015 13:38:59 -0500 From: Max Reitz Date: Mon, 9 Feb 2015 13:38:34 -0500 Message-Id: <1423507124-29809-13-git-send-email-mreitz@redhat.com> In-Reply-To: <1423507124-29809-1-git-send-email-mreitz@redhat.com> References: <1423507124-29809-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v2 12/22] block: Add blk_next_inserted() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , 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 c54792d..5505bb8 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -235,6 +235,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 3790c9b..1772db7 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -74,6 +74,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