[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 30/51] block: Relax *perms_for_storage for data children
From: |
Kevin Wolf |
Subject: |
[PULL 30/51] block: Relax *perms_for_storage for data children |
Date: |
Fri, 15 May 2020 14:45:00 +0200 |
From: Max Reitz <address@hidden>
We can be less restrictive about pure data children than those with
metadata on them, so let bdrv_default_perms_for_storage() handle
metadata children differently from pure data children.
As explained in the code, the restrictions on metadata children are
strictly stricter than those for pure data children, so in theory we
just have to distinguish between pure-data and all other storage
children (pure metadata or data+metadata). In practice, that is not
obvious, though, so we have two independent code paths for metadata and
for data children, and data+metadata children will go through both
(without the path for data children doing anything meaningful).
Signed-off-by: Max Reitz <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 48 insertions(+), 10 deletions(-)
diff --git a/block.c b/block.c
index 5d17aa1cc3..5ff6cbd796 100644
--- a/block.c
+++ b/block.c
@@ -2528,19 +2528,57 @@ static void
bdrv_default_perms_for_storage(BlockDriverState *bs, BdrvChild *c,
bdrv_filter_default_perms(bs, c, child_class, role, reopen_queue,
perm, shared, &perm, &shared);
- /* Format drivers may touch metadata even if the guest doesn't write */
- if (bdrv_is_writable_after_reopen(bs, reopen_queue)) {
- perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
+ if (role & BDRV_CHILD_METADATA) {
+ /* Format drivers may touch metadata even if the guest doesn't write */
+ if (bdrv_is_writable_after_reopen(bs, reopen_queue)) {
+ perm |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
+ }
+
+ /*
+ * bs->file always needs to be consistent because of the
+ * metadata. We can never allow other users to resize or write
+ * to it.
+ */
+ if (!(flags & BDRV_O_NO_IO)) {
+ perm |= BLK_PERM_CONSISTENT_READ;
+ }
+ shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE);
}
- /*
- * bs->file always needs to be consistent because of the metadata. We
- * can never allow other users to resize or write to it.
- */
- if (!(flags & BDRV_O_NO_IO)) {
- perm |= BLK_PERM_CONSISTENT_READ;
+ if (role & BDRV_CHILD_DATA) {
+ /*
+ * Technically, everything in this block is a subset of the
+ * BDRV_CHILD_METADATA path taken above, and so this could
+ * be an "else if" branch. However, that is not obvious, and
+ * this function is not performance critical, therefore we let
+ * this be an independent "if".
+ */
+
+ /*
+ * We cannot allow other users to resize the file because the
+ * format driver might have some assumptions about the size
+ * (e.g. because it is stored in metadata, or because the file
+ * is split into fixed-size data files).
+ */
+ shared &= ~BLK_PERM_RESIZE;
+
+ /*
+ * WRITE_UNCHANGED often cannot be performed as such on the
+ * data file. For example, the qcow2 driver may still need to
+ * write copied clusters on copy-on-read.
+ */
+ if (perm & BLK_PERM_WRITE_UNCHANGED) {
+ perm |= BLK_PERM_WRITE;
+ }
+
+ /*
+ * If the data file is written to, the format driver may
+ * expect to be able to resize it by writing beyond the EOF.
+ */
+ if (perm & BLK_PERM_WRITE) {
+ perm |= BLK_PERM_RESIZE;
+ }
}
- shared &= ~(BLK_PERM_WRITE | BLK_PERM_RESIZE);
if (bs->open_flags & BDRV_O_INACTIVE) {
shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
--
2.25.4
- [PULL 23/51] block: Use bdrv_inherited_options(), (continued)
- [PULL 23/51] block: Use bdrv_inherited_options(), Kevin Wolf, 2020/05/15
- [PULL 20/51] block: Pass parent_is_format to .inherit_options(), Kevin Wolf, 2020/05/15
- [PULL 18/51] block: Pass BdrvChildRole to bdrv_child_perm(), Kevin Wolf, 2020/05/15
- [PULL 25/51] block: Unify bdrv_child_cb_detach(), Kevin Wolf, 2020/05/15
- [PULL 28/51] block: Pull out bdrv_default_perms_for_cow(), Kevin Wolf, 2020/05/15
- [PULL 27/51] block: Distinguish paths in *_format_default_perms, Kevin Wolf, 2020/05/15
- [PULL 26/51] block: Add child_of_bds, Kevin Wolf, 2020/05/15
- [PULL 29/51] block: Pull out bdrv_default_perms_for_storage(), Kevin Wolf, 2020/05/15
- [PULL 21/51] block: Rename bdrv_inherited_options(), Kevin Wolf, 2020/05/15
- [PULL 24/51] block: Unify bdrv_child_cb_attach(), Kevin Wolf, 2020/05/15
- [PULL 30/51] block: Relax *perms_for_storage for data children,
Kevin Wolf <=
- [PULL 31/51] block: Add bdrv_default_perms(), Kevin Wolf, 2020/05/15
- [PULL 32/51] raw-format: Split raw_read_options(), Kevin Wolf, 2020/05/15
- [PULL 34/51] block: Drop child_format, Kevin Wolf, 2020/05/15
- [PULL 33/51] block: Switch child_format users to child_of_bds, Kevin Wolf, 2020/05/15
- [PULL 37/51] block: Make format drivers use child_of_bds, Kevin Wolf, 2020/05/15
- [PULL 35/51] block: Make backing files child_of_bds children, Kevin Wolf, 2020/05/15
- [PULL 36/51] block: Drop child_backing, Kevin Wolf, 2020/05/15
- [PULL 38/51] block: Make filter drivers use child_of_bds, Kevin Wolf, 2020/05/15
- [PULL 39/51] block: Use child_of_bds in remaining places, Kevin Wolf, 2020/05/15
- [PULL 40/51] tests: Use child_of_bds instead of child_file, Kevin Wolf, 2020/05/15