[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 07/14] block: Add bdrv_child_refresh_perms()
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 07/14] block: Add bdrv_child_refresh_perms() |
Date: |
Tue, 18 Jun 2019 17:23:11 +0200 |
From: Max Reitz <address@hidden>
If a block node uses bdrv_child_try_set_perm() to change the permission
it takes on its child, the result may be very short-lived. If anything
makes the block layer recalculate the permissions internally, it will
invoke the node driver's .bdrv_child_perm() implementation. The
permission/shared permissions masks that returns will then override the
values previously passed to bdrv_child_try_set_perm().
If drivers want a child edge to have specific values for the
permissions/shared permissions mask, it must return them in
.bdrv_child_perm(). Consequentially, there is no need for them to pass
the same values to bdrv_child_try_set_perm() then: It is better to have
a function that invokes .bdrv_child_perm() and calls
bdrv_child_try_set_perm() with the result. This patch adds such a
function under the name of bdrv_child_refresh_perms().
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
include/block/block_int.h | 15 +++++++++++++++
block.c | 12 ++++++++++++
2 files changed, 27 insertions(+)
diff --git a/include/block/block_int.h b/include/block/block_int.h
index a498c2670b..d6415b53c1 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -1165,9 +1165,24 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState
*child_bs,
void *opaque, Error **errp);
void bdrv_root_unref_child(BdrvChild *child);
+/**
+ * Sets a BdrvChild's permissions. Avoid if the parent is a BDS; use
+ * bdrv_child_refresh_perms() instead and make the parent's
+ * .bdrv_child_perm() implementation return the correct values.
+ */
int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
Error **errp);
+/**
+ * Calls bs->drv->bdrv_child_perm() and updates the child's permission
+ * masks with the result.
+ * Drivers should invoke this function whenever an event occurs that
+ * makes their .bdrv_child_perm() implementation return different
+ * values than before, but which will not result in the block layer
+ * automatically refreshing the permissions.
+ */
+int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp);
+
/* Default implementation for BlockDriver.bdrv_child_perm() that can be used by
* block filters: Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED and RESIZE to
* all children */
diff --git a/block.c b/block.c
index ceb2ea23c5..013369851b 100644
--- a/block.c
+++ b/block.c
@@ -2083,6 +2083,18 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm,
uint64_t shared,
return 0;
}
+int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp)
+{
+ uint64_t parent_perms, parent_shared;
+ uint64_t perms, shared;
+
+ bdrv_get_cumulative_perm(bs, &parent_perms, &parent_shared);
+ bdrv_child_perm(bs, c->bs, c, c->role, NULL, parent_perms, parent_shared,
+ &perms, &shared);
+
+ return bdrv_child_try_set_perm(c, perms, shared, errp);
+}
+
void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c,
const BdrvChildRole *role,
BlockReopenQueue *reopen_queue,
--
2.20.1
- [Qemu-block] [PULL 00/14] Block layer patches, Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 01/14] iotests: Hide timestamps for skipped tests, Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 03/14] block/block-backend: blk_iostatus_reset: drop usage of bs->job, Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 02/14] block/replication: drop usage of bs->job, Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 09/14] block/commit: Drop bdrv_child_try_set_perm(), Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 08/14] block/mirror: Fix child permissions, Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 05/14] block: drop bs->job, Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 06/14] file-posix: Update open_flags in raw_set_perm(), Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 07/14] block: Add bdrv_child_refresh_perms(),
Kevin Wolf <=
- [Qemu-block] [PULL 11/14] block: Add *tighten_restrictions to *check*_perm(), Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 04/14] blockdev: blockdev_mark_auto_del: drop usage of bs->job, Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 13/14] iotests: Test failure to loosen restrictions, Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 12/14] block: Ignore loosening perm restrictions failures, Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 10/14] block: Fix order in bdrv_replace_child(), Kevin Wolf, 2019/06/18
- [Qemu-block] [PULL 14/14] block/null: Expose read-zeroes option in QAPI schema, Kevin Wolf, 2019/06/18
- Re: [Qemu-block] [Qemu-devel] [PULL 00/14] Block layer patches, Peter Maydell, 2019/06/18