Eric Blake
2018-Aug-13 17:44 UTC
Re: [Libguestfs] [PATCH v2 1/4] file: Avoid unsupported fallocate() calls
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
Nir Soffer
2018-Aug-13 20:58 UTC
Re: [Libguestfs] [PATCH v2 1/4] file: Avoid unsupported fallocate() calls
On Mon, Aug 13, 2018 at 8:44 PM Eric Blake <eblake@redhat.com> wrote:> > #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. >I'll fix it in the next version. Nir
Nir Soffer
2018-Aug-18 20:09 UTC
Re: [Libguestfs] [PATCH v2 1/4] file: Avoid unsupported fallocate() calls
On Mon, Aug 13, 2018 at 11:58 PM Nir Soffer <nsoffer@redhat.com> wrote:> On Mon, Aug 13, 2018 at 8:44 PM Eric Blake <eblake@redhat.com> wrote: > >> > #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. >> >It does look off in my mail client (inbox), but looks fine (2 spaces indentation) in my editor. Nir
Seemingly Similar Threads
- Re: [PATCH v2 1/4] file: Avoid unsupported fallocate() calls
- Re: [PATCH v2 1/4] file: Avoid unsupported fallocate() calls
- Re: [PATCH v2 1/4] file: Avoid unsupported fallocate() calls
- [PATCH v2 1/4] file: Avoid unsupported fallocate() calls
- [PATCH v3 1/4] file: Avoid unsupported fallocate() calls