From f8d89f67817fa362a3b8ed0721775e353dac8f18 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 9 May 2025 15:40:19 -0500 Subject: [PATCH 02/14] file-posix, gluster: Handle zero block status hint better RH-Author: Eric Blake RH-MergeRequest: 363: blockdev-mirror: More efficient handling of sparse mirrors RH-Jira: RHEL-88435 RHEL-88437 RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Miroslav Rezanina RH-Commit: [2/14] c40cd3f8cda2ea1646d90fd174b5f0dbd3e1a50b (ebblake/centos-qemu-kvm) Although the previous patch to change 'bool want_zero' into a bitmask made no semantic change, it is now time to differentiate. When the caller specifically wants to know what parts of the file read as zero, we need to use lseek and actually reporting holes, rather than short-circuiting and advertising full allocation. This change will be utilized in later patches to let mirroring optimize for the case when the destination already reads as zeroes. Signed-off-by: Eric Blake Reviewed-by: Stefan Hajnoczi Message-ID: <20250509204341.3553601-17-eblake@redhat.com> (cherry picked from commit a6a0a7fb0e327d17594c971b4a39de14e025b415) Jira: https://issues.redhat.com/browse/RHEL-88435 Jira: https://issues.redhat.com/browse/RHEL-88437 Signed-off-by: Eric Blake --- block/file-posix.c | 3 ++- block/gluster.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 0c6569742f..dea7b09b6c 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3282,7 +3282,8 @@ static int coroutine_fn raw_co_block_status(BlockDriverState *bs, return ret; } - if (mode != BDRV_WANT_PRECISE) { + if (!(mode & BDRV_WANT_ZERO)) { + /* There is no backing file - all bytes are allocated in this file. */ *pnum = bytes; *map = offset; *file = bs; diff --git a/block/gluster.c b/block/gluster.c index 8197b0ecef..e702666cbc 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1482,7 +1482,7 @@ static int coroutine_fn qemu_gluster_co_block_status(BlockDriverState *bs, return ret; } - if (mode != BDRV_WANT_PRECISE) { + if (!(mode & BDRV_WANT_ZERO)) { *pnum = bytes; *map = offset; *file = bs; -- 2.39.3