qcow2: Implement v2 zero writes with discard if possible
commit61b3043965fe3552ee2684a97e7cc809ca7a71b3
authorKevin Wolf <kwolf@redhat.com>
Tue, 21 Jul 2020 13:55:19 +0000 (21 15:55 +0200)
committerKevin Wolf <kwolf@redhat.com>
Tue, 21 Jul 2020 14:28:57 +0000 (21 16:28 +0200)
tree496e9ee83a0312ebd88803a49761d14b83b18fa8
parentbae127d4dcf6158c5042e2eee9582430839a9967
qcow2: Implement v2 zero writes with discard if possible

qcow2 version 2 images don't support the zero flag for clusters, so for
write_zeroes requests, we return -ENOTSUP and get explicit zero buffer
writes. If the image doesn't have a backing file, we can do better: Just
discard the respective clusters.

This is relevant for 'qemu-img convert -O qcow2 -n', where qemu-img has
to assume that the existing target image may contain any data, so it has
to write zeroes. Without this patch, this results in a fully allocated
target image, even if the source image was empty.

Reported-by: Nir Soffer <nsoffer@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200721135520.72355-2-kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/qcow2-cluster.c