[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 07/25] block: Fix permissions in image activation
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 07/25] block: Fix permissions in image activation |
Date: |
Fri, 17 Nov 2017 19:16:35 +0100 |
Inactive images generally request less permissions for their image files
than they would if they were active (in particular, write permissions).
Activating the image involves extending the permissions, therefore.
drv->bdrv_invalidate_cache() can already require write access to the
image file, so we have to update the permissions earlier than that.
The current code does it only later, so we have to move up this part.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
---
block.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/block.c b/block.c
index 0ed0c27140..752fe6192b 100644
--- a/block.c
+++ b/block.c
@@ -4174,7 +4174,29 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error
**errp)
}
}
+ /*
+ * Update permissions, they may differ for inactive nodes.
+ *
+ * Note that the required permissions of inactive images are always a
+ * subset of the permissions required after activating the image. This
+ * allows us to just get the permissions upfront without restricting
+ * drv->bdrv_invalidate_cache().
+ *
+ * It also means that in error cases, we don't have to try and revert to
+ * the old permissions (which is an operation that could fail, too). We can
+ * just keep the extended permissions for the next time that an activation
+ * of the image is tried.
+ */
bs->open_flags &= ~BDRV_O_INACTIVE;
+ bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
+ ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, &local_err);
+ if (ret < 0) {
+ bs->open_flags |= BDRV_O_INACTIVE;
+ error_propagate(errp, local_err);
+ return;
+ }
+ bdrv_set_perm(bs, perm, shared_perm);
+
if (bs->drv->bdrv_invalidate_cache) {
bs->drv->bdrv_invalidate_cache(bs, &local_err);
if (local_err) {
@@ -4191,16 +4213,6 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error
**errp)
return;
}
- /* Update permissions, they may differ for inactive nodes */
- bdrv_get_cumulative_perm(bs, &perm, &shared_perm);
- ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, &local_err);
- if (ret < 0) {
- bs->open_flags |= BDRV_O_INACTIVE;
- error_propagate(errp, local_err);
- return;
- }
- bdrv_set_perm(bs, perm, shared_perm);
-
QLIST_FOREACH(parent, &bs->parents, next_parent) {
if (parent->role->activate) {
parent->role->activate(parent, &local_err);
--
2.13.6
- [Qemu-devel] [PULL 00/25] Block layer patches for 2.11.0-rc2, Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 02/25] qemu-iotests: Use -nographic in 182, Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 03/25] block: Fix error path in bdrv_backing_update_filename(), Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 04/25] qcow2: don't permit changing encryption parameters, Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 01/25] replication: Fix replication open fail, Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 05/25] block: Deprecate bdrv_set_read_only() and users, Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 07/25] block: Fix permissions in image activation,
Kevin Wolf <=
- [Qemu-devel] [PULL 06/25] qcow2: fix image corruption after committing qcow2 image into base, Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 13/25] block: qobject_is_equal() in bdrv_reopen_prepare(), Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 08/25] iotests: test clearing unknown autoclear_features by qcow2, Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 11/25] qapi/qlist: Add qlist_append_null() macro, Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 10/25] qapi/qnull: Add own header, Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 09/25] qcow2: fix image corruption on commit with persistent bitmap, Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 12/25] qapi: Add qobject_is_equal(), Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 14/25] iotests: Add test for non-string option reopening, Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 15/25] tests: Add check-qobject for equality tests, Kevin Wolf, 2017/11/17
- [Qemu-devel] [PULL 17/25] qcow2: reject unaligned offsets in write compressed, Kevin Wolf, 2017/11/17