NFSv4.2 supports server side copying of byte ranges within a file. To support this, a new system call and VOP_xxx()
is required. (For file systems that don't support VOP_COPY_FILE_RANGE(), it simply does the copy in a loop using
the input file's preferred I/O size. This saves system calls compared with a copy done in userland, but I have no
idea if there is a measurable performance difference.)
This patch implements the copy_file_range(2) syscall and VOP_COPY_FILE_RANGE() to do this.
It is intended to be compatible with the Linux syscall of the same name.
It was written from the Linux man page. There are a couple of oddities in the Linux syscall, such as no way to
specify "copy to EOF" and requires the syscall to fail with EINVAL if the file offset plus len exceeds the file size
of the file being copied from.
Since VOP_IOCTL() must be called with the vnode unlocked, the code simply looks for "holes" by scanning the
entire read block to see if it all 0s, instead of using VOP_IOCTL() to try and find the holes.
(I should probably note what the Linux man page mentions w.r.t. using lseek(SEEK_HOLE) and lseek(SEEK_DATA)
for copying sparse files.)
One thing I am not sure of is if it will work for stacked file systems.
I strongly suspect there will be several iterations of this patch, but this is a first draft.