[Libguestfs] [PATCH v2 1/4] file: Avoid unsupported fallocate() calls

Eric Blake eblake at redhat.com
Mon Aug 13 17:44:07 UTC 2018


On 08/03/2018 02:28 PM, Nir Soffer wrote:
> When using file systems not supporting ZERO_RANGE (e.g. NFS 4.2) or
> block device on kernel < 4.9, we used to call fallocate() for every
> zero, fail with EOPNOTSUPP, and fallback to manual zeroing.  When
> trimming, we used to try unsupported fallocate() on every call.
> 
> Change file handle to remember if punching holes or zeroing range are
> supported, and avoid unsupported calls.
> 
> - zero changed to:
>    1. If we can punch hole and may trim, try PUNCH_HOLE
>    2. If we can zero range, try ZERO_RANGE
>    3. Fall back to manual writing
> 
> - trim changed to:
>    1. If we can punch hole, try PUNCH_HOLE
>    2. Succeed
> ---
>   plugins/file/file.c | 80 ++++++++++++++++++++++++++++++---------------
>   1 file changed, 53 insertions(+), 27 deletions(-)
> 

>   #ifdef FALLOC_FL_ZERO_RANGE
> -  r = do_fallocate (h->fd, FALLOC_FL_ZERO_RANGE, offset, count);
> -  if (r == -1 && errno != EOPNOTSUPP) {
> -    nbdkit_error ("zero: %m");
> +  if (h->can_zero_range) {
> +    r = do_fallocate (h->fd, FALLOC_FL_ZERO_RANGE, offset, count);
> +    if (r== 0)

Spacing is off.

Otherwise looks good to me.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




More information about the Libguestfs mailing list