This is the third version to support efficient zero for block
devices
on older kernels (e.g. RHEL 7.5), and file systems that do not support
yet FALLOC_FS_ZERO_RANGE (e.g. NFS 4.2).
Changes since v2:
- Revert file_can_trim change, since it is too late to change the value
after negotiation. Changing the capability dinamically may be useful
internally, but it should be done via other means.
- Do not depend on FALLOC_FL_* when including <linux/fs.h>.
- Add common/includes/isaligned.h for is_aligned helper, implemented
in a more efficient way with bitwise math.
- If getting sector size fail, fall back to safe guess instead of
hard failure.
- More efficient alignment check using bitwise math.
- For BLKZEROOUT, treat ENOTTY as EOPNOTSUPP. Theoretically possible
with a mix of new headers and old or strangely configured kernel.
- Use default multi line comment style.
- Fix few typos in comments and commit message
Issues to explore later:
- Eric suggested to use the new FALLOC_FL_NO_HIDE_STALE. Requires
benchmarking with a system supporting this flag.
- Eric suggested to use tri-state for can_* flags. I don't see a need at
this point.
- Eric suggested to add can_zero. I'm not sure about the semantics of
this, and it has the same issue of can_trim, reporting dynamic value.
v2 was here:
https://www.redhat.com/archives/libguestfs/2018-August/msg00025.html
Changes since v1:
- Split to smaller patches
- Skip linux only includes on other systems
- Skip code using BLKZEROOUT if the macro is not defined
- Try BLKZEROOUT only if the offset and count are aligned to device
sector size.
- initialize h->can_* properly. Before they were uninitialized if
FALLOC_FL_* macros were not defined.
- Use new h->can_punch_hole in file_can_trim, so now we report the
actual capability once we detected it.
- Use h->can_punch_hole in file_trim, so we try only once if the
operation is not supported.
v1 was here:
https://www.redhat.com/archives/libguestfs/2018-July/msg00084.html
Nir Soffer (4):
file: Avoid unsupported fallocate() calls
file: Support zero without ZERO_RANGE
common: Add isaligned helper module
file: Zero for block devices on old kernels
common/include/isaligned.h | 50 ++++++++++
plugins/file/Makefile.am | 3 +-
plugins/file/file.c | 182 +++++++++++++++++++++++++++++--------
3 files changed, 196 insertions(+), 39 deletions(-)
create mode 100644 common/include/isaligned.h
--
2.17.1