mirror of
https://github.com/torvalds/linux.git
synced 2024-12-26 12:52:30 +00:00
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:
parent
3e5de27e94
commit
a76b5b0437
@ -3232,9 +3232,6 @@ int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode,
|
||||
loff_t pos, size_t write_bytes,
|
||||
struct extent_state **cached);
|
||||
int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end);
|
||||
ssize_t btrfs_copy_file_range(struct file *file_in, loff_t pos_in,
|
||||
struct file *file_out, loff_t pos_out,
|
||||
size_t len, unsigned int flags);
|
||||
int btrfs_clone_file_range(struct file *file_in, loff_t pos_in,
|
||||
struct file *file_out, loff_t pos_out, u64 len);
|
||||
|
||||
|
@ -2998,7 +2998,6 @@ const struct file_operations btrfs_file_operations = {
|
||||
#ifdef CONFIG_COMPAT
|
||||
.compat_ioctl = btrfs_compat_ioctl,
|
||||
#endif
|
||||
.copy_file_range = btrfs_copy_file_range,
|
||||
.clone_file_range = btrfs_clone_file_range,
|
||||
.dedupe_file_range = btrfs_dedupe_file_range,
|
||||
};
|
||||
|
@ -3980,18 +3980,6 @@ out_unlock:
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t btrfs_copy_file_range(struct file *file_in, loff_t pos_in,
|
||||
struct file *file_out, loff_t pos_out,
|
||||
size_t len, unsigned int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
ret = btrfs_clone_files(file_out, file_in, pos_in, len, pos_out);
|
||||
if (ret == 0)
|
||||
ret = len;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int btrfs_clone_file_range(struct file *src_file, loff_t off,
|
||||
struct file *dst_file, loff_t destoff, u64 len)
|
||||
{
|
||||
|
@ -1542,20 +1542,37 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = -EOPNOTSUPP;
|
||||
if (file_out->f_op->copy_file_range)
|
||||
/*
|
||||
* Try cloning first, this is supported by more file systems, and
|
||||
* more efficient if both clone and copy are supported (e.g. NFS).
|
||||
*/
|
||||
if (file_in->f_op->clone_file_range) {
|
||||
ret = file_in->f_op->clone_file_range(file_in, pos_in,
|
||||
file_out, pos_out, len);
|
||||
if (ret == 0) {
|
||||
ret = len;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_out->f_op->copy_file_range) {
|
||||
ret = file_out->f_op->copy_file_range(file_in, pos_in, file_out,
|
||||
pos_out, len, flags);
|
||||
if (ret == -EOPNOTSUPP)
|
||||
if (ret != -EOPNOTSUPP)
|
||||
goto done;
|
||||
}
|
||||
|
||||
ret = do_splice_direct(file_in, &pos_in, file_out, &pos_out,
|
||||
len > MAX_RW_COUNT ? MAX_RW_COUNT : len, 0);
|
||||
|
||||
done:
|
||||
if (ret > 0) {
|
||||
fsnotify_access(file_in);
|
||||
add_rchar(current, ret);
|
||||
fsnotify_modify(file_out);
|
||||
add_wchar(current, ret);
|
||||
}
|
||||
|
||||
inc_syscr(current);
|
||||
inc_syscw(current);
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user