[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 08/17] blockdev: Add list of all BlockBackends
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v4 08/17] blockdev: Add list of all BlockBackends |
Date: |
Wed, 16 Mar 2016 19:54:36 +0100 |
While monitor_block_backends contains nearly all BBs, we sometimes
really need all BBs. To this end, this patch adds the block_backend
list.
Signed-off-by: Max Reitz <address@hidden>
---
block/block-backend.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/block/block-backend.c b/block/block-backend.c
index 3bb2a6a..35206be 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -29,6 +29,7 @@ struct BlockBackend {
int refcnt;
BlockDriverState *bs;
DriveInfo *legacy_dinfo; /* null unless created by drive_new() */
+ QTAILQ_ENTRY(BlockBackend) link; /* for block_backends */
QTAILQ_ENTRY(BlockBackend) monitor_link; /* for monitor_block_backends */
void *dev; /* attached device model, if any */
@@ -69,6 +70,10 @@ static const AIOCBInfo block_backend_aiocb_info = {
static void drive_info_del(DriveInfo *dinfo);
+/* All BlockBackends */
+static QTAILQ_HEAD(, BlockBackend) block_backends =
+ QTAILQ_HEAD_INITIALIZER(block_backends);
+
/* All BlockBackends referenced by the monitor and which are iterated through
by
* blk_next() */
static QTAILQ_HEAD(, BlockBackend) monitor_block_backends =
@@ -106,7 +111,10 @@ BlockBackend *blk_new(const char *name, Error **errp)
blk->refcnt = 1;
notifier_list_init(&blk->remove_bs_notifiers);
notifier_list_init(&blk->insert_bs_notifiers);
+
+ QTAILQ_INSERT_TAIL(&block_backends, blk, link);
QTAILQ_INSERT_TAIL(&monitor_block_backends, blk, monitor_link);
+
return blk;
}
@@ -177,11 +185,15 @@ static void blk_delete(BlockBackend *blk)
g_free(blk->root_state.throttle_group);
throttle_group_unref(blk->root_state.throttle_state);
}
+
/* Avoid double-remove after blk_hide_on_behalf_of_hmp_drive_del() */
if (blk->name[0]) {
QTAILQ_REMOVE(&monitor_block_backends, blk, monitor_link);
}
g_free(blk->name);
+
+ QTAILQ_REMOVE(&block_backends, blk, link);
+
drive_info_del(blk->legacy_dinfo);
block_acct_cleanup(&blk->stats);
g_free(blk);
@@ -226,11 +238,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(&block_backends);
+}
+
void blk_remove_all_bs(void)
{
BlockBackend *blk = NULL;
- while ((blk = blk_next(blk)) != NULL) {
+ while ((blk = blk_all_next(blk)) != NULL) {
AioContext *ctx = blk_get_aio_context(blk);
aio_context_acquire(ctx);
--
2.7.3
- [Qemu-devel] [PATCH v4 00/17] blockdev: Further BlockBackend work, Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 01/17] monitor: Use BB list for BB name completion, Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 03/17] block: Add blk_commit_all(), Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 02/17] block: Use blk_next() in block-backend.c, Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 06/17] block: Drop BB name from bad option error, Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 04/17] block: Use blk_{commit, flush}_all() consistently, Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 07/17] blockdev: Rename blk_backends, Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 08/17] blockdev: Add list of all BlockBackends,
Max Reitz <=
- [Qemu-devel] [PATCH v4 09/17] blockdev: Separate BB name management, Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 05/17] qapi: Drop QERR_UNKNOWN_BLOCK_FORMAT_FEATURE, Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 13/17] block: Add bdrv_next_monitor_owned(), Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 10/17] blockdev: Split monitor reference from BB creation, Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 11/17] blockdev: Remove blk_hide_on_behalf_of_hmp_drive_del(), Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 14/17] block: Add blk_next_root_bs(), Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 12/17] block: Move some bdrv_*_all() functions to BB, Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 15/17] block: Rewrite bdrv_next(), Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 16/17] block: Use bdrv_next() instead of bdrv_states, Max Reitz, 2016/03/16
- [Qemu-devel] [PATCH v4 17/17] block: Remove bdrv_states list, Max Reitz, 2016/03/16