vmdk: Fix next_cluster_sector for compressed write
PATCH 1/1 vmdk: Fix next_cluster_sector for compressed write
This fixes the bug introduced by commit c6ac36e (vmdk: Optimize cluster allocation).
Sometimes, write_len could be larger than cluster size, because it contains both data and marker. We must advance next_cluster_sector in this case, otherwise the image gets corrupted.
--- block/vmdk.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
block/vmdk.c +10 -4
@@ -1302,6 +1302,8 @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,uLongf buf_len;const uint8_t *write_buf = buf;int write_len = nb_sectors *512 ; +int64_t write_offset; +int64_t write_end_sector;if (extent->compressed) {if (!extent->has_marker) {
@@ -1320,10 +1322,14 @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset, write_buf = (uint8_t *)data; write_len = buf_len +sizeof (VmdkGrainMarker); } - ret =bdrv_pwrite (extent->file, - cluster_offset + offset_in_cluster, - write_buf, - write_len); + write_offset = cluster_offset + offset_in_cluster, + ret =bdrv_pwrite (extent->file, write_offset, write_buf, write_len); + + write_end_sector =DIV_ROUND_UP (write_offset + write_len,BDRV_SECTOR_SIZE ); + + extent->next_cluster_sector =MAX (extent->next_cluster_sector, + write_end_sector); +if (ret != write_len) { ret = ret <0 ? ret : -EIO ; goto out;
Signature · 1 line
1.9.3
Quoted 35 lines · Fam Zheng
This fixes the bug introduced by commit c6ac36e (vmdk: Optimize cluster allocation).
Sometimes,
write_lencould be larger than cluster size, because it contains both data and marker. We must advancenext_cluster_sectorin this case, otherwise the image gets corrupted.Reported-by Antoni Villalonga <[email protected]>Signed-off-by Fam Zheng <[email protected]>--- block/vmdk.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)block/vmdk.c +3
-4@@ -1302,6 +1302,8 @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,uLongf buf_len;const uint8_t *write_buf = buf;int write_len = nb_sectors *512 ; +int64_t write_offset; +int64_t write_end_sector;if (extent->compressed) {if (!extent->has_marker) {@@ -1320,10 +1322,14 @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset, write_buf = (uint8_t *)data; write_len = buf_len +sizeof (VmdkGrainMarker); } - ret =bdrv_pwrite (extent->file, - cluster_offset + offset_in_cluster, - write_buf, - write_len); + write_offset = cluster_offset + offset_in_cluster,
block/vmdk.c static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset, · line 1335
Quoted 10 lines
block/vmdk.c +7
-0+ ret =bdrv_pwrite (extent->file, write_offset, write_buf, write_len); + + write_end_sector =DIV_ROUND_UP (write_offset + write_len,BDRV_SECTOR_SIZE ); + + extent->next_cluster_sector =MAX (extent->next_cluster_sector, + write_end_sector); +if (ret != write_len) { ret = ret <0 ? ret : -EIO ; goto out;
Am 06.05.2015 um 20:01 hat Max Reitz geschrieben:
Quoted 12 lines · Fam Zheng
Quoted 9 lines
This fixes the bug introduced by commit c6ac36e (vmdk: Optimize cluster allocation).
Sometimes,
write_lencould be larger than cluster size, because it contains both data and marker. We must advancenext_cluster_sectorin this case, otherwise the image gets corrupted.Reported-by Antoni Villalonga <[email protected]>Signed-off-by Fam Zheng <[email protected]>Reviewed-by Max Reitz <[email protected]>
Thanks, added a "Cc: [email protected]" line to the commit message and applied to the block branch.
Kevin