diff options
author | Kevin Wolf <kwolf@redhat.com> | 2017-01-20 15:42:39 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2017-02-28 20:40:36 +0100 |
commit | 981776b34875ef75b218a338e1831b8fc65ea6bd (patch) | |
tree | 674bf4a9192d58cded0335b7c5c6ae0a5af8c7ea /block | |
parent | f68c598be6a48995ca4c7cc42fc1f6e1195ec7aa (diff) |
block: Add permissions to BlockBackend
The BlockBackend can now store the permissions that its user requires.
This is necessary because nodes can be ejected from or inserted into a
BlockBackend and all of these operations must make sure that the user
still gets what it requested initially.
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/block-backend.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/block/block-backend.c b/block/block-backend.c index 9bb45285ef..1ed75c6c15 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -59,6 +59,9 @@ struct BlockBackend { bool iostatus_enabled; BlockDeviceIoStatus iostatus; + uint64_t perm; + uint64_t shared_perm; + bool allow_write_beyond_eof; NotifierList remove_bs_notifiers, insert_bs_notifiers; @@ -126,6 +129,8 @@ BlockBackend *blk_new(void) blk = g_new0(BlockBackend, 1); blk->refcnt = 1; + blk->perm = 0; + blk->shared_perm = BLK_PERM_ALL; blk_set_enable_write_cache(blk, true); qemu_co_queue_init(&blk->public.throttled_reqs[0]); @@ -511,6 +516,27 @@ void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs) } } +/* + * Sets the permission bitmasks that the user of the BlockBackend needs. + */ +int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm, + Error **errp) +{ + int ret; + + if (blk->root) { + ret = bdrv_child_try_set_perm(blk->root, perm, shared_perm, errp); + if (ret < 0) { + return ret; + } + } + + blk->perm = perm; + blk->shared_perm = shared_perm; + + return 0; +} + static int blk_do_attach_dev(BlockBackend *blk, void *dev) { if (blk->dev) { @@ -557,6 +583,7 @@ void blk_detach_dev(BlockBackend *blk, void *dev) blk->dev_ops = NULL; blk->dev_opaque = NULL; blk->guest_block_size = 512; + blk_set_perm(blk, 0, BLK_PERM_ALL, &error_abort); blk_unref(blk); } |