Skip to content

Commit 4ca7635

Browse files
committed
fsnotify: add groups to fsnotify_inode_groups when registering inode watch
Currently all fsnotify groups are added immediately to the fsnotify_inode_groups list upon creation. This means, even groups with no watches (common for audit) will be on the global tracking list and will get checked for every event. This patch adds groups to the global list on when the first inode mark is added to the group. Signed-of-by: Eric Paris <eparis@redhat.com>
1 parent 36fddeb commit 4ca7635

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎fs/notify/fsnotify.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ extern __u32 fsnotify_inode_mask;
1616
/* destroy all events sitting in this groups notification queue */
1717
extern void fsnotify_flush_notify(struct fsnotify_group *group);
1818

19+
/* add a group to the inode group list */
20+
extern void fsnotify_add_inode_group(struct fsnotify_group *group);
1921
/* final kfree of a group */
2022
extern void fsnotify_final_destroy_group(struct fsnotify_group *group);
2123

‎fs/notify/group.c‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,15 @@ void fsnotify_recalc_group_mask(struct fsnotify_group *group)
7777
fsnotify_recalc_global_mask();
7878
}
7979

80-
static void fsnotify_add_group(struct fsnotify_group *group)
80+
void fsnotify_add_inode_group(struct fsnotify_group *group)
8181
{
82-
BUG_ON(!mutex_is_locked(&fsnotify_grp_mutex));
82+
mutex_lock(&fsnotify_grp_mutex);
8383

84+
if (!group->on_inode_group_list)
85+
list_add_tail_rcu(&group->inode_group_list, &fsnotify_inode_groups);
8486
group->on_inode_group_list = 1;
85-
list_add_tail_rcu(&group->inode_group_list, &fsnotify_inode_groups);
87+
88+
mutex_unlock(&fsnotify_grp_mutex);
8689
}
8790

8891
/*
@@ -188,22 +191,17 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
188191
*/
189192
atomic_set(&group->num_marks, 1);
190193

191-
192194
mutex_init(&group->notification_mutex);
193195
INIT_LIST_HEAD(&group->notification_list);
194196
init_waitqueue_head(&group->notification_waitq);
195197
group->max_events = UINT_MAX;
196198

199+
INIT_LIST_HEAD(&group->inode_group_list);
200+
197201
spin_lock_init(&group->mark_lock);
198202
INIT_LIST_HEAD(&group->mark_entries);
199203

200204
group->ops = ops;
201205

202-
mutex_lock(&fsnotify_grp_mutex);
203-
204-
fsnotify_add_group(group);
205-
206-
mutex_unlock(&fsnotify_grp_mutex);
207-
208206
return group;
209207
}

‎fs/notify/inode_mark.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ int fsnotify_add_mark(struct fsnotify_mark_entry *entry,
322322
if (unlikely(!inode))
323323
return -EINVAL;
324324

325+
/*
326+
* if this group isn't being testing for inode type events we need
327+
* to start testing
328+
*/
329+
if (unlikely(list_empty(&group->inode_group_list)))
330+
fsnotify_add_inode_group(group);
331+
325332
/*
326333
* LOCKING ORDER!!!!
327334
* entry->lock

0 commit comments

Comments
 (0)