diff options
author | Kevin Wolf <kwolf@redhat.com> | 2017-01-20 17:07:26 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2017-02-28 20:40:36 +0100 |
commit | 6d0eb64d5c6d57017c52a4f36ccae1db79215ee1 (patch) | |
tree | ac53990a1e31ff6232f31cb8c9d3a322e960fb4b /block | |
parent | 981776b34875ef75b218a338e1831b8fc65ea6bd (diff) | |
download | qemu-6d0eb64d5c6d57017c52a4f36ccae1db79215ee1.zip qemu-6d0eb64d5c6d57017c52a4f36ccae1db79215ee1.tar.gz qemu-6d0eb64d5c6d57017c52a4f36ccae1db79215ee1.tar.bz2 |
block: Add permissions to blk_new()
We want every user to be specific about the permissions it needs, so
we'll pass the initial permissions as parameters to blk_new(). A user
only needs to call blk_set_perm() if it wants to change the permissions
after the fact.
The permissions are stored in the BlockBackend and applied whenever a
BlockDriverState should be attached in blk_insert_bs().
This does not include actually choosing the right set of permissions
everywhere yet. Instead, the usual FIXME comment is added to each place
and will be addressed in individual patches.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Acked-by: Fam Zheng <famz@redhat.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/backup.c | 3 | ||||
-rw-r--r-- | block/block-backend.c | 21 | ||||
-rw-r--r-- | block/commit.c | 12 | ||||
-rw-r--r-- | block/mirror.c | 3 | ||||
-rw-r--r-- | block/qcow2.c | 2 |
5 files changed, 27 insertions, 14 deletions
diff --git a/block/backup.c b/block/backup.c index fe010e7..4b3c94c 100644 --- a/block/backup.c +++ b/block/backup.c @@ -624,7 +624,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, goto error; } - job->target = blk_new(); + /* FIXME Use real permissions */ + job->target = blk_new(0, BLK_PERM_ALL); blk_insert_bs(job->target, target); job->on_source_error = on_source_error; diff --git a/block/block-backend.c b/block/block-backend.c index 1ed75c6..0319220 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -120,17 +120,23 @@ static const BdrvChildRole child_root = { /* * Create a new BlockBackend with a reference count of one. - * Store an error through @errp on failure, unless it's null. + * + * @perm is a bitmasks of BLK_PERM_* constants which describes the permissions + * to request for a block driver node that is attached to this BlockBackend. + * @shared_perm is a bitmask which describes which permissions may be granted + * to other users of the attached node. + * Both sets of permissions can be changed later using blk_set_perm(). + * * Return the new BlockBackend on success, null on failure. */ -BlockBackend *blk_new(void) +BlockBackend *blk_new(uint64_t perm, uint64_t shared_perm) { BlockBackend *blk; blk = g_new0(BlockBackend, 1); blk->refcnt = 1; - blk->perm = 0; - blk->shared_perm = BLK_PERM_ALL; + blk->perm = perm; + blk->shared_perm = shared_perm; blk_set_enable_write_cache(blk, true); qemu_co_queue_init(&blk->public.throttled_reqs[0]); @@ -161,7 +167,7 @@ BlockBackend *blk_new_open(const char *filename, const char *reference, BlockBackend *blk; BlockDriverState *bs; - blk = blk_new(); + blk = blk_new(0, BLK_PERM_ALL); bs = bdrv_open(filename, reference, options, flags, errp); if (!bs) { blk_unref(blk); @@ -505,9 +511,10 @@ void blk_remove_bs(BlockBackend *blk) void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) { bdrv_ref(bs); - /* FIXME Use real permissions */ + /* FIXME Error handling */ blk->root = bdrv_root_attach_child(bs, "root", &child_root, - 0, BLK_PERM_ALL, blk, &error_abort); + blk->perm, blk->shared_perm, blk, + &error_abort); notifier_list_notify(&blk->insert_bs_notifiers, blk); if (blk->public.throttle_state) { diff --git a/block/commit.c b/block/commit.c index c284e85..1897e98 100644 --- a/block/commit.c +++ b/block/commit.c @@ -275,10 +275,12 @@ void commit_start(const char *job_id, BlockDriverState *bs, block_job_add_bdrv(&s->common, overlay_bs); } - s->base = blk_new(); + /* FIXME Use real permissions */ + s->base = blk_new(0, BLK_PERM_ALL); blk_insert_bs(s->base, base); - s->top = blk_new(); + /* FIXME Use real permissions */ + s->top = blk_new(0, BLK_PERM_ALL); blk_insert_bs(s->top, top); s->active = bs; @@ -328,10 +330,12 @@ int bdrv_commit(BlockDriverState *bs) } } - src = blk_new(); + /* FIXME Use real permissions */ + src = blk_new(0, BLK_PERM_ALL); blk_insert_bs(src, bs); - backing = blk_new(); + /* FIXME Use real permissions */ + backing = blk_new(0, BLK_PERM_ALL); blk_insert_bs(backing, bs->backing->bs); length = blk_getlength(src); diff --git a/block/mirror.c b/block/mirror.c index 1b34b36..30398fb 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1017,7 +1017,8 @@ static void mirror_start_job(const char *job_id, BlockDriverState *bs, return; } - s->target = blk_new(); + /* FIXME Use real permissions */ + s->target = blk_new(0, BLK_PERM_ALL); blk_insert_bs(s->target, target); s->replaces = g_strdup(replaces); diff --git a/block/qcow2.c b/block/qcow2.c index ef028f6..0356e69 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3262,7 +3262,7 @@ static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts, } if (new_size) { - BlockBackend *blk = blk_new(); + BlockBackend *blk = blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL); blk_insert_bs(blk, bs); ret = blk_truncate(blk, new_size); blk_unref(blk); |