Skip to content

Commit a7db503

Browse files
dhowellsaxboe
authored andcommitted
nfs: Provide a splice-read wrapper
Provide a splice_read wrapper for NFS. This locks the inode around filemap_splice_read() and revalidates the mapping. Splicing from direct I/O is handled by the caller. Signed-off-by: David Howells <[email protected]> cc: Christoph Hellwig <[email protected]> cc: Al Viro <[email protected]> cc: Jens Axboe <[email protected]> cc: Trond Myklebust <[email protected]> cc: Anna Schumaker <[email protected]> cc: [email protected] cc: [email protected] cc: [email protected] cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent ceb11d0 commit a7db503

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

fs/nfs/file.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,27 @@ nfs_file_read(struct kiocb *iocb, struct iov_iter *to)
178178
}
179179
EXPORT_SYMBOL_GPL(nfs_file_read);
180180

181+
ssize_t
182+
nfs_file_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe,
183+
size_t len, unsigned int flags)
184+
{
185+
struct inode *inode = file_inode(in);
186+
ssize_t result;
187+
188+
dprintk("NFS: splice_read(%pD2, %zu@%llu)\n", in, len, *ppos);
189+
190+
nfs_start_io_read(inode);
191+
result = nfs_revalidate_mapping(inode, in->f_mapping);
192+
if (!result) {
193+
result = filemap_splice_read(in, ppos, pipe, len, flags);
194+
if (result > 0)
195+
nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, result);
196+
}
197+
nfs_end_io_read(inode);
198+
return result;
199+
}
200+
EXPORT_SYMBOL_GPL(nfs_file_splice_read);
201+
181202
int
182203
nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
183204
{
@@ -879,7 +900,7 @@ const struct file_operations nfs_file_operations = {
879900
.fsync = nfs_file_fsync,
880901
.lock = nfs_lock,
881902
.flock = nfs_flock,
882-
.splice_read = generic_file_splice_read,
903+
.splice_read = nfs_file_splice_read,
883904
.splice_write = iter_file_splice_write,
884905
.check_flags = nfs_check_flags,
885906
.setlease = simple_nosetlease,

fs/nfs/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ static inline __u32 nfs_access_xattr_mask(const struct nfs_server *server)
416416
int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
417417
loff_t nfs_file_llseek(struct file *, loff_t, int);
418418
ssize_t nfs_file_read(struct kiocb *, struct iov_iter *);
419+
ssize_t nfs_file_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe,
420+
size_t len, unsigned int flags);
419421
int nfs_file_mmap(struct file *, struct vm_area_struct *);
420422
ssize_t nfs_file_write(struct kiocb *, struct iov_iter *);
421423
int nfs_file_release(struct inode *, struct file *);

fs/nfs/nfs4file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ const struct file_operations nfs4_file_operations = {
454454
.fsync = nfs_file_fsync,
455455
.lock = nfs_lock,
456456
.flock = nfs_flock,
457-
.splice_read = generic_file_splice_read,
457+
.splice_read = nfs_file_splice_read,
458458
.splice_write = iter_file_splice_write,
459459
.check_flags = nfs_check_flags,
460460
.setlease = nfs4_setlease,

0 commit comments

Comments
 (0)