diff options
| author | Eric Blake <eblake@redhat.com> | 2025-05-09 15:40:21 -0500 |
|---|---|---|
| committer | Eric Blake <eblake@redhat.com> | 2025-05-14 16:08:23 -0500 |
| commit | 52726096707c5c8b90597c445de897fa64d56e73 (patch) | |
| tree | 60a6f05a19b725daf4f838e10a511020db8a4c0c /include | |
| parent | 31bf15d97dd1d205a3b264675f9a1b3bd1939068 (diff) | |
| download | focaccia-qemu-52726096707c5c8b90597c445de897fa64d56e73.tar.gz focaccia-qemu-52726096707c5c8b90597c445de897fa64d56e73.zip | |
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>
Diffstat (limited to 'include')
| -rw-r--r-- | include/block/block-io.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/include/block/block-io.h b/include/block/block-io.h index b49e0537dd..b99cc98d26 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -161,6 +161,8 @@ bdrv_is_allocated_above(BlockDriverState *bs, BlockDriverState *base, int coroutine_fn GRAPH_RDLOCK bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset, int64_t bytes); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_is_all_zeroes(BlockDriverState *bs); int GRAPH_RDLOCK bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg, |