Skip to content

Commit

Permalink
block: Unify bdrv_child_cb_detach()
Browse files Browse the repository at this point in the history
Make bdrv_child_cb_detach() call bdrv_backing_detach() for children with
a COW role (and drop the reverse call from bdrv_backing_detach()), 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.detach that ensures bdrv_backing_detach() is
called for all COW children that do not have their role set yet.

(Also, move bdrv_child_cb_detach() down to group it with
bdrv_inherited_options() and bdrv_child_cb_attach().)

Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200513110544.176672-14-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
XanClic authored and kevmw committed May 18, 2020
1 parent ca2f123 commit 48e0828
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions block.c
Expand Up @@ -85,6 +85,7 @@ 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);
static void bdrv_child_cb_detach(BdrvChild *child);

/* If non-zero, use only whitelisted block drivers */
static int use_bdrv_whitelist;
Expand Down Expand Up @@ -1100,12 +1101,6 @@ static void bdrv_child_cb_drained_end(BdrvChild *child,
bdrv_drained_end_no_poll(bs, drained_end_counter);
}

static void bdrv_child_cb_detach(BdrvChild *child)
{
BlockDriverState *bs = child->opaque;
bdrv_unapply_subtree_drain(child, bs);
}

static int bdrv_child_cb_inactivate(BdrvChild *child)
{
BlockDriverState *bs = child->opaque;
Expand Down Expand Up @@ -1266,7 +1261,14 @@ static void bdrv_backing_detach(BdrvChild *c)
bdrv_op_unblock_all(c->bs, parent->backing_blocker);
error_free(parent->backing_blocker);
parent->backing_blocker = NULL;
}

/* XXX: Will be removed along with child_backing */
static void bdrv_child_cb_detach_backing(BdrvChild *c)
{
if (!(c->role & BDRV_CHILD_COW)) {
bdrv_backing_detach(c);
}
bdrv_child_cb_detach(c);
}

Expand Down Expand Up @@ -1314,7 +1316,7 @@ const BdrvChildClass child_backing = {
.parent_is_bds = true,
.get_parent_desc = bdrv_child_get_parent_desc,
.attach = bdrv_child_cb_attach_backing,
.detach = bdrv_backing_detach,
.detach = bdrv_child_cb_detach_backing,
.inherit_options = bdrv_backing_options,
.drained_begin = bdrv_child_cb_drained_begin,
.drained_poll = bdrv_child_cb_drained_poll,
Expand Down Expand Up @@ -1416,6 +1418,17 @@ static void bdrv_child_cb_attach(BdrvChild *child)
bdrv_apply_subtree_drain(child, bs);
}

static void bdrv_child_cb_detach(BdrvChild *child)
{
BlockDriverState *bs = child->opaque;

if (child->role & BDRV_CHILD_COW) {
bdrv_backing_detach(child);
}

bdrv_unapply_subtree_drain(child, bs);
}

static int bdrv_open_flags(BlockDriverState *bs, int flags)
{
int open_flags = flags;
Expand Down

0 comments on commit 48e0828

Please sign in to comment.