From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zvv79-00043g-Vm for qemu-devel@nongnu.org; Mon, 09 Nov 2015 17:40:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zvv79-000558-1Y for qemu-devel@nongnu.org; Mon, 09 Nov 2015 17:40:39 -0500 From: Max Reitz Date: Mon, 9 Nov 2015 23:39:30 +0100 Message-Id: <1447108773-6836-22-git-send-email-mreitz@redhat.com> In-Reply-To: <1447108773-6836-1-git-send-email-mreitz@redhat.com> References: <1447108773-6836-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v7 21/24] block: Add blk_remove_all_bs() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: Kevin Wolf , Alberto Garcia , John Snow , Markus Armbruster , qemu-devel@nongnu.org, Stefan Hajnoczi , Paolo Bonzini , Max Reitz When bdrv_close_all() is called, instead of force-closing all root BlockDriverStates, it is better to just drop the reference from all BlockBackends and let them be closed automatically. This prevents BDS from getting closed that are still referenced by other BDS, which may result in loss of cached data. This patch adds a function for doing that, but does not yet incorporate it in bdrv_close_all(). Signed-off-by: Max Reitz Reviewed-by: Kevin Wolf --- 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 4523387..7373093 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -221,6 +221,21 @@ void blk_unref(BlockBackend *blk) } } +void blk_remove_all_bs(void) +{ + BlockBackend *blk; + + QTAILQ_FOREACH(blk, &blk_backends, link) { + AioContext *ctx = blk_get_aio_context(blk); + + aio_context_acquire(ctx); + if (blk->bs) { + blk_remove_bs(blk); + } + aio_context_release(ctx); + } +} + /* * Return the BlockBackend after @blk. * If @blk is null, return the first one. diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index abb52be..9fb3e54 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -68,6 +68,7 @@ BlockBackend *blk_new_open(const char *name, const char *filename, int blk_get_refcnt(BlockBackend *blk); void blk_ref(BlockBackend *blk); void blk_unref(BlockBackend *blk); +void blk_remove_all_bs(void); const char *blk_name(BlockBackend *blk); BlockBackend *blk_by_name(const char *name); BlockBackend *blk_next(BlockBackend *blk); -- 2.6.2