Skip to content

Commit 94aca68

Browse files
dhowellsaxboe
authored andcommitted
ocfs2: Provide a splice-read wrapper
Provide a splice_read wrapper for ocfs2. This emits trace lines and does an atime lock/update before calling filemap_splice_read(). Splicing from direct I/O is handled by the caller. A couple of new tracepoints are added for this purpose. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> cc: Christoph Hellwig <hch@lst.de> cc: Al Viro <viro@zeniv.linux.org.uk> cc: Jens Axboe <axboe@kernel.dk> cc: Mark Fasheh <mark@fasheh.com> cc: Joel Becker <jlbec@evilplan.org> cc: ocfs2-devel@oss.oracle.com 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-23-dhowells@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 5149439 commit 94aca68

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

fs/ocfs2/file.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,7 +2552,7 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb,
25522552
*
25532553
* Take and drop the meta data lock to update inode fields
25542554
* like i_size. This allows the checks down below
2555-
* generic_file_read_iter() a chance of actually working.
2555+
* copy_splice_read() a chance of actually working.
25562556
*/
25572557
ret = ocfs2_inode_lock_atime(inode, filp->f_path.mnt, &lock_level,
25582558
!nowait);
@@ -2581,6 +2581,43 @@ static ssize_t ocfs2_file_read_iter(struct kiocb *iocb,
25812581
return ret;
25822582
}
25832583

2584+
static ssize_t ocfs2_file_splice_read(struct file *in, loff_t *ppos,
2585+
struct pipe_inode_info *pipe,
2586+
size_t len, unsigned int flags)
2587+
{
2588+
struct inode *inode = file_inode(in);
2589+
ssize_t ret = 0;
2590+
int lock_level = 0;
2591+
2592+
trace_ocfs2_file_splice_read(inode, in, in->f_path.dentry,
2593+
(unsigned long long)OCFS2_I(inode)->ip_blkno,
2594+
in->f_path.dentry->d_name.len,
2595+
in->f_path.dentry->d_name.name,
2596+
flags);
2597+
2598+
/*
2599+
* We're fine letting folks race truncates and extending writes with
2600+
* read across the cluster, just like they can locally. Hence no
2601+
* rw_lock during read.
2602+
*
2603+
* Take and drop the meta data lock to update inode fields like i_size.
2604+
* This allows the checks down below filemap_splice_read() a chance of
2605+
* actually working.
2606+
*/
2607+
ret = ocfs2_inode_lock_atime(inode, in->f_path.mnt, &lock_level, 1);
2608+
if (ret < 0) {
2609+
if (ret != -EAGAIN)
2610+
mlog_errno(ret);
2611+
goto bail;
2612+
}
2613+
ocfs2_inode_unlock(inode, lock_level);
2614+
2615+
ret = filemap_splice_read(in, ppos, pipe, len, flags);
2616+
trace_filemap_splice_read_ret(ret);
2617+
bail:
2618+
return ret;
2619+
}
2620+
25842621
/* Refer generic_file_llseek_unlocked() */
25852622
static loff_t ocfs2_file_llseek(struct file *file, loff_t offset, int whence)
25862623
{
@@ -2744,7 +2781,7 @@ const struct file_operations ocfs2_fops = {
27442781
#endif
27452782
.lock = ocfs2_lock,
27462783
.flock = ocfs2_flock,
2747-
.splice_read = generic_file_splice_read,
2784+
.splice_read = ocfs2_file_splice_read,
27482785
.splice_write = iter_file_splice_write,
27492786
.fallocate = ocfs2_fallocate,
27502787
.remap_file_range = ocfs2_remap_file_range,

fs/ocfs2/ocfs2_trace.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,8 @@ DEFINE_OCFS2_FILE_OPS(ocfs2_file_splice_write);
13191319

13201320
DEFINE_OCFS2_FILE_OPS(ocfs2_file_read_iter);
13211321

1322+
DEFINE_OCFS2_FILE_OPS(ocfs2_file_splice_read);
1323+
13221324
DEFINE_OCFS2_ULL_ULL_ULL_EVENT(ocfs2_truncate_file);
13231325

13241326
DEFINE_OCFS2_ULL_ULL_EVENT(ocfs2_truncate_file_error);
@@ -1470,6 +1472,7 @@ TRACE_EVENT(ocfs2_prepare_inode_for_write,
14701472
);
14711473

14721474
DEFINE_OCFS2_INT_EVENT(generic_file_read_iter_ret);
1475+
DEFINE_OCFS2_INT_EVENT(filemap_splice_read_ret);
14731476

14741477
/* End of trace events for fs/ocfs2/file.c. */
14751478

0 commit comments

Comments
 (0)