[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 12/43] block: Add permissions to BlockBackend
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH v2 12/43] block: Add permissions to BlockBackend |
Date: |
Mon, 27 Feb 2017 21:09:13 +0100 |
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 <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block/block-backend.c | 27 +++++++++++++++++++++++++++
include/sysemu/block-backend.h | 2 ++
2 files changed, 29 insertions(+)
diff --git a/block/block-backend.c b/block/block-backend.c
index 9bb4528..1ed75c6 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);
}
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index f365a51..4a18e86 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -105,6 +105,8 @@ void blk_remove_bs(BlockBackend *blk);
void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs);
bool bdrv_has_blk(BlockDriverState *bs);
bool bdrv_is_root_node(BlockDriverState *bs);
+int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm,
+ Error **errp);
void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow);
void blk_iostatus_enable(BlockBackend *blk);
--
1.8.3.1
- [Qemu-block] [PATCH v2 02/43] block: Add Error argument to bdrv_attach_child(), (continued)
- [Qemu-block] [PATCH v2 02/43] block: Add Error argument to bdrv_attach_child(), Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 03/43] block: Let callers request permissions when attaching a child node, Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 04/43] block: Involve block drivers in permission granting, Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 05/43] block: Default .bdrv_child_perm() for filter drivers, Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 06/43] block: Request child permissions in filter drivers, Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 07/43] block: Default .bdrv_child_perm() for format drivers, Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 08/43] block: Request child permissions in format drivers, Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 09/43] vvfat: Implement .bdrv_child_perm(), Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 10/43] block: Require .bdrv_child_perm() with child nodes, Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 11/43] block: Request real permissions in bdrv_attach_child(), Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 12/43] block: Add permissions to BlockBackend,
Kevin Wolf <=
- [Qemu-block] [PATCH v2 13/43] block: Add permissions to blk_new(), Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 14/43] block: Add error parameter to blk_insert_bs(), Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 15/43] block: Add BDRV_O_RESIZE for blk_new_open(), Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 16/43] block: Request real permissions in blk_new_open(), Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 17/43] block: Allow error return in BlockDevOps.change_media_cb(), Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 18/43] hw/block: Request permissions, Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 19/43] hw/block: Introduce share-rw qdev property, Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 20/43] blockjob: Add permissions to block_job_create(), Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 21/43] block: Add BdrvChildRole.get_parent_desc(), Kevin Wolf, 2017/02/27
- [Qemu-block] [PATCH v2 22/43] block: Include details on permission errors in message, Kevin Wolf, 2017/02/27