All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
	Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v4 08/17] blockdev: Add list of all BlockBackends
Date: Wed, 16 Mar 2016 19:54:36 +0100	[thread overview]
Message-ID: <1458154485-32536-9-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1458154485-32536-1-git-send-email-mreitz@redhat.com>

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 <mreitz@redhat.com>
---
 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

  parent reply	other threads:[~2016-03-16 18:55 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-16 18:54 [Qemu-devel] [PATCH v4 00/17] blockdev: Further BlockBackend work Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 01/17] monitor: Use BB list for BB name completion Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 02/17] block: Use blk_next() in block-backend.c Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 03/17] block: Add blk_commit_all() Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 04/17] block: Use blk_{commit, flush}_all() consistently Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 05/17] qapi: Drop QERR_UNKNOWN_BLOCK_FORMAT_FEATURE Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 06/17] block: Drop BB name from bad option error Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 07/17] blockdev: Rename blk_backends Max Reitz
2016-03-16 18:54 ` Max Reitz [this message]
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 09/17] blockdev: Separate BB name management Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 10/17] blockdev: Split monitor reference from BB creation Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 11/17] blockdev: Remove blk_hide_on_behalf_of_hmp_drive_del() Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 12/17] block: Move some bdrv_*_all() functions to BB Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 13/17] block: Add bdrv_next_monitor_owned() Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 14/17] block: Add blk_next_root_bs() Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 15/17] block: Rewrite bdrv_next() Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 16/17] block: Use bdrv_next() instead of bdrv_states Max Reitz
2016-03-16 18:54 ` [Qemu-devel] [PATCH v4 17/17] block: Remove bdrv_states list Max Reitz
2016-03-17 13:44 ` [Qemu-devel] [PATCH v4 00/17] blockdev: Further BlockBackend work Kevin Wolf
2016-03-23 19:06   ` Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1458154485-32536-9-git-send-email-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.