From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org,
armbru@redhat.com, mreitz@redhat.com
Subject: [Qemu-devel] [PATCH v2 12/13] block: Add BlockDriverState.inherits_from
Date: Wed, 10 Jun 2015 15:47:06 +0200 [thread overview]
Message-ID: <1433944027-28533-13-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1433944027-28533-1-git-send-email-kwolf@redhat.com>
Currently, the block layer assumes that any block node can have only one
parent, and if it has a parent, that it inherits some options/flags from
this parent.
This is not true any more: With references used in block device
creation, a single node can be used by multiple parents, or it can be
created separately and not inherit flags from any parent.
To handle reopens correctly, a node must know from which parent it
inherited options. This patch adds the information to BlockDriverState.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
block.c | 17 +++++++++++++++++
include/block/block_int.h | 4 ++++
2 files changed, 21 insertions(+)
diff --git a/block.c b/block.c
index e2236c3..fa89410 100644
--- a/block.c
+++ b/block.c
@@ -1398,6 +1398,7 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
}
if (child_role) {
+ bs->inherits_from = parent;
flags = child_role->inherit_flags(parent->open_flags);
}
@@ -1825,6 +1826,9 @@ void bdrv_close(BlockDriverState *bs)
BdrvChild *child, *next;
QLIST_FOREACH_SAFE(child, &bs->children, next, next) {
+ if (child->bs->inherits_from == bs) {
+ child->bs->inherits_from = NULL;
+ }
QLIST_REMOVE(child, next);
g_free(child);
}
@@ -1973,6 +1977,7 @@ static void bdrv_move_feature_fields(BlockDriverState *bs_dest,
void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
{
BlockDriverState tmp;
+ BdrvChild *child;
bdrv_drain(bs_new);
bdrv_drain(bs_old);
@@ -2032,6 +2037,18 @@ void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
QLIST_FIX_HEAD_PTR(&bs_new->children, next);
QLIST_FIX_HEAD_PTR(&bs_old->children, next);
+ /* Update references in bs->opaque and children */
+ QLIST_FOREACH(child, &bs_old->children, next) {
+ if (child->bs->inherits_from == bs_new) {
+ child->bs->inherits_from = bs_old;
+ }
+ }
+ QLIST_FOREACH(child, &bs_new->children, next) {
+ if (child->bs->inherits_from == bs_old) {
+ child->bs->inherits_from = bs_new;
+ }
+ }
+
bdrv_rebind(bs_new);
bdrv_rebind(bs_old);
}
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 4ae5860..2732ccd 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -437,6 +437,10 @@ struct BlockDriverState {
/* long-running background operation */
BlockJob *job;
+ /* The node that this node inherited default options from (and a reopen on
+ * which can affect this node by changing these defaults). This is always a
+ * parent node of this node. */
+ BlockDriverState *inherits_from;
QLIST_HEAD(, BdrvChild) children;
QDict *options;
--
1.8.3.1
next prev parent reply other threads:[~2015-06-10 13:47 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-10 13:46 [Qemu-devel] [PATCH v2 00/13] bdrv_reopen() overhaul, part 1 Kevin Wolf
2015-06-10 13:46 ` [Qemu-devel] [PATCH v2 01/13] qdict: Add qdict_array_entries() Kevin Wolf
2015-06-10 20:50 ` Eric Blake
2015-06-12 14:07 ` Max Reitz
2015-06-10 13:46 ` [Qemu-devel] [PATCH v2 02/13] qdict: Add qdict_{set, copy}_default() Kevin Wolf
2015-06-10 21:29 ` Eric Blake
2015-06-10 13:46 ` [Qemu-devel] [PATCH v2 03/13] check-qdict: Test cases for new functions Kevin Wolf
2015-06-10 21:34 ` Eric Blake
2015-06-12 14:12 ` Max Reitz
2015-06-10 13:46 ` [Qemu-devel] [PATCH v2 04/13] quorum: Use bdrv_open_image() Kevin Wolf
2015-06-10 13:46 ` [Qemu-devel] [PATCH v2 05/13] vmdk: " Kevin Wolf
2015-06-10 13:47 ` [Qemu-devel] [PATCH v2 06/13] block: Use macro for cache option names Kevin Wolf
2015-06-10 13:47 ` [Qemu-devel] [PATCH v2 07/13] block: Use QemuOpts in bdrv_open_common() Kevin Wolf
2015-06-10 21:42 ` Eric Blake
2015-06-12 14:15 ` Max Reitz
2015-06-10 13:47 ` [Qemu-devel] [PATCH v2 08/13] block: Move flag inheritance to bdrv_open_inherit() Kevin Wolf
2015-06-10 13:47 ` [Qemu-devel] [PATCH v2 09/13] block: Drain requests before swapping nodes in bdrv_swap() Kevin Wolf
2015-06-10 23:17 ` Eric Blake
2015-06-12 14:16 ` Max Reitz
2015-06-10 13:47 ` [Qemu-devel] [PATCH v2 10/13] queue.h: Add QLIST_FIX_HEAD_PTR() Kevin Wolf
2015-06-10 23:19 ` Eric Blake
2015-06-12 14:19 ` Max Reitz
2015-06-10 13:47 ` [Qemu-devel] [PATCH v2 11/13] block: Add list of children to BlockDriverState Kevin Wolf
2015-06-10 23:26 ` Eric Blake
2015-06-12 14:23 ` Max Reitz
2015-06-10 13:47 ` Kevin Wolf [this message]
2015-06-10 13:47 ` [Qemu-devel] [PATCH v2 13/13] block: Fix reopen flag inheritance Kevin Wolf
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=1433944027-28533-13-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=berto@igalia.com \
--cc=mreitz@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).