[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 09/34] block: Add BlockDriverState.inherits_from
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 09/34] block: Add BlockDriverState.inherits_from |
Date: |
Fri, 8 May 2015 19:21:41 +0200 |
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 <address@hidden>
---
block.c | 17 +++++++++++++++++
include/block/block_int.h | 4 ++++
2 files changed, 21 insertions(+)
diff --git a/block.c b/block.c
index 59f54ed..59585a9 100644
--- a/block.c
+++ b/block.c
@@ -1385,6 +1385,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);
}
@@ -1812,6 +1813,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;
+ }
g_free(child);
}
@@ -1959,6 +1963,7 @@ static void bdrv_move_feature_fields(BlockDriverState
*bs_dest,
void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old)
{
BlockDriverState tmp;
+ BdrvChild *child;
/* The code needs to swap the node_name but simply swapping node_list won't
* work so first remove the nodes from the graph list, do the swap then
@@ -2003,6 +2008,18 @@ void bdrv_swap(BlockDriverState *bs_new,
BlockDriverState *bs_old)
QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs_old, node_list);
}
+ /* 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 12c7fb3..2fad5f8 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -434,6 +434,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
[Qemu-devel] [PATCH 06/34] block: Use QemuOpts in bdrv_open_common(), Kevin Wolf, 2015/05/08
[Qemu-devel] [PATCH 09/34] block: Add BlockDriverState.inherits_from,
Kevin Wolf <=
[Qemu-devel] [PATCH 10/34] block: Fix reopen flag inheritance, Kevin Wolf, 2015/05/08
[Qemu-devel] [PATCH 07/34] block: Move flag inheritance to bdrv_open_inherited(), Kevin Wolf, 2015/05/08