[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 03/22] vmdk: Fix next_cluster_sector for compressed w
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 03/22] vmdk: Fix next_cluster_sector for compressed write |
Date: |
Fri, 22 May 2015 17:26:21 +0200 |
From: Fam Zheng <address@hidden>
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.
Cc: address@hidden
Reported-by: Antoni Villalonga <address@hidden>
Signed-off-by: Fam Zheng <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/vmdk.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index 1c5e2ef..4b4a862 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -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;
--
1.8.3.1
- [Qemu-block] [PULL 00/22] Block layer core and image format patches, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 03/22] vmdk: Fix next_cluster_sector for compressed write,
Kevin Wolf <=
- [Qemu-block] [PULL 02/22] nvme: support NVME_VOLATILE_WRITE_CACHE feature, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 04/22] vmdk: Fix overflow if l1_size is 0x20000000, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 01/22] qcow2: Flush pending discards before allocating cluster, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 05/22] qcow2: use one single memory block for the L2/refcount cache tables, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 06/22] qcow2: simplify qcow2_cache_put() and qcow2_cache_entry_mark_dirty(), Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 07/22] qcow2: use an LRU algorithm to replace entries from the L2 cache, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 09/22] qcow2: use a hash to look for entries in the L2 cache, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 08/22] qcow2: remove qcow2_cache_find_entry_to_replace(), Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 10/22] qcow2: make qcow2_cache_put() a void function, Kevin Wolf, 2015/05/22
- [Qemu-block] [PULL 11/22] qcow2: style fixes in qcow2-cache.c, Kevin Wolf, 2015/05/22