Skip to content

Commit 1715f71

Browse files
committed
Merge tag 'fsnotify_for_v6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs
Pull fsnotify updates from Jan Kara: - fsnotify optimizations to reduce cost of fsnotify when nobody is watching - fix longstanding wart that system could not be suspended when some process was waiting for response to fanotify permission event - some spelling fixes * tag 'fsnotify_for_v6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: fanotify: allow freeze when waiting response for permission events fanotify: Fix misspelling of "writable" fsnotify: Fix misspelling of "writable" inotify: Fix misspelling of "writable" fsnotify: Add fsnotify_sb_has_watchers() helper fsnotify: optimize the case of no parent watcher
2 parents babbcc0 + 0045fb1 commit 1715f71

File tree

6 files changed

+36
-22
lines changed

6 files changed

+36
-22
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ static int fanotify_get_response(struct fsnotify_group *group,
228228

229229
pr_debug("%s: group=%p event=%p\n", __func__, group, event);
230230

231-
ret = wait_event_killable(group->fanotify_data.access_waitq,
232-
event->state == FAN_EVENT_ANSWERED);
231+
ret = wait_event_state(group->fanotify_data.access_waitq,
232+
event->state == FAN_EVENT_ANSWERED,
233+
(TASK_KILLABLE|TASK_FREEZABLE));
234+
233235
/* Signal pending? */
234236
if (ret < 0) {
235237
spin_lock(&group->notification_lock);

fs/notify/fsnotify.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode)
141141
}
142142

