提交 b4f51e42 编写于 作者: H Hou Tao 提交者: Zheng Zengkai

fs: add helper fs_file_read_do_trace()

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I53R0H
CVE: NA
backport: openEuler-22.03-LTS

---------------------------

fs_file_read_do_trace() uses writable-tracepoint to update f_mode
for file read procedure. Also export it to make it being usable
for filesystem kernel module.
Signed-off-by: NHou Tao <houtao1@huawei.com>
Acked-by: Nfang wei <fangwei1@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NZhihao Cheng <chengzhihao1@huawei.com>
Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 fdd92676
...@@ -1682,5 +1682,38 @@ int generic_file_rw_checks(struct file *file_in, struct file *file_out) ...@@ -1682,5 +1682,38 @@ int generic_file_rw_checks(struct file *file_in, struct file *file_out)
return 0; return 0;
} }
#ifdef CONFIG_TRACEPOINTS
static void fs_file_read_ctx_init(struct fs_file_read_ctx *ctx,
struct file *filp, loff_t pos)
{
memset(ctx, 0, sizeof(*ctx));
ctx->name = file_dentry(filp)->d_name.name;
ctx->f_ctl_mode = filp->f_ctl_mode;
ctx->key = (unsigned long)filp;
ctx->i_size = file_inode(filp)->i_size;
ctx->prev_index = filp->f_ra.prev_pos >> PAGE_SHIFT;
ctx->index = pos >> PAGE_SHIFT;
}
#define FS_FILE_READ_VERSION 1
#define FS_FILE_READ_MODE_MASK (FMODE_CTL_RANDOM | FMODE_CTL_WILLNEED)
void fs_file_read_update_args_by_trace(struct kiocb *iocb)
{
struct file *filp = iocb->ki_filp;
struct fs_file_read_ctx ctx;
fs_file_read_ctx_init(&ctx, filp, iocb->ki_pos);
trace_fs_file_read(&ctx, FS_FILE_READ_VERSION);
if (!ctx.set_f_ctl_mode && !ctx.clr_f_ctl_mode)
return;
filp->f_ctl_mode |= ctx.set_f_ctl_mode & FS_FILE_READ_MODE_MASK;
filp->f_ctl_mode &= ~(ctx.clr_f_ctl_mode & FS_FILE_READ_MODE_MASK);
}
EXPORT_SYMBOL_GPL(fs_file_read_update_args_by_trace);
#endif
EXPORT_TRACEPOINT_SYMBOL_GPL(fs_file_read); EXPORT_TRACEPOINT_SYMBOL_GPL(fs_file_read);
EXPORT_TRACEPOINT_SYMBOL_GPL(fs_file_release); EXPORT_TRACEPOINT_SYMBOL_GPL(fs_file_release);
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <linux/build_bug.h> #include <linux/build_bug.h>
#include <linux/stddef.h> #include <linux/stddef.h>
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/tracepoint-defs.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <uapi/linux/fs.h> #include <uapi/linux/fs.h>
...@@ -3579,4 +3580,16 @@ struct fs_file_read_ctx { ...@@ -3579,4 +3580,16 @@ struct fs_file_read_ctx {
long long index; long long index;
}; };
#ifdef CONFIG_TRACEPOINTS
DECLARE_TRACEPOINT(fs_file_read);
extern void fs_file_read_update_args_by_trace(struct kiocb *iocb);
#else
static inline void fs_file_read_update_args_by_trace(struct kiocb *iocb) {}
#endif
static inline void fs_file_read_do_trace(struct kiocb *iocb)
{
if (tracepoint_enabled(fs_file_read))
fs_file_read_update_args_by_trace(iocb);
}
#endif /* _LINUX_FS_H */ #endif /* _LINUX_FS_H */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册