aboutsummaryrefslogtreecommitdiff
path: root/block/qcow2.c
diff options
context:
space:
mode:
authorAlberto Garcia <berto@igalia.com>2020-09-11 16:09:41 +0200
committerMax Reitz <mreitz@redhat.com>2020-09-15 11:30:36 +0200
commit8e958260c5a562f3be08beef2055975c04836200 (patch)
tree285ff3263c213a71f082f2907f6b36a815a104c5 /block/qcow2.c
parentc1dadda02ca62823d5ee21dc6435d593c3993d32 (diff)
qcow2: Make preallocate_co() resize the image to the correct size
This function preallocates metadata structures and then extends the image to its new size, but that new size calculation is wrong because it doesn't take into account that the host_offset variable is always cluster-aligned. This problem can be reproduced with preallocation=metadata when the original size is not cluster-aligned but the new size is. In this case the final image size will be shorter than expected. qemu-img create -f qcow2 img.qcow2 31k qemu-img resize --preallocation=metadata img.qcow2 128k Signed-off-by: Alberto Garcia <berto@igalia.com> Message-Id: <adeb8b059917b141d5f5b3bd2a016262d3052c79.1599833007.git.berto@igalia.com> Reviewed-by: Max Reitz <mreitz@redhat.com> [mreitz: Mark compat=0.10 unsupported for iotest 125] Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block/qcow2.c')
-rw-r--r--block/qcow2.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/block/qcow2.c b/block/qcow2.c
index 77c43ce178..1cb5daf39a 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3135,6 +3135,7 @@ static int coroutine_fn preallocate_co(BlockDriverState *bs, uint64_t offset,
error_setg_errno(errp, -ret, "Allocating clusters failed");
goto out;
}
+ host_offset += offset_into_cluster(s, offset);
for (m = meta; m != NULL; m = m->next) {
m->prealloc = true;