[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 12/30] vmdk: Fix partial overwrite of zero cluster
From: |
Kevin Wolf |
Subject: |
[PULL 12/30] vmdk: Fix partial overwrite of zero cluster |
Date: |
Fri, 8 May 2020 14:41:17 +0200 |
When overwriting a zero cluster, we must not perform copy-on-write from
the backing file, but from a zeroed buffer.
Signed-off-by: Kevin Wolf <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/vmdk.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index fcd6b38d64..ab8eec1f27 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1340,7 +1340,9 @@ static void vmdk_refresh_limits(BlockDriverState *bs,
Error **errp)
* get_whole_cluster
*
* Copy backing file's cluster that covers @sector_num, otherwise write zero,
- * to the cluster at @cluster_sector_num.
+ * to the cluster at @cluster_sector_num. If @zeroed is true, we're overwriting
+ * a zeroed cluster in the current layer and must not copy data from the
+ * backing file.
*
* If @skip_start_sector < @skip_end_sector, the relative range
* [@skip_start_sector, @skip_end_sector) is not copied or written, and leave
@@ -1351,18 +1353,21 @@ static int get_whole_cluster(BlockDriverState *bs,
uint64_t cluster_offset,
uint64_t offset,
uint64_t skip_start_bytes,
- uint64_t skip_end_bytes)
+ uint64_t skip_end_bytes,
+ bool zeroed)
{
int ret = VMDK_OK;
int64_t cluster_bytes;
uint8_t *whole_grain;
+ bool copy_from_backing;
/* For COW, align request sector_num to cluster start */
cluster_bytes = extent->cluster_sectors << BDRV_SECTOR_BITS;
offset = QEMU_ALIGN_DOWN(offset, cluster_bytes);
whole_grain = qemu_blockalign(bs, cluster_bytes);
+ copy_from_backing = bs->backing && !zeroed;
- if (!bs->backing) {
+ if (!copy_from_backing) {
memset(whole_grain, 0, skip_start_bytes);
memset(whole_grain + skip_end_bytes, 0, cluster_bytes -
skip_end_bytes);
}
@@ -1377,7 +1382,7 @@ static int get_whole_cluster(BlockDriverState *bs,
/* Read backing data before skip range */
if (skip_start_bytes > 0) {
- if (bs->backing) {
+ if (copy_from_backing) {
/* qcow2 emits this on bs->file instead of bs->backing */
BLKDBG_EVENT(extent->file, BLKDBG_COW_READ);
ret = bdrv_pread(bs->backing, offset, whole_grain,
@@ -1397,7 +1402,7 @@ static int get_whole_cluster(BlockDriverState *bs,
}
/* Read backing data after skip range */
if (skip_end_bytes < cluster_bytes) {
- if (bs->backing) {
+ if (copy_from_backing) {
/* qcow2 emits this on bs->file instead of bs->backing */
BLKDBG_EVENT(extent->file, BLKDBG_COW_READ);
ret = bdrv_pread(bs->backing, offset + skip_end_bytes,
@@ -1631,7 +1636,8 @@ static int get_cluster_offset(BlockDriverState *bs,
* or inappropriate VM shutdown.
*/
ret = get_whole_cluster(bs, extent, cluster_sector * BDRV_SECTOR_SIZE,
- offset, skip_start_bytes, skip_end_bytes);
+ offset, skip_start_bytes, skip_end_bytes,
+ zeroed);
if (ret) {
return ret;
}
--
2.25.3
- [PULL 01/30] iotests: handle tmpfs, (continued)
- [PULL 01/30] iotests: handle tmpfs, Kevin Wolf, 2020/05/08
- [PULL 02/30] iotests/082: require bochs, Kevin Wolf, 2020/05/08
- [PULL 04/30] iotests/041: drop self.assert_no_active_block_jobs(), Kevin Wolf, 2020/05/08
- [PULL 03/30] iotests/148: use skip_if_unsupported, Kevin Wolf, 2020/05/08
- [PULL 06/30] iotests/055: skip vmdk target tests if vmdk is not whitelisted, Kevin Wolf, 2020/05/08
- [PULL 05/30] iotests/055: refactor compressed backup to vmdk, Kevin Wolf, 2020/05/08
- [PULL 07/30] iotests/109: mark required formats as required to support whitelisting, Kevin Wolf, 2020/05/08
- [PULL 08/30] iotests/113: mark bochs as required to support whitelisting, Kevin Wolf, 2020/05/08
- [PULL 10/30] vmdk: Rename VmdkMetaData.valid to new_allocation, Kevin Wolf, 2020/05/08
- [PULL 13/30] vmdk: Don't update L2 table for zero write on zero cluster, Kevin Wolf, 2020/05/08
- [PULL 12/30] vmdk: Fix partial overwrite of zero cluster,
Kevin Wolf <=
- [PULL 11/30] vmdk: Fix zero cluster allocation, Kevin Wolf, 2020/05/08
- [PULL 09/30] qcow2: Avoid integer wraparound in qcow2_co_truncate(), Kevin Wolf, 2020/05/08
- [PULL 14/30] vmdk: Flush only once in vmdk_L2update(), Kevin Wolf, 2020/05/08
- [PULL 16/30] iotests/283: Use consistent size for source and target, Kevin Wolf, 2020/05/08
- [PULL 15/30] iotests: vmdk: Enable zeroed_grained=on by default, Kevin Wolf, 2020/05/08
- [PULL 21/30] qcow2: Fix preallocation on block devices, Kevin Wolf, 2020/05/08
- [PULL 27/30] ssh: Support BDRV_REQ_ZERO_WRITE for truncate, Kevin Wolf, 2020/05/08
- [PULL 22/30] gluster: Drop useless has_zero_init callback, Kevin Wolf, 2020/05/08
- [PULL 17/30] backup: Improve error for bdrv_getlength() failure, Kevin Wolf, 2020/05/08
- [PULL 20/30] iotests/055: Use cache.no-flush for vmdk target, Kevin Wolf, 2020/05/08