qcow2: Make preallocate_co() resize the image to the correct size
authorAlberto Garcia <berto@igalia.com>
Fri, 11 Sep 2020 14:09:41 +0000 (16:09 +0200)
committerMax Reitz <mreitz@redhat.com>
Tue, 15 Sep 2020 09:30:36 +0000 (11:30 +0200)
commit8e958260c5a562f3be08beef2055975c04836200
tree285ff3263c213a71f082f2907f6b36a815a104c5
parentc1dadda02ca62823d5ee21dc6435d593c3993d32
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>
block/qcow2.c
tests/qemu-iotests/125
tests/qemu-iotests/125.out