]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs: use splice_copy_file_range() inline helper
authorAmir Goldstein <amir73il@gmail.com>
Tue, 12 Dec 2023 09:44:37 +0000 (11:44 +0200)
committerChristian Brauner <brauner@kernel.org>
Tue, 12 Dec 2023 15:20:02 +0000 (16:20 +0100)
generic_copy_file_range() is just a wrapper around splice_file_range(),
which caps the maximum copy length.

The only caller of splice_file_range(), namely __ceph_copy_file_range()
is already ready to cope with short copy.

Move the length capping into splice_file_range() and replace the exported
symbol generic_copy_file_range() with a simple inline helper.

Suggested-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/linux-fsdevel/20231204083849.GC32438@lst.de/
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Link: https://lore.kernel.org/r/20231212094440.250945-3-amir73il@gmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/ceph/file.c
fs/fuse/file.c
fs/nfs/nfs4file.c
fs/read_write.c
fs/smb/client/cifsfs.c
fs/splice.c
include/linux/fs.h
include/linux/splice.h

index f11de6e1f1c15d0bacc6009ba05c2eda6ba4a956..d380d9dad0e018426177110f17c51942b1c8a868 100644 (file)
@@ -3090,8 +3090,8 @@ static ssize_t ceph_copy_file_range(struct file *src_file, loff_t src_off,
                                     len, flags);
 
        if (ret == -EOPNOTSUPP || ret == -EXDEV)
-               ret = generic_copy_file_range(src_file, src_off, dst_file,
-                                             dst_off, len, flags);
+               ret = splice_copy_file_range(src_file, src_off, dst_file,
+                                            dst_off, len);
        return ret;
 }
 
index 1cdb6327511ef843db8936302fe7f141c4016186..7d0860ef63d06c2e30d2ebf8280bf5d2158acb91 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/uio.h>
 #include <linux/fs.h>
 #include <linux/filelock.h>
+#include <linux/splice.h>
 
 static int fuse_send_open(struct fuse_mount *fm, u64 nodeid,
                          unsigned int open_flags, int opcode,
@@ -3193,8 +3194,8 @@ static ssize_t fuse_copy_file_range(struct file *src_file, loff_t src_off,
                                     len, flags);
 
        if (ret == -EOPNOTSUPP || ret == -EXDEV)
-               ret = generic_copy_file_range(src_file, src_off, dst_file,
-                                             dst_off, len, flags);
+               ret = splice_copy_file_range(src_file, src_off, dst_file,
+                                            dst_off, len);
        return ret;
 }
 
index 02788c3c85e5bb5c26dcd405ae081b5bb1fda947..e238abc78a13e72672fe0e635e433ce92252a669 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/mount.h>
 #include <linux/nfs_fs.h>
 #include <linux/nfs_ssc.h>
+#include <linux/splice.h>
 #include "delegation.h"
 #include "internal.h"
 #include "iostat.h"
@@ -195,8 +196,8 @@ static ssize_t nfs4_copy_file_range(struct file *file_in, loff_t pos_in,
        ret = __nfs4_copy_file_range(file_in, pos_in, file_out, pos_out, count,
                                     flags);
        if (ret == -EOPNOTSUPP || ret == -EXDEV)
-               ret = generic_copy_file_range(file_in, pos_in, file_out,
-                                             pos_out, count, flags);
+               ret = splice_copy_file_range(file_in, pos_in, file_out,
+                                            pos_out, count);
        return ret;
 }
 
index 7783b8522693ca0eb010419ac3e4b15a479049db..e3abf603eaaf84df6939deff567d7c33cfff7b04 100644 (file)
@@ -1396,40 +1396,6 @@ COMPAT_SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd,
 }
 #endif
 
