[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 12/34] block: Unify bdrv_child_cb_attach()
From: |
Max Reitz |
Subject: |
[PATCH v4 12/34] block: Unify bdrv_child_cb_attach() |
Date: |
Wed, 13 May 2020 13:05:22 +0200 |
Make bdrv_child_cb_attach() call bdrv_backing_attach() for children with
a COW role (and drop the reverse call from bdrv_backing_attach()), so it
can be used for any child (with a proper role set).
Because so far no child has a proper role set, we need a temporary new
callback for child_backing.attach that ensures bdrv_backing_attach() is
called for all COW children that do not have their role set yet.
(Also, move bdrv_child_cb_attach() down to group it with
bdrv_inherited_options().)
Signed-off-by: Max Reitz <address@hidden>
---
block.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/block.c b/block.c
index b3b978a092..755704a54c 100644
--- a/block.c
+++ b/block.c
@@ -84,6 +84,7 @@ static BlockDriverState *bdrv_open_inherit(const char
*filename,
static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format,
int *child_flags, QDict *child_options,
int parent_flags, QDict *parent_options);
+static void bdrv_child_cb_attach(BdrvChild *child);
/* If non-zero, use only whitelisted block drivers */
static int use_bdrv_whitelist;
@@ -1099,12 +1100,6 @@ static void bdrv_child_cb_drained_end(BdrvChild *child,
bdrv_drained_end_no_poll(bs, drained_end_counter);
}
-static void bdrv_child_cb_attach(BdrvChild *child)
-{
- BlockDriverState *bs = child->opaque;
- bdrv_apply_subtree_drain(child, bs);
-}
-
static void bdrv_child_cb_detach(BdrvChild *child)
{
BlockDriverState *bs = child->opaque;
@@ -1252,7 +1247,14 @@ static void bdrv_backing_attach(BdrvChild *c)
parent->backing_blocker);
bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_BACKUP_TARGET,
parent->backing_blocker);
+}
+/* XXX: Will be removed along with child_backing */
+static void bdrv_child_cb_attach_backing(BdrvChild *c)
+{
+ if (!(c->role & BDRV_CHILD_COW)) {
+ bdrv_backing_attach(c);
+ }
bdrv_child_cb_attach(c);
}
@@ -1311,7 +1313,7 @@ static int bdrv_backing_update_filename(BdrvChild *c,
BlockDriverState *base,
const BdrvChildClass child_backing = {
.parent_is_bds = true,
.get_parent_desc = bdrv_child_get_parent_desc,
- .attach = bdrv_backing_attach,
+ .attach = bdrv_child_cb_attach_backing,
.detach = bdrv_backing_detach,
.inherit_options = bdrv_backing_options,
.drained_begin = bdrv_child_cb_drained_begin,
@@ -1403,6 +1405,17 @@ static void bdrv_inherited_options(BdrvChildRole role,
bool parent_is_format,
*child_flags = flags;
}
+static void bdrv_child_cb_attach(BdrvChild *child)
+{
+ BlockDriverState *bs = child->opaque;
+
+ if (child->role & BDRV_CHILD_COW) {
+ bdrv_backing_attach(child);
+ }
+
+ bdrv_apply_subtree_drain(child, bs);
+}
+
static int bdrv_open_flags(BlockDriverState *bs, int flags)
{
int open_flags = flags;
--
2.26.2
- [PATCH v4 03/34] block: Rename BdrvChildRole to BdrvChildClass, (continued)
- [PATCH v4 03/34] block: Rename BdrvChildRole to BdrvChildClass, Max Reitz, 2020/05/13
- [PATCH v4 05/34] block: Add BdrvChildRole to BdrvChild, Max Reitz, 2020/05/13
- [PATCH v4 06/34] block: Pass BdrvChildRole to bdrv_child_perm(), Max Reitz, 2020/05/13
- [PATCH v4 07/34] block: Pass BdrvChildRole to .inherit_options(), Max Reitz, 2020/05/13
- [PATCH v4 08/34] block: Pass parent_is_format to .inherit_options(), Max Reitz, 2020/05/13
- [PATCH v4 09/34] block: Rename bdrv_inherited_options(), Max Reitz, 2020/05/13
- [PATCH v4 10/34] block: Add generic bdrv_inherited_options(), Max Reitz, 2020/05/13
- [PATCH v4 11/34] block: Use bdrv_inherited_options(), Max Reitz, 2020/05/13
- [PATCH v4 12/34] block: Unify bdrv_child_cb_attach(),
Max Reitz <=
- [PATCH v4 13/34] block: Unify bdrv_child_cb_detach(), Max Reitz, 2020/05/13
- [PATCH v4 14/34] block: Add child_of_bds, Max Reitz, 2020/05/13
- [PATCH v4 15/34] block: Distinguish paths in *_format_default_perms, Max Reitz, 2020/05/13
- [PATCH v4 16/34] block: Pull out bdrv_default_perms_for_cow(), Max Reitz, 2020/05/13
- [PATCH v4 17/34] block: Pull out bdrv_default_perms_for_storage(), Max Reitz, 2020/05/13