fsnotify: fsnotify_obtain_group kzalloc cleanup
Subsystems (5)
Eric Paris
maintainerPATCH 1/5 fsnotify: fsnotify_obtain_group kzalloc cleanup
fsnotify_obtain_group uses kzalloc but then proceedes to set things to 0. This patch just deletes those useless lines.
---
fs/notify/group.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
fs/notify/group.c +0 -3
@@ -178,17 +178,14 @@ struct fsnotify_group *fsnotify_obtain_group(__u32 mask,atomic_set (&group->refcnt,1 ); - group->on_group_list =0 ; group->mask = mask;mutex_init (&group->notification_mutex);INIT_LIST_HEAD (&group->notification_list);init_waitqueue_head (&group->notification_waitq); - group->q_len =0 ; group->max_events =UINT_MAX ;spin_lock_init (&group->mark_lock); -atomic_set (&group->num_marks,0 );INIT_LIST_HEAD (&group->mark_entries); group->ops = ops;
Eric Paris
maintainerPATCH 2/5 fsnotify: fsnotify_obtain_group should be fsnotify_alloc_group
fsnotify_obtain_group was intended to be able to find an already existing group. Nothing uses that functionality. This just renames it to fsnotify_alloc_group so it is clear what it is doing.
---
fs/notify/dnotify/dnotify.c | 2 +- fs/notify/group.c | 10 +++------- fs/notify/inotify/inotify_user.c | 2 +- include/linux/fsnotify_backend.h | 4 ++-- kernel/audit_tree.c | 2 +- kernel/audit_watch.c | 4 ++-- 6 files changed, 10 insertions(+), 14 deletions(-)
fs/notify/dnotify/dnotify.c +1 -1
@@ -432,7 +432,7 @@ static int __init dnotify_init(void) dnotify_struct_cache =KMEM_CACHE (dnotify_struct,SLAB_PANIC ); dnotify_mark_entry_cache =KMEM_CACHE (dnotify_mark_entry,SLAB_PANIC ); - dnotify_group =fsnotify_obtain_group (0 , &dnotify_fsnotify_ops); + dnotify_group =fsnotify_alloc_group (0 , &dnotify_fsnotify_ops);if (IS_ERR (dnotify_group))panic ("unable to allocate fsnotify group for dnotify\n" );return 0 ;
fs/notify/group.c +3 -7
@@ -162,16 +162,13 @@ void fsnotify_put_group(struct fsnotify_group *group) }/* -* Either finds an existing group which matches the group_num, mask, and ops or -* creates a new group and adds it to the global group list. In either case we -* take a reference for the group returned. +* Create a new fsnotify_group and hold a reference for the group returned. */ -struct fsnotify_group *fsnotify_obtain_group (__u32 mask, -const struct fsnotify_ops *ops) +struct fsnotify_group *fsnotify_alloc_group (__u32 mask, +const struct fsnotify_ops *ops) {struct fsnotify_group *group; -/* very low use, simpler locking if we just always alloc */ group =kzalloc (sizeof (struct fsnotify_group ),GFP_KERNEL );if (!group)return ERR_PTR (-ENOMEM );
@@ -192,7 +189,6 @@ struct fsnotify_group *fsnotify_obtain_group(__u32 mask,mutex_lock (&fsnotify_grp_mutex); -/* group not found, add a new one */ list_add_rcu (&group->group_list, &fsnotify_groups); group->on_group_list =1 ;/* being on the fsnotify_groups list holds one num_marks */
fs/notify/inotify/inotify_user.c +1 -1
@@ -709,7 +709,7 @@ static struct fsnotify_group *inotify_new_group(struct user_struct *user, unsign {struct fsnotify_group *group; - group =fsnotify_obtain_group (0 , &inotify_fsnotify_ops); + group =fsnotify_alloc_group (0 , &inotify_fsnotify_ops);if (IS_ERR (group))return group;
include/linux/fsnotify_backend.h +2 -2
@@ -305,11 +305,11 @@ static inline void __fsnotify_d_instantiate(struct dentry *dentry, struct inode/* must call when a group changes its ->mask */ extern void fsnotify_recalc_global_mask (void );/* get a reference to an existing or create a new group */ -extern struct fsnotify_group *fsnotify_obtain_group (__u32 mask, +extern struct fsnotify_group *fsnotify_alloc_group (__u32 mask,const struct fsnotify_ops *ops);/* run all marks associated with this group and update group->mask */ extern void fsnotify_recalc_group_mask (struct fsnotify_group *group); -/* drop reference on a group from fsnotify_obtain_group */ +/* drop reference on a group from fsnotify_alloc_group */ extern void fsnotify_put_group (struct fsnotify_group *group);/* take a reference to an event */
kernel/audit_tree.c +1 -1
@@ -976,7 +976,7 @@ static int __init audit_tree_init(void) {int i; - audit_tree_group =fsnotify_obtain_group (0 , &audit_tree_ops); + audit_tree_group =fsnotify_alloc_group (0 , &audit_tree_ops);if (IS_ERR (audit_tree_group))audit_panic ("cannot initialize inotify handle for rectree watches" );
kernel/audit_watch.c +2 -2
@@ -576,8 +576,8 @@ static const struct fsnotify_ops audit_watch_fsnotify_ops = {static int __init audit_watch_init (void ) { - audit_watch_group =fsnotify_obtain_group (AUDIT_FS_WATCH , - &audit_watch_fsnotify_ops); + audit_watch_group =fsnotify_alloc_group (AUDIT_FS_WATCH , + &audit_watch_fsnotify_ops);if (IS_ERR (audit_watch_group)) { audit_watch_group =NULL ;audit_panic ("cannot create audit fsnotify group" );
Eric Paris
maintainerPATCH 3/5 fsnotify: rename fsnotify_groups to fsnotify_inode_groups
In reply to Eric ParisSimple renaming patch. fsnotify is about to support mount point listeners so I am renaming fsnotify_groups and fsnotify_mask to indicate these are lists used only for groups which have watches on inodes.
---
fs/notify/fsnotify.c | 6 +++--- fs/notify/fsnotify.h | 8 ++++---- fs/notify/group.c | 30 +++++++++++++++++++----------- include/linux/fsnotify_backend.h | 6 +++--- 4 files changed, 29 insertions(+), 21 deletions(-)
fs/notify/fsnotify.c +3 -3
@@ -147,10 +147,10 @@ void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, const/* global tests shouldn't care about events on child only the specific event */ __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD ); -if (list_empty (&fsnotify_groups)) +if (list_empty (&fsnotify_inode_groups))return ; -if (!(test_mask & fsnotify_mask)) +if (!(test_mask & fsnotify_inode_mask))return ;if (!(test_mask & to_tell->i_fsnotify_mask))
@@ -161,7 +161,7 @@ void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, const* anything other than walk the list so it's crazy to pre-allocate. */ idx =srcu_read_lock (&fsnotify_grp_srcu); -list_for_each_entry_rcu (group, &fsnotify_groups, group_list) { +list_for_each_entry_rcu (group, &fsnotify_inode_groups, inode_group_list) {if (test_mask & group->mask) {if (!group->ops->should_send_event (group, to_tell, mask, data, data_is))
fs/notify/fsnotify.h +4 -4
@@ -8,10 +8,10 @@/* protects reads of fsnotify_groups */ extern struct srcu_struct fsnotify_grp_srcu; -/* all groups which receive fsnotify events */ -extern struct list_head fsnotify_groups; -/* all bitwise OR of all event types (FS_*) for all fsnotify_groups */ -extern __u32 fsnotify_mask; +/* all groups which receive inode fsnotify events */ +extern struct list_head fsnotify_inode_groups; +/* all bitwise OR of all event types (FS_*) for all fsnotify_inode_groups */ +extern __u32 fsnotify_inode_mask;/* destroy all events sitting in this groups notification queue */ extern void fsnotify_flush_notify (struct fsnotify_group *group);
fs/notify/group.c +19 -11
@@ -33,9 +33,9 @@ static DEFINE_MUTEX(fsnotify_grp_mutex);/* protects reads while running the fsnotify_groups list */ struct srcu_struct fsnotify_grp_srcu;/* all groups registered to receive filesystem notifications */ -LIST_HEAD (fsnotify_groups); +LIST_HEAD (fsnotify_inode_groups);/* bitwise OR of all events (FS_*) interesting to some group on this system */ -__u32 fsnotify_mask; +__u32 fsnotify_inode_mask;/* * When a new group registers or changes it's set of interesting events
@@ -48,10 +48,10 @@ void fsnotify_recalc_global_mask(void)int idx; idx =srcu_read_lock (&fsnotify_grp_srcu); -list_for_each_entry_rcu (group, &fsnotify_groups, group_list) +list_for_each_entry_rcu (group, &fsnotify_inode_groups, inode_group_list) mask |= group->mask;srcu_read_unlock (&fsnotify_grp_srcu, idx); - fsnotify_mask = mask; + fsnotify_inode_mask = mask; }/*
@@ -77,6 +77,17 @@ void fsnotify_recalc_group_mask(struct fsnotify_group *group)fsnotify_recalc_global_mask (); } +static void fsnotify_add_group (struct fsnotify_group *group) +{ +BUG_ON (!mutex_is_locked (&fsnotify_grp_mutex)); + + group->on_inode_group_list =1 ; +/* being on the fsnotify_groups list holds one num_marks */ +atomic_inc (&group->num_marks); + +list_add_tail_rcu (&group->inode_group_list, &fsnotify_inode_groups); +} +/* * Final freeing of a group */
@@ -118,9 +129,9 @@ static void __fsnotify_evict_group(struct fsnotify_group *group) {BUG_ON (!mutex_is_locked (&fsnotify_grp_mutex)); -if (group->on_group_list) -list_del_rcu (&group->group_list); - group->on_group_list =0 ; +if (group->on_inode_group_list) +list_del_rcu (&group->inode_group_list); + group->on_inode_group_list =0 ; }/*
@@ -189,10 +200,7 @@ struct fsnotify_group *fsnotify_alloc_group(__u32 mask,mutex_lock (&fsnotify_grp_mutex); -list_add_rcu (&group->group_list, &fsnotify_groups); - group->on_group_list =1 ; -/* being on the fsnotify_groups list holds one num_marks */ -atomic_inc (&group->num_marks); +fsnotify_add_group (group);mutex_unlock (&fsnotify_grp_mutex);
include/linux/fsnotify_backend.h +3 -3
@@ -95,10 +95,10 @@ struct fsnotify_ops {struct fsnotify_group {/* * global list of all groups receiving events from fsnotify. -* anchored by fsnotify_groups and protected by either fsnotify_grp_mutex +* anchored by fsnotify_inode_groups and protected by either fsnotify_grp_mutex * or fsnotify_grp_srcu depending on write vs read. */ -struct list_head group_list; +struct list_head inode_group_list;/* * Defines all of the event types in which this group is interested.
@@ -136,7 +136,7 @@ struct fsnotify_group {struct list_head mark_entries;/* all inode mark entries for this group */ /* prevents double list_del of group_list. protected by global fsnotify_grp_mutex */ -bool on_group_list; +bool on_inode_group_list;/* groups can define private fields here or use the void *private */ union {
Eric Paris
maintainerPATCH 4/5 fsnotify: initialize the group->num_marks in a better place
In reply to Eric ParisCurrently the comments say that group->num_marks is held because the group is on the fsnotify_group list. This isn't strictly the case, we really just hold the num_marks for the life of the group (any time group->refcnt is != 0) This patch moves the initialization stuff and makes it clear when it is really being held.
---
fs/notify/group.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-)
fs/notify/group.c +7 -3
@@ -82,9 +82,6 @@ static void fsnotify_add_group(struct fsnotify_group *group)BUG_ON (!mutex_is_locked (&fsnotify_grp_mutex)); group->on_inode_group_list =1 ; -/* being on the fsnotify_groups list holds one num_marks */ -atomic_inc (&group->num_marks); -list_add_tail_rcu (&group->inode_group_list, &fsnotify_inode_groups); }
@@ -184,7 +181,14 @@ struct fsnotify_group *fsnotify_alloc_group(__u32 mask,if (!group)return ERR_PTR (-ENOMEM ); +/* set to 0 when there a no external references to this group */ atomic_set (&group->refcnt,1 ); +/* +* hits 0 when there are no external references AND no marks for +* this group +*/ +atomic_set (&group->num_marks,1 ); + group->mask = mask;
Eric Paris
maintainerPATCH 5/5 fsnotify: add groups to fsnotify_inode_groups when registering inode watch
In reply to Eric ParisCurrently 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.
---
fs/notify/fsnotify.h | 2 ++ fs/notify/group.c | 18 ++++++++---------- fs/notify/inode_mark.c | 7 +++++++ 3 files changed, 17 insertions(+), 10 deletions(-)
fs/notify/fsnotify.h +2 -0
@@ -16,6 +16,8 @@ extern __u32 fsnotify_inode_mask;/* destroy all events sitting in this groups notification queue */ extern void fsnotify_flush_notify (struct fsnotify_group *group); +/* add a group to the inode group list */ +extern void fsnotify_add_inode_group (struct fsnotify_group *group);/* final kfree of a group */ extern void fsnotify_final_destroy_group (struct fsnotify_group *group);
fs/notify/group.c +8 -10
@@ -77,12 +77,15 @@ void fsnotify_recalc_group_mask(struct fsnotify_group *group)fsnotify_recalc_global_mask (); } -static void fsnotify_add_group (struct fsnotify_group *group) +void fsnotify_add_inode_group (struct fsnotify_group *group) { -BUG_ON (!mutex_is_locked (&fsnotify_grp_mutex)); +mutex_lock (&fsnotify_grp_mutex); +if (!group->on_inode_group_list) +list_add_tail_rcu (&group->inode_group_list, &fsnotify_inode_groups); group->on_inode_group_list =1 ; -list_add_tail_rcu (&group->inode_group_list, &fsnotify_inode_groups); + +mutex_unlock (&fsnotify_grp_mutex); }/*
@@ -189,7 +192,6 @@ struct fsnotify_group *fsnotify_alloc_group(__u32 mask,*/ atomic_set (&group->num_marks,1 ); - group->mask = mask;mutex_init (&group->notification_mutex);
@@ -197,17 +199,13 @@ struct fsnotify_group *fsnotify_alloc_group(__u32 mask,init_waitqueue_head (&group->notification_waitq); group->max_events =UINT_MAX ; +INIT_LIST_HEAD (&group->inode_group_list); +spin_lock_init (&group->mark_lock);INIT_LIST_HEAD (&group->mark_entries); group->ops = ops; -mutex_lock (&fsnotify_grp_mutex); - -fsnotify_add_group (group); - -mutex_unlock (&fsnotify_grp_mutex); -if (mask)fsnotify_recalc_global_mask ();
fs/notify/inode_mark.c +7 -0
@@ -324,6 +324,13 @@ int fsnotify_add_mark(struct fsnotify_mark_entry *entry,return -EINVAL ;/* +* if this group isn't being testing for inode type events we need +* to start testing +*/ +if (unlikely (list_empty (&group->inode_group_list))) +fsnotify_add_inode_group (group); + +/* * LOCKING ORDER!!!! * entry->lock * group->mark_lock