Skip to content

Commit

Permalink
block: add bdrv_attach_child_noperm() transaction action
Browse files Browse the repository at this point in the history
Split no-perm part of bdrv_attach_child as separate transaction action.
It will be used in later commits.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20210428151804.439460-20-vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
Vladimir Sementsov-Ogievskiy authored and kevmw committed Apr 30, 2021
1 parent 548a74c commit aa5a04c
Showing 1 changed file with 58 additions and 13 deletions.
71 changes: 58 additions & 13 deletions block.c
Expand Up @@ -85,6 +85,14 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,

static void bdrv_replace_child_noperm(BdrvChild *child,
BlockDriverState *new_bs);
static int bdrv_attach_child_noperm(BlockDriverState *parent_bs,
BlockDriverState *child_bs,
const char *child_name,
const BdrvChildClass *child_class,
BdrvChildRole child_role,
BdrvChild **child,
Transaction *tran,
Error **errp);

static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue
*queue, Error **errp);
Expand Down Expand Up @@ -3079,6 +3087,40 @@ static int bdrv_attach_child_common(BlockDriverState *child_bs,
return 0;
}

static int bdrv_attach_child_noperm(BlockDriverState *parent_bs,
BlockDriverState *child_bs,
const char *child_name,
const BdrvChildClass *child_class,
BdrvChildRole child_role,
BdrvChild **child,
Transaction *tran,
Error **errp)
{
int ret;
uint64_t perm, shared_perm;

assert(parent_bs->drv);

bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm);
bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL,
perm, shared_perm, &perm, &shared_perm);

ret = bdrv_attach_child_common(child_bs, child_name, child_class,
child_role, perm, shared_perm, parent_bs,
child, tran, errp);
if (ret < 0) {
return ret;
}

QLIST_INSERT_HEAD(&parent_bs->children, *child, next);
/*
* child is removed in bdrv_attach_child_common_abort(), so don't care to
* abort this change separately.
*/

return 0;
}

static void bdrv_detach_child(BdrvChild *child)
{
bdrv_replace_child(child, NULL);
Expand Down Expand Up @@ -3139,23 +3181,26 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
BdrvChildRole child_role,
Error **errp)
{
BdrvChild *child;
uint64_t perm, shared_perm;

bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm);
int ret;
BdrvChild *child = NULL;
Transaction *tran = tran_new();

assert(parent_bs->drv);
bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL,
perm, shared_perm, &perm, &shared_perm);
ret = bdrv_attach_child_noperm(parent_bs, child_bs, child_name, child_class,
child_role, &child, tran, errp);
if (ret < 0) {
goto out;
}

child = bdrv_root_attach_child(child_bs, child_name, child_class,
child_role, perm, shared_perm, parent_bs,
errp);
if (child == NULL) {
return NULL;
ret = bdrv_refresh_perms(parent_bs, errp);
if (ret < 0) {
goto out;
}

QLIST_INSERT_HEAD(&parent_bs->children, child, next);
out:
tran_finalize(tran, ret);

bdrv_unref(child_bs);

return child;
}

Expand Down

0 comments on commit aa5a04c

Please sign in to comment.