Skip to content

Commit

Permalink
block: bdrv_set_perm() drop redundant parameters.
Browse files Browse the repository at this point in the history
We should never set permissions other than cumulative permissions of
parents. During bdrv_reopen_multiple() we _check_ for synthetic
permissions but when we do _set_ the graph is already updated.
Add an assertion to bdrv_reopen_multiple(), other cases are more
obvious.

Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Max Reitz <[email protected]>
Signed-off-by: Max Reitz <[email protected]>
  • Loading branch information
Vladimir Sementsov-Ogievskiy authored and XanClic committed Dec 18, 2020
1 parent bb87e4d commit 74ad9a3
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -2112,16 +2112,18 @@ static void bdrv_abort_perm_update(BlockDriverState *bs)
}
}

static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms,
uint64_t cumulative_shared_perms)
static void bdrv_set_perm(BlockDriverState *bs)
{
uint64_t cumulative_perms, cumulative_shared_perms;
BlockDriver *drv = bs->drv;
BdrvChild *c;

if (!drv) {
return;
}

bdrv_get_cumulative_perm(bs, &cumulative_perms, &cumulative_shared_perms);

/* Update this node */
if (drv->bdrv_set_perm) {
drv->bdrv_set_perm(bs, cumulative_perms, cumulative_shared_perms);
Expand Down Expand Up @@ -2304,16 +2306,12 @@ static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q,

static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared)
{
uint64_t cumulative_perms, cumulative_shared_perms;

c->has_backup_perm = false;

c->perm = perm;
c->shared_perm = shared;

bdrv_get_cumulative_perm(c->bs, &cumulative_perms,
&cumulative_shared_perms);
bdrv_set_perm(c->bs, cumulative_perms, cumulative_shared_perms);
bdrv_set_perm(c->bs);
}

static void bdrv_child_abort_perm_update(BdrvChild *c)
Expand All @@ -2340,7 +2338,7 @@ static int bdrv_refresh_perms(BlockDriverState *bs, bool *tighten_restrictions,
bdrv_abort_perm_update(bs);
return ret;
}
bdrv_set_perm(bs, perm, shared_perm);
bdrv_set_perm(bs);

return 0;
}
Expand Down Expand Up @@ -2641,7 +2639,6 @@ static void bdrv_replace_child_noperm(BdrvChild *child,
static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs)
{
BlockDriverState *old_bs = child->bs;
uint64_t perm, shared_perm;

/* Asserts that child->frozen == false */
bdrv_replace_child_noperm(child, new_bs);
Expand All @@ -2655,8 +2652,7 @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs)
* restrictions.
*/
if (new_bs) {
bdrv_get_cumulative_perm(new_bs, &perm, &shared_perm);
bdrv_set_perm(new_bs, perm, shared_perm);
bdrv_set_perm(new_bs);
}

if (old_bs) {
Expand Down Expand Up @@ -3874,7 +3870,13 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp)
}

if (ret == 0) {
bdrv_set_perm(state->bs, state->perm, state->shared_perm);
uint64_t perm, shared;

bdrv_get_cumulative_perm(state->bs, &perm, &shared);
assert(perm == state->perm);
assert(shared == state->shared_perm);

bdrv_set_perm(state->bs);
} else {
bdrv_abort_perm_update(state->bs);
if (state->replace_backing_bs && state->new_backing_bs) {
Expand Down Expand Up @@ -4644,8 +4646,7 @@ static void bdrv_replace_node_common(BlockDriverState *from,
bdrv_unref(from);
}

bdrv_get_cumulative_perm(to, &perm, &shared);
bdrv_set_perm(to, perm, shared);
bdrv_set_perm(to);

out:
g_slist_free(list);
Expand Down

0 comments on commit 74ad9a3

Please sign in to comment.