Skip to content

Commit

Permalink
block.c: assertions to the block layer permissions API
Browse files Browse the repository at this point in the history
Now that we "covered" the three main cases where the
permission API was being used under BQL (fuse,
amend and invalidate_cache), we can safely assert for
the permission functions implemented in block.c

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Message-Id: <20220303151616.325444-11-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
esposem authored and kevmw committed Mar 4, 2022
1 parent 37868b2 commit 862fded
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions block.c
Expand Up @@ -2109,6 +2109,7 @@ static bool bdrv_a_allow_b(BdrvChild *a, BdrvChild *b, Error **errp)

assert(a->bs);
assert(a->bs == b->bs);
GLOBAL_STATE_CODE();

if ((b->perm & a->shared_perm) == b->perm) {
return true;
Expand All @@ -2132,6 +2133,7 @@ static bool bdrv_a_allow_b(BdrvChild *a, BdrvChild *b, Error **errp)
static bool bdrv_parent_perms_conflict(BlockDriverState *bs, Error **errp)
{
BdrvChild *a, *b;
GLOBAL_STATE_CODE();

/*
* During the loop we'll look at each pair twice. That's correct because
Expand Down Expand Up @@ -2213,6 +2215,8 @@ static void bdrv_child_set_perm_abort(void *opaque)
{
BdrvChildSetPermState *s = opaque;

GLOBAL_STATE_CODE();

s->child->perm = s->old_perm;
s->child->shared_perm = s->old_shared_perm;
}
Expand All @@ -2226,6 +2230,7 @@ static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm,
uint64_t shared, Transaction *tran)
{
BdrvChildSetPermState *s = g_new(BdrvChildSetPermState, 1);
GLOBAL_STATE_CODE();

*s = (BdrvChildSetPermState) {
.child = c,
Expand Down Expand Up @@ -2405,6 +2410,7 @@ static int bdrv_node_refresh_perm(BlockDriverState *bs, BlockReopenQueue *q,
BdrvChild *c;
int ret;
uint64_t cumulative_perms, cumulative_shared_perms;
GLOBAL_STATE_CODE();

bdrv_get_cumulative_perm(bs, &cumulative_perms, &cumulative_shared_perms);

Expand Down Expand Up @@ -2473,6 +2479,7 @@ static int bdrv_list_refresh_perms(GSList *list, BlockReopenQueue *q,
{
int ret;
BlockDriverState *bs;
GLOBAL_STATE_CODE();

for ( ; list; list = list->next) {
bs = list->data;
Expand Down Expand Up @@ -2540,6 +2547,7 @@ static int bdrv_refresh_perms(BlockDriverState *bs, Error **errp)
int ret;
Transaction *tran = tran_new();
g_autoptr(GSList) list = bdrv_topological_dfs(NULL, NULL, bs);
GLOBAL_STATE_CODE();

ret = bdrv_list_refresh_perms(list, NULL, tran, errp);
tran_finalize(tran, ret);
Expand Down Expand Up @@ -2602,6 +2610,7 @@ static void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c,
uint64_t perm, uint64_t shared,
uint64_t *nperm, uint64_t *nshared)
{
GLOBAL_STATE_CODE();
*nperm = perm & DEFAULT_PERM_PASSTHROUGH;
*nshared = (shared & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UNCHANGED;
}
Expand All @@ -2613,6 +2622,7 @@ static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c,
uint64_t *nperm, uint64_t *nshared)
{
assert(role & BDRV_CHILD_COW);
GLOBAL_STATE_CODE();

/*
* We want consistent read from backing files if the parent needs it.
Expand Down Expand Up @@ -2649,6 +2659,7 @@ static void bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c,
{
int flags;

GLOBAL_STATE_CODE();
assert(role & (BDRV_CHILD_METADATA | BDRV_CHILD_DATA));

flags = bdrv_reopen_get_flags(reopen_queue, bs);
Expand Down Expand Up @@ -6028,6 +6039,7 @@ static void xdbg_graph_add_edge(XDbgBlockGraphConstructor *gr, void *parent,
{
BlockPermission qapi_perm;
XDbgBlockGraphEdge *edge;
GLOBAL_STATE_CODE();

edge = g_new0(XDbgBlockGraphEdge, 1);

Expand Down

0 comments on commit 862fded

Please sign in to comment.