diff mbox series

[v2,02/11] file-posix: Handle zero block status hint better

Message ID 20250417184133.105746-15-eblake@redhat.com (mailing list archive)
State New
Headers show
Series Make blockdev-mirror dest sparse in more cases | expand

Commit Message

Eric Blake April 17, 2025, 6:39 p.m. UTC
Although the previous patch to change 'bool want_zero' into an enum
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 <eblake@redhat.com>
---
 block/file-posix.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Stefan Hajnoczi April 17, 2025, 8:58 p.m. UTC | #1
On Thu, Apr 17, 2025 at 01:39:07PM -0500, Eric Blake wrote:
> Although the previous patch to change 'bool want_zero' into an enum
> 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 <eblake@redhat.com>
> ---
>  block/file-posix.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
diff mbox series

Patch

diff --git a/block/file-posix.c b/block/file-posix.c
index 30129ec9b37..8f3e7a8304f 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -3217,7 +3217,8 @@  static int coroutine_fn raw_co_block_status(BlockDriverState *bs,
         return ret;
     }

-    if (mode != BDRV_BSTAT_PRECISE) {
+    if (mode == BDRV_BSTAT_ALLOCATED) {
+        /* There is no backing file - all bytes are allocated in this file.  */
         *pnum = bytes;
         *map = offset;
         *file = bs;