Skip to content

Commit

Permalink
block: Always call bdrv_child_check_perm first
Browse files Browse the repository at this point in the history
bdrv_child_set_perm alone is not very usable because the caller must
call bdrv_child_check_perm first. This is already encapsulated
conveniently in bdrv_child_try_set_perm, so remove the other prototypes
from the header and fix the one wrong caller, block/mirror.c.

Signed-off-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
Fam Zheng authored and kevmw committed Mar 17, 2017
1 parent fed414d commit c1cef67
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
13 changes: 9 additions & 4 deletions block.c
Expand Up @@ -1393,6 +1393,11 @@ static int bdrv_fill_options(QDict **options, const char *filename,
return 0;
}

static int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
GSList *ignore_children, Error **errp);
static void bdrv_child_abort_perm_update(BdrvChild *c);
static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared);

/*
* Check whether permissions on this node can be changed in a way that
* @cumulative_perms and @cumulative_shared_perms are the new cumulative
Expand Down Expand Up @@ -1615,8 +1620,8 @@ static int bdrv_check_update_perm(BlockDriverState *bs, uint64_t new_used_perm,

/* Needs to be followed by a call to either bdrv_child_set_perm() or
* bdrv_child_abort_perm_update(). */
int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
GSList *ignore_children, Error **errp)
static int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
GSList *ignore_children, Error **errp)
{
int ret;

Expand All @@ -1627,7 +1632,7 @@ int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
return ret;
}

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

Expand All @@ -1639,7 +1644,7 @@ void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared)
bdrv_set_perm(c->bs, cumulative_perms, cumulative_shared_perms);
}

void bdrv_child_abort_perm_update(BdrvChild *c)
static void bdrv_child_abort_perm_update(BdrvChild *c)
{
bdrv_abort_perm_update(c->bs);
}
Expand Down
6 changes: 4 additions & 2 deletions block/mirror.c
Expand Up @@ -574,7 +574,8 @@ static void mirror_exit(BlockJob *job, void *opaque)
* valid. Also give up permissions on mirror_top_bs->backing, which might
* block the removal. */
block_job_remove_all_bdrv(job);
bdrv_child_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL);
bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL,
&error_abort);
bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abort);

/* We just changed the BDS the job BB refers to (with either or both of the
Expand Down Expand Up @@ -1245,7 +1246,8 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs,
block_job_unref(&s->common);
}

bdrv_child_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL);
bdrv_child_try_set_perm(mirror_top_bs->backing, 0, BLK_PERM_ALL,
&error_abort);
bdrv_replace_node(mirror_top_bs, backing_bs(mirror_top_bs), &error_abort);
}

Expand Down
4 changes: 0 additions & 4 deletions include/block/block_int.h
Expand Up @@ -889,10 +889,6 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
void *opaque, Error **errp);
void bdrv_root_unref_child(BdrvChild *child);

int bdrv_child_check_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
GSList *ignore_children, Error **errp);
void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared);
void bdrv_child_abort_perm_update(BdrvChild *c);
int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
Error **errp);

Expand Down

0 comments on commit c1cef67

Please sign in to comment.