143143
/* Are inode/sb/mount interested in parent and name info with this event? */
144-
static bool fsnotify_event_needs_parent(struct inode *inode, struct mount *mnt,
144+
static bool fsnotify_event_needs_parent(struct inode *inode, __u32 mnt_mask,
145145
__u32 mask)
146146
{
147147
__u32 marks_mask = 0;
@@ -160,13 +160,22 @@ static bool fsnotify_event_needs_parent(struct inode *inode, struct mount *mnt,
160160
/* Did either inode/sb/mount subscribe for events with parent/name? */
161161
marks_mask |= fsnotify_parent_needed_mask(inode->i_fsnotify_mask);
162162
marks_mask |= fsnotify_parent_needed_mask(inode->i_sb->s_fsnotify_mask);
163-
if (mnt)
164-
marks_mask |= fsnotify_parent_needed_mask(mnt->mnt_fsnotify_mask);
163+
marks_mask |= fsnotify_parent_needed_mask(mnt_mask);
165164

166165
/* Did they subscribe for this event with parent/name info? */
167166
return mask & marks_mask;
168167
}
169168

169+
/* Are there any inode/mount/sb objects that are interested in this event? */
170+
static inline bool fsnotify_object_watched(struct inode *inode, __u32 mnt_mask,
171+
__u32 mask)
172+
{
173+
__u32 marks_mask = inode->i_fsnotify_mask | mnt_mask |
174+
inode->i_sb->s_fsnotify_mask;
175+
176+
return mask & marks_mask & ALL_FSNOTIFY_EVENTS;
177+
}
178+
170179
/*
171180
* Notify this dentry's parent about a child's events with child name info
172181
* if parent is watching or if inode/sb/mount are interested in events with
@@ -179,7 +188,7 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
179188
int data_type)
180189
{
181190
const struct path *path = fsnotify_data_path(data, data_type);
182-
struct mount *mnt = path ? real_mount(path->mnt) : NULL;
191+
__u32 mnt_mask = path ? real_mount(path->mnt)->mnt_fsnotify_mask : 0;
183192
struct inode *inode = d_inode(dentry);
184193
struct dentry *parent;
185194
bool parent_watched = dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED;
@@ -190,16 +199,13 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
190199
struct qstr *file_name = NULL;
191200
int ret = 0;
192201

193-
/*
194-
* Do inode/sb/mount care about parent and name info on non-dir?
195-
* Do they care about any event at all?
196-
*/
197-
if (!inode->i_fsnotify_marks && !inode->i_sb->s_fsnotify_marks &&
198-
(!mnt || !mnt->mnt_fsnotify_marks) && !parent_watched)
202+
/* Optimize the likely case of nobody watching this path */
203+
if (likely(!parent_watched &&
204+
!fsnotify_object_watched(inode, mnt_mask, mask)))
199205
return 0;
200206

201207
parent = NULL;
202-
parent_needed = fsnotify_event_needs_parent(inode, mnt, mask);
208+
parent_needed = fsnotify_event_needs_parent(inode, mnt_mask, mask);
203209
if (!parent_watched && !parent_needed)
204210
goto notify;
205211

include/linux/fsnotify.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
#include <linux/slab.h>
1818
#include <linux/bug.h>
1919

20+
/* Are there any inode/mount/sb objects that are being watched at all? */
21+
static inline bool fsnotify_sb_has_watchers(struct super_block *sb)
22+
{
23+
return atomic_long_read(&sb->s_fsnotify_connectors);
24+
}
25+
2026
/*
2127
* Notify this @dir inode about a change in a child directory entry.
2228
* The directory entry may have turned positive or negative or its inode may
@@ -30,7 +36,7 @@ static inline int fsnotify_name(__u32 mask, const void *data, int data_type,
3036
struct inode *dir, const struct qstr *name,
3137
u32 cookie)
3238
{
33-
if (atomic_long_read(&dir->i_sb->s_fsnotify_connectors) == 0)
39+
if (!fsnotify_sb_has_watchers(dir->i_sb))
3440
return 0;
3541

3642
return fsnotify(mask, data, data_type, dir, name, NULL, cookie);
@@ -44,7 +50,7 @@ static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry,
4450

4551
static inline void fsnotify_inode(struct inode *inode, __u32 mask)
4652
{
47-
if (atomic_long_read(&inode->i_sb->s_fsnotify_connectors) == 0)
53+
if (!fsnotify_sb_has_watchers(inode->i_sb))
4854
return;
4955

5056
if (S_ISDIR(inode->i_mode))
@@ -59,7 +65,7 @@ static inline int fsnotify_parent(struct dentry *dentry, __u32 mask,
5965
{
6066
struct inode *inode = d_inode(dentry);
6167

62-
if (atomic_long_read(&inode->i_sb->s_fsnotify_connectors) == 0)
68+
if (!fsnotify_sb_has_watchers(inode->i_sb))
6369
return 0;
6470

6571
if (S_ISDIR(inode->i_mode)) {

include/linux/fsnotify_backend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
#define FS_ACCESS 0x00000001 /* File was accessed */
3232
#define FS_MODIFY 0x00000002 /* File was modified */
3333
#define FS_ATTRIB 0x00000004 /* Metadata changed */
34-
#define FS_CLOSE_WRITE 0x00000008 /* Writtable file was closed */
35-
#define FS_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */
34+
#define FS_CLOSE_WRITE 0x00000008 /* Writable file was closed */
35+
#define FS_CLOSE_NOWRITE 0x00000010 /* Unwritable file closed */
3636
#define FS_OPEN 0x00000020 /* File was opened */
3737
#define FS_MOVED_FROM 0x00000040 /* File was moved from X */
3838
#define FS_MOVED_TO 0x00000080 /* File was moved to Y */

include/uapi/linux/fanotify.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#define FAN_ACCESS 0x00000001 /* File was accessed */
99
#define FAN_MODIFY 0x00000002 /* File was modified */
1010
#define FAN_ATTRIB 0x00000004 /* Metadata changed */
11-
#define FAN_CLOSE_WRITE 0x00000008 /* Writtable file closed */
12-
#define FAN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */
11+
#define FAN_CLOSE_WRITE 0x00000008 /* Writable file closed */
12+
#define FAN_CLOSE_NOWRITE 0x00000010 /* Unwritable file closed */
1313
#define FAN_OPEN 0x00000020 /* File was opened */
1414
#define FAN_MOVED_FROM 0x00000040 /* File was moved from X */
1515
#define FAN_MOVED_TO 0x00000080 /* File was moved to Y */

include/uapi/linux/inotify.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ struct inotify_event {
3030
#define IN_ACCESS 0x00000001 /* File was accessed */
3131
#define IN_MODIFY 0x00000002 /* File was modified */
3232
#define IN_ATTRIB 0x00000004 /* Metadata changed */
33-
#define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed */
34-
#define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */
33+
#define IN_CLOSE_WRITE 0x00000008 /* Writable file was closed */
34+
#define IN_CLOSE_NOWRITE 0x00000010 /* Unwritable file closed */
3535
#define IN_OPEN 0x00000020 /* File was opened */
3636
#define IN_MOVED_FROM 0x00000040 /* File was moved from X */
3737
#define IN_MOVED_TO 0x00000080 /* File was moved to Y */

0 commit comments

Comments
 (0)