[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/6] vmdk: Fix zero cluster allocation
From: |
Kevin Wolf |
Subject: |
[PATCH 2/6] vmdk: Fix zero cluster allocation |
Date: |
Thu, 30 Apr 2020 15:30:03 +0200 |
m_data must be contain valid data even for zero clusters when no cluster
was allocated in the image file. Without this, zero writes segfault with
images that have zeroed_grain=on.
For zero writes, we don't want to allocate a cluster in the image file
even in compressed files.
Fixes: 524089bce43fd1cd3daaca979872451efa2cf7c6
Signed-off-by: Kevin Wolf <address@hidden>
---
block/vmdk.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index 5b09275578..bdd7d2dcf1 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1572,6 +1572,12 @@ static int get_cluster_offset(BlockDriverState *bs,
extent->l2_cache_counts[min_index] = 1;
found:
l2_index = ((offset >> 9) / extent->cluster_sectors) % extent->l2_size;
+ if (m_data) {
+ m_data->l1_index = l1_index;
+ m_data->l2_index = l2_index;
+ m_data->l2_offset = l2_offset;
+ m_data->l2_cache_entry = ((uint32_t *)l2_table) + l2_index;
+ }
if (extent->sesparse) {
cluster_sector = le64_to_cpu(((uint64_t *)l2_table)[l2_index]);
@@ -1631,10 +1637,6 @@ static int get_cluster_offset(BlockDriverState *bs,
}
if (m_data) {
m_data->new_allocation = true;
- m_data->l1_index = l1_index;
- m_data->l2_index = l2_index;
- m_data->l2_offset = l2_offset;
- m_data->l2_cache_entry = ((uint32_t *)l2_table) + l2_index;
}
}
*cluster_offset = cluster_sector << BDRV_SECTOR_BITS;
@@ -1990,7 +1992,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t
offset,
error_report("Could not write to allocated cluster"
" for streamOptimized");
return -EIO;
- } else {
+ } else if (!zeroed) {
/* allocate */
ret = get_cluster_offset(bs, extent, &m_data, offset,
true, &cluster_offset, 0, 0);
--
2.25.3
- [PATCH 0/6] vmdk: Fix zero cluster handling, Kevin Wolf, 2020/04/30
- [PATCH 1/6] vmdk: Rename VmdkMetaData.valid to new_allocation, Kevin Wolf, 2020/04/30
- [PATCH 2/6] vmdk: Fix zero cluster allocation,
Kevin Wolf <=
- [PATCH 3/6] vmdk: Fix partial overwrite of zero cluster, Kevin Wolf, 2020/04/30
- [PATCH 4/6] vmdk: Don't update L2 table for zero write on zero cluster, Kevin Wolf, 2020/04/30
- [PATCH 5/6] vmdk: Flush only once in vmdk_L2update(), Kevin Wolf, 2020/04/30
- [PATCH 6/6] iotests: vmdk: Enable zeroed_grained=on by default, Kevin Wolf, 2020/04/30