Skip to content

Commit ceb11d0

Browse files
dhowellsaxboe
authored andcommitted
f2fs: Provide a splice-read wrapper
Provide a splice_read wrapper for f2fs. This does some checks and tracing before calling filemap_splice_read() and will update the iostats afterwards. 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: Jaegeuk Kim <[email protected]> cc: Chao Yu <[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 fa6c46e commit ceb11d0

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

fs/f2fs/file.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4367,22 +4367,23 @@ static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct iov_iter *to)
43674367
return ret;
43684368
}
43694369

4370-
static void f2fs_trace_rw_file_path(struct kiocb *iocb, size_t count, int rw)
4370+
static void f2fs_trace_rw_file_path(struct file *file, loff_t pos, size_t count,
4371+
int rw)
43714372
{
4372-
struct inode *inode = file_inode(iocb->ki_filp);
4373+
struct inode *inode = file_inode(file);
43734374
char *buf, *path;
43744375

43754376
buf = f2fs_getname(F2FS_I_SB(inode));
43764377
if (!buf)
43774378
return;
4378-
path = dentry_path_raw(file_dentry(iocb->ki_filp), buf, PATH_MAX);
4379+
path = dentry_path_raw(file_dentry(file), buf, PATH_MAX);
43794380
if (IS_ERR(path))
43804381
goto free_buf;
43814382
if (rw == WRITE)
4382-
trace_f2fs_datawrite_start(inode, iocb->ki_pos, count,
4383+
trace_f2fs_datawrite_start(inode, pos, count,
43834384
current->pid, path, current->comm);
43844385
else
4385-
trace_f2fs_dataread_start(inode, iocb->ki_pos, count,
4386+
trace_f2fs_dataread_start(inode, pos, count,
43864387
current->pid, path, current->comm);
43874388
free_buf:
43884389
f2fs_putname(buf);
@@ -4398,7 +4399,8 @@ static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
43984399
return -EOPNOTSUPP;
43994400

44004401
if (trace_f2fs_dataread_start_enabled())
4401-
f2fs_trace_rw_file_path(iocb, iov_iter_count(to), READ);
4402+
f2fs_trace_rw_file_path(iocb->ki_filp, iocb->ki_pos,
4403+
iov_iter_count(to), READ);
44024404

44034405
if (f2fs_should_use_dio(inode, iocb, to)) {
44044406
ret = f2fs_dio_read_iter(iocb, to);
@@ -4413,6 +4415,30 @@ static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
44134415
return ret;
44144416
}
44154417

4418+
static ssize_t f2fs_file_splice_read(struct file *in, loff_t *ppos,
4419+
struct pipe_inode_info *pipe,
4420+
size_t len, unsigned int flags)
4421+
{
4422+
struct inode *inode = file_inode(in);
4423+
const loff_t pos = *ppos;
4424+
ssize_t ret;
4425+
4426+
if (!f2fs_is_compress_backend_ready(inode))
4427+
return -EOPNOTSUPP;
4428+
4429+
if (trace_f2fs_dataread_start_enabled())
4430+
f2fs_trace_rw_file_path(in, pos, len, READ);
4431+
4432+
ret = filemap_splice_read(in, ppos, pipe, len, flags);
4433+
if (ret > 0)
4434+
f2fs_update_iostat(F2FS_I_SB(inode), inode,
4435+
APP_BUFFERED_READ_IO, ret);
4436+
4437+
if (trace_f2fs_dataread_end_enabled())
4438+
trace_f2fs_dataread_end(inode, pos, ret);
4439+
return ret;
4440+
}
4441+
44164442
static ssize_t f2fs_write_checks(struct kiocb *iocb, struct iov_iter *from)
44174443
{
44184444
struct file *file = iocb->ki_filp;
@@ -4714,7 +4740,8 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
47144740
ret = preallocated;
47154741
} else {
47164742
if (trace_f2fs_datawrite_start_enabled())
4717-
f2fs_trace_rw_file_path(iocb, orig_count, WRITE);
4743+
f2fs_trace_rw_file_path(iocb->ki_filp, iocb->ki_pos,
4744+
orig_count, WRITE);
47184745

47194746
/* Do the actual write. */
47204747
ret = dio ?
@@ -4919,7 +4946,7 @@ const struct file_operations f2fs_file_operations = {
49194946
#ifdef CONFIG_COMPAT
49204947
.compat_ioctl = f2fs_compat_ioctl,
49214948
#endif
4922-
.splice_read = generic_file_splice_read,
4949+
.splice_read = f2fs_file_splice_read,
49234950
.splice_write = iter_file_splice_write,
49244951
.fadvise = f2fs_file_fadvise,
49254952
};

0 commit comments

Comments
 (0)