-/**
- * generic_copy_file_range - copy data between two files
- * @file_in:   file structure to read from
- * @pos_in:    file offset to read from
- * @file_out:  file structure to write data to
- * @pos_out:   file offset to write data to
- * @len:       amount of data to copy
- * @flags:     copy flags
- *
- * This is a generic filesystem helper to copy data from one file to another.
- * It has no constraints on the source or destination file owners - the files
- * can belong to different superblocks and different filesystem types. Short
- * copies are allowed.
- *
- * This should be called from the @file_out filesystem, as per the
- * ->copy_file_range() method.
- *
- * Returns the number of bytes copied or a negative error indicating the
- * failure.
- */
-
-ssize_t generic_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)
-{
-       /* May only be called from within ->copy_file_range() methods */
-       if (WARN_ON_ONCE(flags))
-               return -EINVAL;
-
-       return splice_file_range(file_in, &pos_in, file_out, &pos_out,
-                                min_t(size_t, len, MAX_RW_COUNT));
-}
-EXPORT_SYMBOL(generic_copy_file_range);
-
 /*
  * Performs necessary checks before doing a file copy
  *
index ea3a7a668b45f38ccfa6079449e666f2e6c9877b..ee461bf0ef63e8ae5b9dd23815ef855792728462 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/freezer.h>
 #include <linux/namei.h>
 #include <linux/random.h>
+#include <linux/splice.h>
 #include <linux/uuid.h>
 #include <linux/xattr.h>
 #include <uapi/linux/magic.h>
@@ -1362,8 +1363,8 @@ static ssize_t cifs_copy_file_range(struct file *src_file, loff_t off,
        free_xid(xid);
 
        if (rc == -EOPNOTSUPP || rc == -EXDEV)
-               rc = generic_copy_file_range(src_file, off, dst_file,
-                                            destoff, len, flags);
+               rc = splice_copy_file_range(src_file, off, dst_file,
+                                           destoff, len);
        return rc;
 }
 
index c39d1abf23c82367dda56c67d53bec624d8c13c9..218e24b1ac40173bbae9e3892e39ab15e076295c 100644 (file)
@@ -1244,7 +1244,7 @@ EXPORT_SYMBOL(do_splice_direct);
  * @len:       number of bytes to splice
  *
  * Description:
- *    For use by generic_copy_file_range() and ->copy_file_range() methods.
+ *    For use by ->copy_file_range() methods.
  *    Like do_splice_direct(), but vfs_copy_file_range() already holds
  *    start_file_write() on @out file.
  *
@@ -1255,8 +1255,9 @@ ssize_t splice_file_range(struct file *in, loff_t *ppos, struct file *out,
 {
        lockdep_assert(file_write_started(out));
 
-       return do_splice_direct_actor(in, ppos, out, opos, len, 0,
-                                     splice_file_range_actor);
+       return do_splice_direct_actor(in, ppos, out, opos,
+                                     min_t(size_t, len, MAX_RW_COUNT),
+                                     0, splice_file_range_actor);
 }
 EXPORT_SYMBOL(splice_file_range);
 
index 04422a0eccddd59f962a30b947ded81f685baddf..900d0cd55b50ff26c3de6706cec0f772659c09f4 100644 (file)
@@ -2090,9 +2090,6 @@ extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
 extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *,
                                   loff_t, size_t, unsigned int);
-extern ssize_t generic_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 __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
                                    struct file *file_out, loff_t pos_out,
                                    loff_t *len, unsigned int remap_flags,
index 068a8e8ffd7325188bd11c671abfc8acf6702b41..9dec4861d09f62d6c46664334357fef72a66c80b 100644 (file)
@@ -88,6 +88,13 @@ ssize_t do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
 ssize_t splice_file_range(struct file *in, loff_t *ppos, struct file *out,
                          loff_t *opos, size_t len);
 
+static inline long splice_copy_file_range(struct file *in, loff_t pos_in,
+                                         struct file *out, loff_t pos_out,
+                                         size_t len)
+{
+       return splice_file_range(in, &pos_in, out, &pos_out, len);
+}
+
 ssize_t do_tee(struct file *in, struct file *out, size_t len,
               unsigned int flags);
 ssize_t splice_to_socket(struct pipe_inode_info *pipe, struct file *out,