Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fs: use splice_copy_file_range() inline helper

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>

authored by

Amir Goldstein and committed by
Christian Brauner
705bcfcb 0f292086

+22 -48
+2 -2
fs/ceph/file.c
··· 3090 3090 len, flags); 3091 3091 3092 3092 if (ret == -EOPNOTSUPP || ret == -EXDEV) 3093 - ret = generic_copy_file_range(src_file, src_off, dst_file, 3094 - dst_off, len, flags); 3093 + ret = splice_copy_file_range(src_file, src_off, dst_file, 3094 + dst_off, len); 3095 3095 return ret; 3096 3096 } 3097 3097
+3 -2
fs/fuse/file.c
··· 19 19 #include <linux/uio.h> 20 20 #include <linux/fs.h> 21 21 #include <linux/filelock.h> 22 + #include <linux/splice.h> 22 23 23 24 static int fuse_send_open(struct fuse_mount *fm, u64 nodeid, 24 25 unsigned int open_flags, int opcode, ··· 3194 3193 len, flags); 3195 3194 3196 3195 if (ret == -EOPNOTSUPP || ret == -EXDEV) 3197 - ret = generic_copy_file_range(src_file, src_off, dst_file, 3198 - dst_off, len, flags); 3196 + ret = splice_copy_file_range(src_file, src_off, dst_file, 3197 + dst_off, len); 3199 3198 return ret; 3200 3199 } 3201 3200
+3 -2
fs/nfs/nfs4file.c
··· 10 10 #include <linux/mount.h> 11 11 #include <linux/nfs_fs.h> 12 12 #include <linux/nfs_ssc.h> 13 + #include <linux/splice.h> 13 14 #include "delegation.h" 14 15 #include "internal.h" 15 16 #include "iostat.h" ··· 196 195 ret = __nfs4_copy_file_range(file_in, pos_in, file_out, pos_out, count, 197 196 flags); 198 197 if (ret == -EOPNOTSUPP || ret == -EXDEV) 199 - ret = generic_copy_file_range(file_in, pos_in, file_out, 200 - pos_out, count, flags); 198 + ret = splice_copy_file_range(file_in, pos_in, file_out, 199 + pos_out, count); 201 200 return ret; 202 201 } 203 202
-34
fs/read_write.c
··· 1396 1396 } 1397 1397 #endif 1398 1398 1399 - /** 1400 - * generic_copy_file_range - copy data between two files 1401 - * @file_in: file structure to read from 1402 - * @pos_in: file offset to read from 1403 - * @file_out: file structure to write data to 1404 - * @pos_out: file offset to write data to 1405 - * @len: amount of data to copy 1406 - * @flags: copy flags 1407 - * 1408 - * This is a generic filesystem helper to copy data from one file to another. 1409 - * It has no constraints on the source or destination file owners - the files 1410 - * can belong to different superblocks and different filesystem types. Short 1411 - * copies are allowed. 1412 - * 1413 - * This should be called from the @file_out filesystem, as per the 1414 - * ->copy_file_range() method. 1415 - * 1416 - * Returns the number of bytes copied or a negative error indicating the 1417 - * failure. 1418 - */ 1419 - 1420 - ssize_t generic_copy_file_range(struct file *file_in, loff_t pos_in, 1421 - struct file *file_out, loff_t pos_out, 1422 - size_t len, unsigned int flags) 1423 - { 1424 - /* May only be called from within ->copy_file_range() methods */ 1425 - if (WARN_ON_ONCE(flags)) 1426 - return -EINVAL; 1427 - 1428 - return splice_file_range(file_in, &pos_in, file_out, &pos_out, 1429 - min_t(size_t, len, MAX_RW_COUNT)); 1430 - } 1431 - EXPORT_SYMBOL(generic_copy_file_range); 1432 - 1433 1399 /* 1434 1400 * Performs necessary checks before doing a file copy 1435 1401 *
+3 -2
fs/smb/client/cifsfs.c
··· 25 25 #include <linux/freezer.h> 26 26 #include <linux/namei.h> 27 27 #include <linux/random.h> 28 + #include <linux/splice.h> 28 29 #include <linux/uuid.h> 29 30 #include <linux/xattr.h> 30 31 #include <uapi/linux/magic.h> ··· 1363 1362 free_xid(xid); 1364 1363 1365 1364 if (rc == -EOPNOTSUPP || rc == -EXDEV) 1366 - rc = generic_copy_file_range(src_file, off, dst_file, 1367 - destoff, len, flags); 1365 + rc = splice_copy_file_range(src_file, off, dst_file, 1366 + destoff, len); 1368 1367 return rc; 1369 1368 } 1370 1369
+4 -3
fs/splice.c
··· 1244 1244 * @len: number of bytes to splice 1245 1245 * 1246 1246 * Description: 1247 - * For use by generic_copy_file_range() and ->copy_file_range() methods. 1247 + * For use by ->copy_file_range() methods. 1248 1248 * Like do_splice_direct(), but vfs_copy_file_range() already holds 1249 1249 * start_file_write() on @out file. 1250 1250 * ··· 1255 1255 { 1256 1256 lockdep_assert(file_write_started(out)); 1257 1257 1258 - return do_splice_direct_actor(in, ppos, out, opos, len, 0, 1259 - splice_file_range_actor); 1258 + return do_splice_direct_actor(in, ppos, out, opos, 1259 + min_t(size_t, len, MAX_RW_COUNT), 1260 + 0, splice_file_range_actor); 1260 1261 } 1261 1262 EXPORT_SYMBOL(splice_file_range); 1262 1263
-3
include/linux/fs.h
··· 2090 2090 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *); 2091 2091 extern ssize_t vfs_copy_file_range(struct file *, loff_t , struct file *, 2092 2092 loff_t, size_t, unsigned int); 2093 - extern ssize_t generic_copy_file_range(struct file *file_in, loff_t pos_in, 2094 - struct file *file_out, loff_t pos_out, 2095 - size_t len, unsigned int flags); 2096 2093 int __generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, 2097 2094 struct file *file_out, loff_t pos_out, 2098 2095 loff_t *len, unsigned int remap_flags,
+7
include/linux/splice.h
··· 88 88 ssize_t splice_file_range(struct file *in, loff_t *ppos, struct file *out, 89 89 loff_t *opos, size_t len); 90 90 91 + static inline long splice_copy_file_range(struct file *in, loff_t pos_in, 92 + struct file *out, loff_t pos_out, 93 + size_t len) 94 + { 95 + return splice_file_range(in, &pos_in, out, &pos_out, len); 96 + } 97 + 91 98 ssize_t do_tee(struct file *in, struct file *out, size_t len, 92 99 unsigned int flags); 93 100 ssize_t splice_to_socket(struct pipe_inode_info *pipe, struct file *out,