Skip to content

Commit 54919f9

Browse files
dhowellsaxboe
authored andcommitted
xfs: Provide a splice-read wrapper
Provide a splice_read wrapper for XFS. This does a stat count and a shutdown check before proceeding, then emits a new trace line and locks the inode across the call to filemap_splice_read() and adds to the stats afterwards. Splicing from direct I/O or DAX is handled by the caller. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> cc: Al Viro <viro@zeniv.linux.org.uk> cc: Jens Axboe <axboe@kernel.dk> cc: Darrick J. Wong <djwong@kernel.org> cc: linux-xfs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-block@vger.kernel.org cc: linux-mm@kvack.org Link: https://lore.kernel.org/r/20230522135018.2742245-25-dhowells@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 6bbf64b commit 54919f9

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

fs/xfs/xfs_file.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,34 @@ xfs_file_read_iter(
306306
return ret;
307307
}
308308

309+
STATIC ssize_t
310+
xfs_file_splice_read(
311+
struct file *in,
312+
loff_t *ppos,
313+
struct pipe_inode_info *pipe,
314+
size_t len,
315+
unsigned int flags)
316+
{
317+
struct inode *inode = file_inode(in);
318+
struct xfs_inode *ip = XFS_I(inode);
319+
struct xfs_mount *mp = ip->i_mount;
320+
ssize_t ret = 0;
321+
322+
XFS_STATS_INC(mp, xs_read_calls);
323+
324+
if (xfs_is_shutdown(mp))
325+
return -EIO;
326+
327+
trace_xfs_file_splice_read(ip, *ppos, len);
328+
329+
xfs_ilock(ip, XFS_IOLOCK_SHARED);
330+
ret = filemap_splice_read(in, ppos, pipe, len, flags);
331+
xfs_iunlock(ip, XFS_IOLOCK_SHARED);
332+
if (ret > 0)
333+
XFS_STATS_ADD(mp, xs_read_bytes, ret);
334+
return ret;
335+
}
336+
309337
/*
310338
* Common pre-write limit and setup checks.
311339
*
@@ -1423,7 +1451,7 @@ const struct file_operations xfs_file_operations = {
14231451
.llseek = xfs_file_llseek,
14241452
.read_iter = xfs_file_read_iter,
14251453
.write_iter = xfs_file_write_iter,
1426-
.splice_read = generic_file_splice_read,
1454+
.splice_read = xfs_file_splice_read,
14271455
.splice_write = iter_file_splice_write,
14281456
.iopoll = iocb_bio_iopoll,
14291457
.unlocked_ioctl = xfs_file_ioctl,

fs/xfs/xfs_trace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,6 @@ DEFINE_RW_EVENT(xfs_file_direct_write);
14451445
DEFINE_RW_EVENT(xfs_file_dax_write);
14461446
DEFINE_RW_EVENT(xfs_reflink_bounce_dio_write);
14471447

1448-
14491448
DECLARE_EVENT_CLASS(xfs_imap_class,
14501449
TP_PROTO(struct xfs_inode *ip, xfs_off_t offset, ssize_t count,
14511450
int whichfork, struct xfs_bmbt_irec *irec),
@@ -1535,6 +1534,7 @@ DEFINE_SIMPLE_IO_EVENT(xfs_zero_eof);
15351534
DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write);
15361535
DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write_unwritten);
15371536
DEFINE_SIMPLE_IO_EVENT(xfs_end_io_direct_write_append);
1537+
DEFINE_SIMPLE_IO_EVENT(xfs_file_splice_read);
15381538

15391539
DECLARE_EVENT_CLASS(xfs_itrunc_class,
15401540
TP_PROTO(struct xfs_inode *ip, xfs_fsize_t new_size),

0 commit comments

Comments
 (0)