fs: try to clone files first in vfs_copy_file_range

A clone is a perfectly fine implementation of a file copy, so most
file systems just implement the copy that way.  Instead of duplicating
this logic move it to the VFS.  Currently btrfs and XFS implement copies
the same way as clones and there is no behavior change for them, cifs
only implements clones and grow support for copy_file_range with this
patch.  NFS implements both, so this will allow copy_file_range to work
on servers that only implement CLONE and be lot more efficient on servers
that implements CLONE and COPY.

Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Christoph Hellwig 2016-12-09 16:17:19 -08:00 committed by Darrick J. Wong
parent 3e5de27e94
commit a76b5b0437
5 changed files with 22 additions and 40 deletions

View file

@ -909,24 +909,6 @@ out_unlock:
return error;
}
STATIC ssize_t
xfs_file_copy_range(
struct file *file_in,
loff_t pos_in,
struct file *file_out,
loff_t pos_out,
size_t len,
unsigned int flags)
{
int error;
error = xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out,
len, false);
if (error)
return error;
return len;
}
STATIC int
xfs_file_clone_range(
struct file *file_in,
@ -1625,7 +1607,6 @@ const struct file_operations xfs_file_operations = {
.fsync = xfs_file_fsync,
.get_unmapped_area = thp_get_unmapped_area,
.fallocate = xfs_file_fallocate,
.copy_file_range = xfs_file_copy_range,
.clone_file_range = xfs_file_clone_range,
.dedupe_file_range = xfs_file_dedupe_range,
};