Message ID | 44afe46517b379b6b998a35ba99dd2e1f55a2c7d.1731433903.git.josef@toxicpanda.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | fanotify: add pre-content hooks | expand |
On Tue, Nov 12, 2024 at 6:56 PM Josef Bacik <josef@toxicpanda.com> wrote: > > We want to emit events during page fault, and calling into fanotify > could be expensive, so add a helper to allow us to skip calling into > fanotify from page fault. This will also be used to disable readahead > for content watched files which will be handled in a subsequent patch. > > Signed-off-by: Josef Bacik <josef@toxicpanda.com> > --- > fs/notify/fsnotify.c | 12 ++++++++++++ > include/linux/fsnotify_backend.h | 26 ++++++++++++++++++++++++++ > 2 files changed, 38 insertions(+) > > diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c > index cab5a1a16e57..17047c44cf91 100644 > --- a/fs/notify/fsnotify.c > +++ b/fs/notify/fsnotify.c > @@ -203,6 +203,18 @@ static inline bool fsnotify_object_watched(struct inode *inode, __u32 mnt_mask, > return mask & marks_mask & ALL_FSNOTIFY_EVENTS; > } > > +#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS > +bool fsnotify_file_object_watched(struct file *file, __u32 mask) > +{ > + struct inode *inode = file_inode(file); > + __u32 mnt_mask = real_mount(file->f_path.mnt)->mnt_fsnotify_mask; > + > + return fsnotify_object_watched(inode, mnt_mask, mask); > +} > +EXPORT_SYMBOL_GPL(fsnotify_file_object_watched); > +#endif > + FYI, I was going to use this helper to set the FMODE_ flags, but I noticed that it is missing the check for parent watching pre content events. The other user of fsnotify_object_watched(), __fsnotify_parent() explicitly checks the fsnotify_inode_watches_children() mask. I will need to add this. Thanks, Amir.
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index cab5a1a16e57..17047c44cf91 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -203,6 +203,18 @@ static inline bool fsnotify_object_watched(struct inode *inode, __u32 mnt_mask, return mask & marks_mask & ALL_FSNOTIFY_EVENTS; } +#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +bool fsnotify_file_object_watched(struct file *file, __u32 mask) +{ + struct inode *inode = file_inode(file); + __u32 mnt_mask = real_mount(file->f_path.mnt)->mnt_fsnotify_mask; + + return fsnotify_object_watched(inode, mnt_mask, mask); +} +EXPORT_SYMBOL_GPL(fsnotify_file_object_watched); +#endif + + /* * Notify this dentry's parent about a child's events with child name info * if parent is watching or if inode/sb/mount are interested in events with diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index abd292edb48c..a92d59b66f93 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -896,6 +896,27 @@ static inline void fsnotify_init_event(struct fsnotify_event *event) INIT_LIST_HEAD(&event->list); } +#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS +bool fsnotify_file_object_watched(struct file *file, __u32 mask); + +static inline bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + if (!(file->f_mode & FMODE_NOTIFY_PERM)) + return false; + + if (!(file_inode(file)->i_sb->s_iflags & SB_I_ALLOW_HSM)) + return false; + + return fsnotify_file_object_watched(file, FSNOTIFY_PRE_CONTENT_EVENTS); +} + +#else +static inline bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + return false; +} +#endif /* CONFIG_FANOTIFY_ACCESS_PERMISSIONS */ + #else static inline int fsnotify(__u32 mask, const void *data, int data_type, @@ -934,6 +955,11 @@ static inline u32 fsnotify_get_cookie(void) static inline void fsnotify_unmount_inodes(struct super_block *sb) {} +static inline bool fsnotify_file_has_pre_content_watches(struct file *file) +{ + return false; +} + #endif /* CONFIG_FSNOTIFY */ #endif /* __KERNEL __ */
We want to emit events during page fault, and calling into fanotify could be expensive, so add a helper to allow us to skip calling into fanotify from page fault. This will also be used to disable readahead for content watched files which will be handled in a subsequent patch. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- fs/notify/fsnotify.c | 12 ++++++++++++ include/linux/fsnotify_backend.h | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)