Commit 318652e07fa5b ("fsnotify: check if file is actually being watched for pre-content events on open") added an optimization that may be premature. Patially revert this change, leaving only the file type check, so that we can use the FMODE_FSNOTIFY_HSM() flag to check if there are any pre-content watches on the filesystem, which is needed in some cases. If we find that we need the extra optimization we can reconsider adding it later. Fixes: 318652e07fa5b ("fsnotify: check if file is actually being watched for pre-content events on open") Signed-off-by: Amir Goldstein <amir73il@xxxxxxxxx> --- fs/notify/fsnotify.c | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index fae1b6d397ea0..dafcaa6f8075f 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -650,9 +650,8 @@ EXPORT_SYMBOL_GPL(fsnotify); */ void file_set_fsnotify_mode_from_watchers(struct file *file) { - struct dentry *dentry = file->f_path.dentry, *parent; + struct dentry *dentry = file->f_path.dentry; struct super_block *sb = dentry->d_sb; - __u32 mnt_mask, p_mask; /* Is it a file opened by fanotify? */ if (FMODE_FSNOTIFY_NONE(file->f_mode)) @@ -681,30 +680,10 @@ void file_set_fsnotify_mode_from_watchers(struct file *file) } /* - * OK, there are some pre-content watchers. Check if anybody is - * watching for pre-content events on *this* file. + * OK, there are some pre-content watchers on this fs, so + * Enable pre-content events. */ - mnt_mask = READ_ONCE(real_mount(file->f_path.mnt)->mnt_fsnotify_mask); - if (unlikely(fsnotify_object_watched(d_inode(dentry), mnt_mask, - FSNOTIFY_PRE_CONTENT_EVENTS))) { - /* Enable pre-content events */ - file_set_fsnotify_mode(file, 0); - return; - } - - /* Is parent watching for pre-content events on this file? */ - if (dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED) { - parent = dget_parent(dentry); - p_mask = fsnotify_inode_watches_children(d_inode(parent)); - dput(parent); - if (p_mask & FSNOTIFY_PRE_CONTENT_EVENTS) { - /* Enable pre-content events */ - file_set_fsnotify_mode(file, 0); - return; - } - } - /* Nobody watching for pre-content events from this file */ - file_set_fsnotify_mode(file, FMODE_NONOTIFY | FMODE_NONOTIFY_PERM); + file_set_fsnotify_mode(file, 0); } #endif -- 2.34.1