[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 06/17] block: Improve bdrv_has_zero_init_truncate with backing fi
From: |
Eric Blake |
Subject: |
[PATCH 06/17] block: Improve bdrv_has_zero_init_truncate with backing file |
Date: |
Fri, 31 Jan 2020 11:44:25 -0600 |
When we added bdrv_has_zero_init_truncate(), we chose to blindly
return 0 if a backing file was present, because we knew of the corner
case where a backing layer larger than the current layer might leak
the tail of the backing layer into the resized region. But as this
setup is rare, it penalizes the more common case of a backing layer
smaller than the current layer.
Signed-off-by: Eric Blake <address@hidden>
---
block.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/block.c b/block.c
index 296845040e59..d132662f3103 100644
--- a/block.c
+++ b/block.c
@@ -5112,9 +5112,19 @@ int bdrv_has_zero_init_truncate(BlockDriverState *bs)
return 0;
}
+ /*
+ * If the current layer is smaller than the backing layer,
+ * truncation may expose backing data; treat failure to query size
+ * in the same manner. Otherwise, we can trust the driver.
+ */
+
if (bs->backing) {
- /* Depends on the backing image length, but better safe than sorry */
- return 0;
+ int64_t back = bdrv_getlength(bs->backing->bs);
+ int64_t curr = bdrv_getlength(bs);
+
+ if (back < 0 || curr < back) {
+ return 0;
+ }
}
if (bs->drv->bdrv_has_zero_init_truncate) {
return bs->drv->bdrv_has_zero_init_truncate(bs);
--
2.24.1
- [PATCH 00/17] Improve qcow2 all-zero detection, Eric Blake, 2020/01/31
- [PATCH 04/17] block: Improve documentation of .bdrv_has_zero_init, Eric Blake, 2020/01/31
- [PATCH 01/17] qcow2: Comment typo fixes, Eric Blake, 2020/01/31
- [PATCH 02/17] qcow2: List autoclear bit names in header, Eric Blake, 2020/01/31
- [PATCH 07/17] gluster: Drop useless has_zero_init callback, Eric Blake, 2020/01/31
- [PATCH 06/17] block: Improve bdrv_has_zero_init_truncate with backing file,
Eric Blake <=
- [PATCH 05/17] block: Don't advertise zero_init_truncate with encryption, Eric Blake, 2020/01/31
- [PATCH 03/17] qcow2: Avoid feature name extension on small cluster size, Eric Blake, 2020/01/31
- [PATCH 08/17] sheepdog: Consistently set bdrv_has_zero_init_truncate, Eric Blake, 2020/01/31
- [PATCH 10/17] block: Add new BDRV_ZERO_OPEN flag, Eric Blake, 2020/01/31
- [PATCH 11/17] file-posix: Support BDRV_ZERO_OPEN, Eric Blake, 2020/01/31
- [PATCH 09/17] block: Refactor bdrv_has_zero_init{,_truncate}, Eric Blake, 2020/01/31
- [PATCH 12/17] gluster: Support BDRV_ZERO_OPEN, Eric Blake, 2020/01/31
- [PATCH 13/17] qcow2: Add new autoclear feature for all zero image, Eric Blake, 2020/01/31
- [PATCH 15/17] qcow2: Implement all-zero autoclear bit, Eric Blake, 2020/01/31