]> git.ipfire.org Git - thirdparty/qemu.git/commit
block: Add new bdrv_co_is_all_zeroes() function
authorEric Blake <eblake@redhat.com>
Fri, 9 May 2025 20:40:21 +0000 (15:40 -0500)
committerEric Blake <eblake@redhat.com>
Wed, 14 May 2025 21:08:23 +0000 (16:08 -0500)
commit52726096707c5c8b90597c445de897fa64d56e73
tree60a6f05a19b725daf4f838e10a511020db8a4c0c
parent31bf15d97dd1d205a3b264675f9a1b3bd1939068
block: Add new bdrv_co_is_all_zeroes() function

There are some optimizations that require knowing if an image starts
out as reading all zeroes, such as making blockdev-mirror faster by
skipping the copying of source zeroes to the destination.  The
existing bdrv_co_is_zero_fast() is a good building block for answering
this question, but it tends to give an answer of 0 for a file we just
created via QMP 'blockdev-create' or similar (such as 'qemu-img create
-f raw').  Why?  Because file-posix.c insists on allocating a tiny
header to any file rather than leaving it 100% sparse, due to some
filesystems that are unable to answer alignment probes on a hole.  But
teaching file-posix.c to read the tiny header doesn't scale - the
problem of a small header is also visible when libvirt sets up an NBD
client to a just-created file on a migration destination host.

So, we need a wrapper function that handles a bit more complexity in a
common manner for all block devices - when the BDS is mostly a hole,
but has a small non-hole header, it is still worth the time to read
that header and check if it reads as all zeroes before giving up and
returning a pessimistic answer.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-ID: <20250509204341.3553601-19-eblake@redhat.com>
block/io.c
include/block/block-io.h