Received: from eggs.gnu.org ([2001:4830:134:3::10]:45093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVk3K-00081G-Rq for qemu-devel@nongnu.org; Tue, 16 Feb 2016 13:08:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVk3G-0005WS-HH for qemu-devel@nongnu.org; Tue, 16 Feb 2016 13:08:46 -0500 From: Max Reitz Date: Tue, 16 Feb 2016 19:08:15 +0100 Message-Id: <1455646106-2047-4-git-send-email-mreitz@redhat.com> In-Reply-To: <1455646106-2047-1-git-send-email-mreitz@redhat.com> References: <1455646106-2047-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v3 03/14] block: Add blk_all_next() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: Kevin Wolf , Markus Armbruster , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Some places in block/block-backend.c need to iterate over actually all BlockBackends, so this adds a function to do so. blk_next() in contrast only iterates over the BlockBackends which are owned by the monitor. Right now, both do the same, but this will change as of a follow-up patch. Signed-off-by: Max Reitz --- block/block-backend.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 2146268..30decb4 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -223,11 +223,21 @@ void blk_unref(BlockBackend *blk) } } +/* + * Behaves similarly to blk_next() but iterates over all BlockBackends, even the + * ones which are hidden (i.e. are not referenced by the monitor). + */ +static BlockBackend *blk_all_next(BlockBackend *blk) +{ + return blk ? QTAILQ_NEXT(blk, link) + : QTAILQ_FIRST(&blk_backends); +} + void blk_remove_all_bs(void) { - BlockBackend *blk; + BlockBackend *blk = NULL; - QTAILQ_FOREACH(blk, &blk_backends, link) { + while ((blk = blk_all_next(blk)) != NULL) { AioContext *ctx = blk_get_aio_context(blk); aio_context_acquire(ctx); -- 2.7.1