Message ID | 20180508212405.15297-3-rgoldwyn@suse.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 05/08/2018 11:24 PM, Goldwyn Rodrigues wrote: > While performing copy_file_range(), if superblocks of file_in and > file_out don't match, instead of returning -EXDEV, perform > splice for a faster copy. We have a userspace emulation in glibc which used to be quite faithful, including the EXDEV error (which is not strictly necessary to produce). Should we change glibc to perform a userspace copy if the system call returns EXDEV due to an older kernel? Thanks, Florian
On Wed, May 9, 2018 at 12:24 AM, Goldwyn Rodrigues <rgoldwyn@suse.de> wrote: > From: Goldwyn Rodrigues <rgoldwyn@suse.com> > > While performing copy_file_range(), if superblocks of file_in and > file_out don't match, instead of returning -EXDEV, perform > splice for a faster copy. > > Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Reviewed-by: Amir Goldstein <amir73il@gmail.com> > --- > fs/read_write.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/fs/read_write.c b/fs/read_write.c > index 7d9dfb62ba7d..2c9e7a5ea806 100644 > --- a/fs/read_write.c > +++ b/fs/read_write.c > @@ -1546,6 +1546,8 @@ ssize_t do_copy_file_range(struct file *file_in, loff_t pos_in, > size_t len, unsigned int flags, > unsigned int splice_flags) > { > + struct inode *inode_in = file_inode(file_in); > + struct inode *inode_out = file_inode(file_out); > ssize_t ret = 0; > > if (flags != 0) > @@ -1554,6 +1556,9 @@ ssize_t do_copy_file_range(struct file *file_in, loff_t pos_in, > if (len == 0) > return 0; > > + if (inode_in->i_sb != inode_out->i_sb) > + goto splice; > + > /* > * Try cloning first, this is supported by more file systems, and > * more efficient if both clone and copy are supported (e.g. NFS). > @@ -1571,7 +1576,7 @@ ssize_t do_copy_file_range(struct file *file_in, loff_t pos_in, > if (ret != -EOPNOTSUPP) > return ret; > } > - > +splice: > ret = do_splice_direct(file_in, &pos_in, file_out, &pos_out, > len > MAX_RW_COUNT ? MAX_RW_COUNT : len, splice_flags); > return ret; > @@ -1608,10 +1613,6 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, > (file_out->f_flags & O_APPEND)) > return -EBADF; > > - /* this could be relaxed once a method supports cross-fs copies */ > - if (inode_in->i_sb != inode_out->i_sb) > - return -EXDEV; > - > file_start_write(file_out); > > ret = do_copy_file_range(file_in, pos_in, > -- > 2.16.3 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-unionfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html
On 05/08/2018 04:57 PM, Florian Weimer wrote: > On 05/08/2018 11:24 PM, Goldwyn Rodrigues wrote: >> While performing copy_file_range(), if superblocks of file_in and >> file_out don't match, instead of returning -EXDEV, perform >> splice for a faster copy. > > We have a userspace emulation in glibc which used to be quite faithful, > including the EXDEV error (which is not strictly necessary to produce). > > Should we change glibc to perform a userspace copy if the system call > returns EXDEV due to an older kernel? > I don't seen any purpose. The user would anyways have to perform a copy if it receives -EXDEV.
diff --git a/fs/read_write.c b/fs/read_write.c index 7d9dfb62ba7d..2c9e7a5ea806 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1546,6 +1546,8 @@ ssize_t do_copy_file_range(struct file *file_in, loff_t pos_in, size_t len, unsigned int flags, unsigned int splice_flags) { + struct inode *inode_in = file_inode(file_in); + struct inode *inode_out = file_inode(file_out); ssize_t ret = 0; if (flags != 0) @@ -1554,6 +1556,9 @@ ssize_t do_copy_file_range(struct file *file_in, loff_t pos_in, if (len == 0) return 0; + if (inode_in->i_sb != inode_out->i_sb) + goto splice; + /* * Try cloning first, this is supported by more file systems, and * more efficient if both clone and copy are supported (e.g. NFS). @@ -1571,7 +1576,7 @@ ssize_t do_copy_file_range(struct file *file_in, loff_t pos_in, if (ret != -EOPNOTSUPP) return ret; } - +splice: ret = do_splice_direct(file_in, &pos_in, file_out, &pos_out, len > MAX_RW_COUNT ? MAX_RW_COUNT : len, splice_flags); return ret; @@ -1608,10 +1613,6 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, (file_out->f_flags & O_APPEND)) return -EBADF; - /* this could be relaxed once a method supports cross-fs copies */ - if (inode_in->i_sb != inode_out->i_sb) - return -EXDEV; - file_start_write(file_out); ret = do_copy_file_range(file_in, pos_in,