Skip to content

Commit 390df3b

Browse files
dhowellsaxboe
authored andcommitted
ecryptfs: Provide a splice-read wrapper
Provide a splice_read wrapper for ecryptfs to update the access time on the lower file after the operation. Splicing from a direct I/O fd will update the access time when ->read_iter() is called. Signed-off-by: David Howells <[email protected]> cc: Christoph Hellwig <[email protected]> cc: Al Viro <[email protected]> cc: Jens Axboe <[email protected]> cc: Tyler Hicks <[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 ccfdf7c commit 390df3b

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

fs/ecryptfs/file.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,31 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
4444
return rc;
4545
}
4646

47+
/*
48+
* ecryptfs_splice_read_update_atime
49+
*
50+
* generic_file_splice_read updates the atime of upper layer inode. But, it
51+
* doesn't give us a chance to update the atime of the lower layer inode. This
52+
* function is a wrapper to generic_file_read. It updates the atime of the
53+
* lower level inode if generic_file_read returns without any errors. This is
54+
* to be used only for file reads. The function to be used for directory reads
55+
* is ecryptfs_read.
56+
*/
57+
static ssize_t ecryptfs_splice_read_update_atime(struct file *in, loff_t *ppos,
58+
struct pipe_inode_info *pipe,
59+
size_t len, unsigned int flags)
60+
{
61+
ssize_t rc;
62+
const struct path *path;
63+
64+
rc = generic_file_splice_read(in, ppos, pipe, len, flags);
65+
if (rc >= 0) {
66+
path = ecryptfs_dentry_to_lower_path(in->f_path.dentry);
67+
touch_atime(path);
68+
}
69+
return rc;
70+
}
71+
4772
struct ecryptfs_getdents_callback {
4873
struct dir_context ctx;
4974
struct dir_context *caller;
@@ -414,5 +439,5 @@ const struct file_operations ecryptfs_main_fops = {
414439
.release = ecryptfs_release,
415440
.fsync = ecryptfs_fsync,
416441
.fasync = ecryptfs_fasync,
417-
.splice_read = generic_file_splice_read,
442+
.splice_read = ecryptfs_splice_read_update_atime,
418443
};

0 commit comments

Comments
 (0)