On Fri, Apr 18, 2025 at 04:52:46PM -0500, Eric Blake wrote:
> This patch is purely mechanical, changing bool want_zero into an
> unsigned int for bitwise-or of flags.  As of this patch, all
> implementations are unchanged (the old want_zero==true is now
> mode==BDRV_WANT_PRECISE which is a superset of BDRV_WANT_ZERO); but
> the callers in io.c that used to pass want_zero==false are now
> prepared for future driver changes that can now distinguish bewteen
> BDRV_WANT_ZERO vs. BDRV_WANT_ALLOCATED.  The next patch will actually
> change the file-posix driver along those lines, now that we have
> more-specific hints.
> 
> As for the background why this patch is useful: right now, the
> file-posix driver recognizes that if allocation is being queried, the
> entire image can be reported as allocated (there is no backing file to
> refer to) - but this throws away information on whether the entire
> image reads as zero (trivially true if lseek(SEEK_HOLE) at offset 0
> returns -ENXIO, a bit more complicated to prove if the raw file was
> created with 'qemu-img create' since we intentionally allocate a small
> chunk of all-zero data to help with alignment probing).  Later patches
> will add a generic algorithm for seeing if an entire file reads as
> zeroes.
> 
> Signed-off-by: Eric Blake <ebl...@redhat.com>
> ---
> 
> In response to Stefan's ask for what it would look like as a bitmask
> of flags instead of an enum.  Only the first two patches of the series
> change.

> +++ b/block/io.c
> @@ -2364,10 +2364,8 @@ int bdrv_flush_all(void)
>   * Drivers not implementing the functionality are assumed to not support
>   * backing files, hence all their sectors are reported as allocated.
>   *
> - * If 'want_zero' is true, the caller is querying for mapping
> - * purposes, with a focus on valid BDRV_BLOCK_OFFSET_VALID, _DATA, and
> - * _ZERO where possible; otherwise, the result favors larger 'pnum',
> - * with a focus on accurate BDRV_BLOCK_ALLOCATED.
> + * 'mode' serves as a hint as to which results are favored; see enum
> + * BlockStatusMode for details of the supported modes.

Stale comment applicable to v2 but not v2.5; will fix for v3.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org


Reply via email to