This differential proposed fspacectl(2) system calls, vn_deallocate(9) function
VOP_DEALLOCATE(9) call for hole-punching.
fspacectl(2) is a system call for performing space management operation
on a file. Hole-punching is currently supported. For hole-punching
operation, subsequent reads on such range return 0 in case the operation
succeeds.
The main purpose of proposing the system call and VOP is to allow bhyve
or other hypervisor monitors emulate the behavior of SCSI unmap on a
plain file.
SPACECTL_ALLOC backs the given range with space allocation such that
subsequent write operations in the given region will not fail due to
insufficient space. posix_fallocate(2) is implemented with SPACECTL_ALLOC.
For file system that can never make such guarantee, EINVAL would be
returned. Currently calling posix_fallocate(2) in ZFS returns EINVAL before
and after this revision.
SPACECTL_DEALLOC performs deallocation on the range aligned to
mapping granularity, and zero-fill the range not aligned to mapping
granularity, in case VOP_DEALLOCATE(9) is implemented by the
underlying file system.
A fallback implementation of VOP_DEALLOCATE(9) is provided to perform
zero-filling on non-hole region.
By default, fspacectl(2) does not extend file size in case the specified range
exceeds the current file size. If SPACECTL_F_CANEXTEND is specified, the
file size will be extended in such case.
fo_fspacectl is added to fileops. VOP_DEALLOCATE(9) is added as a new VOP
operation. vn_deallocate(9) is a vnode public KPI.
Submitted by: Ka Ho Ng
Sponsored by: The FreeBSD Foundation