From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 23/25] block: Add list of children to BlockDriverState
Date: Fri, 12 Jun 2015 18:23:32 +0200 [thread overview]
Message-ID: <1434126214-11681-24-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1434126214-11681-1-git-send-email-kwolf@redhat.com>
This allows iterating over all children of a given BDS, not only
including bs->file and bs->backing_hd, but also driver-specific
ones like VMDK extents or Quorum children.
For bdrv_swap(), the list of children of the swapped BDS stays at that
BDS (because that's where the pointers stay as well). The list head
moves and pointers to it must be fixed up therefore.
The list of children in the parent of the swapped BDS is not affected by
the swap. The contents of the BDS objects is swapped, so the existing
pointer in the parent automatically points to the newly swapped in BDS.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
block.c | 37 +++++++++++++++++++++++++++++++++++++
include/block/block_int.h | 8 ++++++++
2 files changed, 45 insertions(+)
diff --git a/block.c b/block.c
index 9a860f1..209ba39 100644
--- a/block.c
+++ b/block.c
@@ -1325,6 +1325,19 @@ out:
return ret;
}
+static void bdrv_attach_child(BlockDriverState *parent_bs,
+ BlockDriverState *child_bs,
+ const BdrvChildRole *child_role)
+{
+ BdrvChild *child = g_new(BdrvChild, 1);
+ *child = (BdrvChild) {
+ .bs = child_bs,
+ .role = child_role,
+ };
+
+ QLIST_INSERT_HEAD(&parent_bs->children, child, next);
+}
+
/*
* Opens a disk image (raw, qcow2, vmdk, ...)
*
@@ -1377,6 +1390,9 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
return -ENODEV;
}
bdrv_ref(bs);
+ if (child_role) {
+ bdrv_attach_child(parent, bs, child_role);
+ }
*pbs = bs;
return 0;
}
@@ -1520,6 +1536,10 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
goto close_and_fail;
}
+ if (child_role) {
+ bdrv_attach_child(parent, bs, child_role);
+ }
+
QDECREF(options);
*pbs = bs;
return 0;
@@ -1814,6 +1834,13 @@ void bdrv_close(BlockDriverState *bs)
notifier_list_notify(&bs->close_notifiers, bs);
if (bs->drv) {
+ BdrvChild *child, *next;
+
+ QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
+ QLIST_REMOVE(child, next);
+ g_free(child);
+ }
+
if (bs->backing_hd) {
BlockDriverState *backing_hd = bs->backing_hd;
bdrv_set_backing_hd(bs, NULL);
@@ -2005,9 +2032,18 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs_old, node_list);
}
+ /*
+ * Update lh_first.le_prev for non-empty lists.
+ *
+ * The head of the op blocker list doesn't change because it is moved back
+ * in bdrv_move_feature_fields().
+ */
assert(QLIST_EMPTY(&bs_old->tracked_requests));
assert(QLIST_EMPTY(&bs_new->tracked_requests));
+ QLIST_FIX_HEAD_PTR(&bs_new->children, next);
+ QLIST_FIX_HEAD_PTR(&bs_old->children, next);
+
bdrv_rebind(bs_new);
bdrv_rebind(bs_old);
}
@@ -2030,6 +2066,7 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top)
/* The contents of 'tmp' will become bs_top, as we are
* swapping bs_new and bs_top contents. */
bdrv_set_backing_hd(bs_top, bs_new);
+ bdrv_attach_child(bs_top, bs_new, &child_backing);
}
static void bdrv_delete(BlockDriverState *bs)
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 662dd56..4ae5860 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -337,6 +337,12 @@ struct BdrvChildRole {
extern const BdrvChildRole child_file;
extern const BdrvChildRole child_format;
+typedef struct BdrvChild {
+ BlockDriverState *bs;
+ const BdrvChildRole *role;
+ QLIST_ENTRY(BdrvChild) next;
+} BdrvChild;
+
/*
* Note: the function bdrv_append() copies and swaps contents of
* BlockDriverStates, so if you add new fields to this struct, please
@@ -431,6 +437,8 @@ struct BlockDriverState {
/* long-running background operation */
BlockJob *job;
+ QLIST_HEAD(, BdrvChild) children;
+
QDict *options;
BlockdevDetectZeroesOptions detect_zeroes;
--
1.8.3.1
next prev parent reply other threads:[~2015-06-12 16:24 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-12 16:23 [Qemu-devel] [PULL 00/25] Block layer core and image format patches Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 01/25] iotests: remove assertIsNotNone call Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 02/25] qemu-iotests: Fix 128 if sudo required Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 03/25] qcow2: Set MIN_L2_CACHE_SIZE to 2 Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 04/25] iotests: qcow2 COW with minimal L2 cache size Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 05/25] qcow2: Add DEFAULT_L2_CACHE_CLUSTERS Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 06/25] vmdk: Fix index_in_cluster calculation in vmdk_co_get_block_status Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 07/25] vmdk: Use vmdk_find_index_in_cluster everywhere Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 08/25] raw-posix: Fix .bdrv_co_get_block_status() for unaligned image size Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 09/25] block: record new size in bdrv_dirty_bitmap_truncate Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 10/25] block: Change bitmap truncate conditional to assertion Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 11/25] block: driver should override flags in bdrv_open() Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 12/25] iotests: Add tests for overriding BDRV_O_PROTOCOL Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 13/25] qdict: Add qdict_array_entries() Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 14/25] qdict: Add qdict_{set,copy}_default() Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 15/25] check-qdict: Test cases for new functions Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 16/25] quorum: Use bdrv_open_image() Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 17/25] vmdk: " Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 18/25] block: Use macro for cache option names Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 19/25] block: Use QemuOpts in bdrv_open_common() Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 20/25] block: Move flag inheritance to bdrv_open_inherit() Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 21/25] block: Drain requests before swapping nodes in bdrv_swap() Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 22/25] queue.h: Add QLIST_FIX_HEAD_PTR() Kevin Wolf
2015-06-12 16:23 ` Kevin Wolf [this message]
2015-06-12 16:23 ` [Qemu-devel] [PULL 24/25] block: Add BlockDriverState.inherits_from Kevin Wolf
2015-06-12 16:23 ` [Qemu-devel] [PULL 25/25] block: Fix reopen flag inheritance Kevin Wolf
2015-06-15 12:24 ` [Qemu-devel] [PULL 00/25] Block layer core and image format patches Peter Maydell
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=1434126214-11681-24-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).