From f0553af054d31f48a75fddd3ef8beb5c39715019 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 17 Dec 2009 20:12:06 -0500 Subject: fsnotify: kzalloc fsnotify groups Use kzalloc for fsnotify_groups so that none of the fields can leak any information accidentally. Signed-off-by: Eric Paris --- fs/notify/group.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index 0e1677144bc5..777ca8212255 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -207,7 +207,7 @@ struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask, struct fsnotify_group *group, *tgroup; /* very low use, simpler locking if we just always alloc */ - group = kmalloc(sizeof(struct fsnotify_group), GFP_KERNEL); + group = kzalloc(sizeof(struct fsnotify_group), GFP_KERNEL); if (!group) return ERR_PTR(-ENOMEM); -- cgit v1.2.2 From 74be0cc82835aecad332a29896b0f212ba893403 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 17 Dec 2009 21:24:22 -0500 Subject: fsnotify: remove group_num altogether The original fsnotify interface has a group-num which was intended to be able to find a group after it was added. I no longer think this is a necessary thing to do and so we remove the group_num. Signed-off-by: Eric Paris --- fs/notify/group.c | 48 ++---------------------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index 777ca8212255..62fb8961a57b 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -77,15 +77,6 @@ void fsnotify_recalc_group_mask(struct fsnotify_group *group) fsnotify_recalc_global_mask(); } -/* - * Take a reference to a group so things found under the fsnotify_grp_mutex - * can't get freed under us - */ -static void fsnotify_get_group(struct fsnotify_group *group) -{ - atomic_inc(&group->refcnt); -} - /* * Final freeing of a group */ @@ -170,41 +161,15 @@ void fsnotify_put_group(struct fsnotify_group *group) fsnotify_destroy_group(group); } -/* - * Simply run the fsnotify_groups list and find a group which matches - * the given parameters. If a group is found we take a reference to that - * group. - */ -static struct fsnotify_group *fsnotify_find_group(unsigned int group_num, __u32 mask, - const struct fsnotify_ops *ops) -{ - struct fsnotify_group *group_iter; - struct fsnotify_group *group = NULL; - - BUG_ON(!mutex_is_locked(&fsnotify_grp_mutex)); - - list_for_each_entry_rcu(group_iter, &fsnotify_groups, group_list) { - if (group_iter->group_num == group_num) { - if ((group_iter->mask == mask) && - (group_iter->ops == ops)) { - fsnotify_get_group(group_iter); - group = group_iter; - } else - group = ERR_PTR(-EEXIST); - } - } - return 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. */ -struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask, +struct fsnotify_group *fsnotify_obtain_group(__u32 mask, const struct fsnotify_ops *ops) { - struct fsnotify_group *group, *tgroup; + struct fsnotify_group *group; /* very low use, simpler locking if we just always alloc */ group = kzalloc(sizeof(struct fsnotify_group), GFP_KERNEL); @@ -214,7 +179,6 @@ struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask, atomic_set(&group->refcnt, 1); group->on_group_list = 0; - group->group_num = group_num; group->mask = mask; mutex_init(&group->notification_mutex); @@ -230,14 +194,6 @@ struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask, group->ops = ops; mutex_lock(&fsnotify_grp_mutex); - tgroup = fsnotify_find_group(group_num, mask, ops); - if (tgroup) { - /* group already exists */ - mutex_unlock(&fsnotify_grp_mutex); - /* destroy the new one we made */ - fsnotify_put_group(group); - return tgroup; - } /* group not found, add a new one */ list_add_rcu(&group->group_list, &fsnotify_groups); -- cgit v1.2.2 From cd7752ce7cac5184ca35aecebffafae9662570bc Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 17 Dec 2009 21:24:22 -0500 Subject: 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. Signed-off-by: Eric Paris --- fs/notify/group.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index 62fb8961a57b..934860e98095 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -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; -- cgit v1.2.2 From ffab83402f01555a5fa32efb48a4dd0ce8d12ef5 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 17 Dec 2009 21:24:22 -0500 Subject: 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. Signed-off-by: Eric Paris --- fs/notify/group.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index 934860e98095..1d20d26d5fee 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -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 */ -- cgit v1.2.2 From 0d2e2a1d00d7d23e5bd9bb0935cde7c3d5835c56 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 17 Dec 2009 21:24:22 -0500 Subject: fsnotify: drop mask argument from fsnotify_alloc_group Nothing uses the mask argument to fsnotify_alloc_group. This patch drops that argument. Signed-off-by: Eric Paris --- fs/notify/group.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index 1d20d26d5fee..1657349c30a6 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -164,8 +164,7 @@ void fsnotify_put_group(struct fsnotify_group *group) /* * Create a new fsnotify_group and hold a reference for the group returned. */ -struct fsnotify_group *fsnotify_alloc_group(__u32 mask, - const struct fsnotify_ops *ops) +struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) { struct fsnotify_group *group; @@ -175,8 +174,6 @@ struct fsnotify_group *fsnotify_alloc_group(__u32 mask, atomic_set(&group->refcnt, 1); - group->mask = mask; - mutex_init(&group->notification_mutex); INIT_LIST_HEAD(&group->notification_list); init_waitqueue_head(&group->notification_waitq); @@ -196,8 +193,5 @@ struct fsnotify_group *fsnotify_alloc_group(__u32 mask, mutex_unlock(&fsnotify_grp_mutex); - if (mask) - fsnotify_recalc_global_mask(); - return group; } -- cgit v1.2.2 From 19c2a0e1a2f60112c158342ba5f568f72b741c2c Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 17 Dec 2009 21:24:23 -0500 Subject: fsnotify: rename fsnotify_groups to fsnotify_inode_groups Simple 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. Signed-off-by: Eric Paris --- fs/notify/group.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index 1657349c30a6..c80809745312 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -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; } /* @@ -186,10 +197,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) 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); -- cgit v1.2.2 From 36fddebaa8a9186d4f5817ab798a83400b2fb2e7 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 17 Dec 2009 21:24:23 -0500 Subject: fsnotify: initialize the group->num_marks in a better place Currently 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. Signed-off-by: Eric Paris --- fs/notify/group.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index c80809745312..656c534ffb66 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -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); } @@ -183,7 +180,14 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) 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); + mutex_init(&group->notification_mutex); INIT_LIST_HEAD(&group->notification_list); -- cgit v1.2.2 From 4ca763523e040dc61191d4866a82981a5d30a4e9 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 17 Dec 2009 21:24:23 -0500 Subject: 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 --- fs/notify/group.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index 656c534ffb66..34fccbd2809c 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -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); } /* @@ -188,22 +191,17 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) */ atomic_set(&group->num_marks, 1); - mutex_init(&group->notification_mutex); INIT_LIST_HEAD(&group->notification_list); 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); - return group; } -- cgit v1.2.2 From 7131485a93679ff9a543b74df280cfd119eb03ca Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 17 Dec 2009 21:24:23 -0500 Subject: fsnotify: mount point listeners list and global mask currently all of the notification systems implemented select which inodes they care about and receive messages only about those inodes (or the children of those inodes.) This patch begins to flesh out fsnotify support for the concept of listeners that want to hear notification for an inode accessed below a given monut point. This patch implements a second list of fsnotify groups to hold these types of groups and a second global mask to hold the events of interest for this type of group. The reason we want a second group list and mask is because the inode based notification should_send_event support which makes each group look for a mark on the given inode. With one nfsmount listener that means that every group would have to take the inode->i_lock, look for their mark, not find one, and return for every operation. By seperating vfsmount from inode listeners only when there is a inode listener will the inode groups have to look for their mark and take the inode lock. vfsmount listeners will have to grab the lock and look for a mark but there should be fewer of them, and one vfsmount listener won't cause the i_lock to be grabbed and released for every fsnotify group on every io operation. Signed-off-by: Eric Paris --- fs/notify/group.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index 34fccbd2809c..aa4654fe6ec2 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -32,10 +32,14 @@ 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 */ +/* all groups registered to receive inode filesystem notifications */ LIST_HEAD(fsnotify_inode_groups); +/* all groups registered to receive mount point filesystem notifications */ +LIST_HEAD(fsnotify_vfsmount_groups); /* bitwise OR of all events (FS_*) interesting to some group on this system */ __u32 fsnotify_inode_mask; +/* bitwise OR of all events (FS_*) interesting to some group on this system */ +__u32 fsnotify_vfsmount_mask; /* * When a new group registers or changes it's set of interesting events @@ -44,14 +48,20 @@ __u32 fsnotify_inode_mask; void fsnotify_recalc_global_mask(void) { struct fsnotify_group *group; - __u32 mask = 0; + __u32 inode_mask = 0; + __u32 vfsmount_mask = 0; int idx; idx = srcu_read_lock(&fsnotify_grp_srcu); list_for_each_entry_rcu(group, &fsnotify_inode_groups, inode_group_list) - mask |= group->mask; + inode_mask |= group->mask; + list_for_each_entry_rcu(group, &fsnotify_vfsmount_groups, vfsmount_group_list) + vfsmount_mask |= group->mask; + srcu_read_unlock(&fsnotify_grp_srcu, idx); - fsnotify_inode_mask = mask; + + fsnotify_inode_mask = inode_mask; + fsnotify_vfsmount_mask = vfsmount_mask; } /* @@ -77,6 +87,17 @@ void fsnotify_recalc_group_mask(struct fsnotify_group *group) fsnotify_recalc_global_mask(); } +void fsnotify_add_vfsmount_group(struct fsnotify_group *group) +{ + mutex_lock(&fsnotify_grp_mutex); + + if (!group->on_vfsmount_group_list) + list_add_tail_rcu(&group->vfsmount_group_list, &fsnotify_vfsmount_groups); + group->on_vfsmount_group_list = 1; + + mutex_unlock(&fsnotify_grp_mutex); +} + void fsnotify_add_inode_group(struct fsnotify_group *group) { mutex_lock(&fsnotify_grp_mutex); @@ -132,6 +153,9 @@ static void __fsnotify_evict_group(struct fsnotify_group *group) if (group->on_inode_group_list) list_del_rcu(&group->inode_group_list); group->on_inode_group_list = 0; + if (group->on_vfsmount_group_list) + list_del_rcu(&group->vfsmount_group_list); + group->on_vfsmount_group_list = 0; } /* @@ -197,6 +221,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) group->max_events = UINT_MAX; INIT_LIST_HEAD(&group->inode_group_list); + INIT_LIST_HEAD(&group->vfsmount_group_list); spin_lock_init(&group->mark_lock); INIT_LIST_HEAD(&group->mark_entries); -- cgit v1.2.2 From e61ce86737b4d60521e4e71f9892fe4bdcfb688b Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 17 Dec 2009 21:24:24 -0500 Subject: fsnotify: rename fsnotify_mark_entry to just fsnotify_mark The name is long and it serves no real purpose. So rename fsnotify_mark_entry to just fsnotify_mark. Signed-off-by: Eric Paris --- fs/notify/group.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index aa4654fe6ec2..b70e7d21dfde 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -74,10 +74,10 @@ void fsnotify_recalc_group_mask(struct fsnotify_group *group) { __u32 mask = 0; __u32 old_mask = group->mask; - struct fsnotify_mark_entry *entry; + struct fsnotify_mark *entry; spin_lock(&group->mark_lock); - list_for_each_entry(entry, &group->mark_entries, g_list) + list_for_each_entry(entry, &group->marks_list, g_list) mask |= entry->mask; spin_unlock(&group->mark_lock); @@ -133,7 +133,7 @@ void fsnotify_final_destroy_group(struct fsnotify_group *group) */ static void fsnotify_destroy_group(struct fsnotify_group *group) { - /* clear all inode mark entries for this group */ + /* clear all inode marks for this group */ fsnotify_clear_marks_by_group(group); /* past the point of no return, matches the initial value of 1 */ @@ -224,7 +224,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) INIT_LIST_HEAD(&group->vfsmount_group_list); spin_lock_init(&group->mark_lock); - INIT_LIST_HEAD(&group->mark_entries); + INIT_LIST_HEAD(&group->marks_list); group->ops = ops; -- cgit v1.2.2 From 841bdc10f573aa010dd5818d35a5690b7d9f73ce Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 17 Dec 2009 21:24:24 -0500 Subject: fsnotify: rename mark_entry to just mark previously I used mark_entry when talking about marks on inodes. The _entry is pretty useless. Just use "mark" instead. Signed-off-by: Eric Paris --- fs/notify/group.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index b70e7d21dfde..9e9eb406afdd 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -74,11 +74,11 @@ void fsnotify_recalc_group_mask(struct fsnotify_group *group) { __u32 mask = 0; __u32 old_mask = group->mask; - struct fsnotify_mark *entry; + struct fsnotify_mark *mark; spin_lock(&group->mark_lock); - list_for_each_entry(entry, &group->marks_list, g_list) - mask |= entry->mask; + list_for_each_entry(mark, &group->marks_list, g_list) + mask |= mark->mask; spin_unlock(&group->mark_lock); group->mask = mask; -- cgit v1.2.2 From cb2d429faf2cae62d3c51e28099a181d5fe8c244 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 17 Dec 2009 21:24:34 -0500 Subject: fsnotify: add group priorities This introduces an ordering to fsnotify groups. With purely asynchronous notification based "things" implementing fsnotify (inotify, dnotify) ordering isn't particularly important. But if people want to use fsnotify for the basis of sycronous notification or blocking notification ordering becomes important. eg. A Hierarchical Storage Management listener would need to get its event before an AV scanner could get its event (since the HSM would need to bring the data in for the AV scanner to scan.) Typically asynchronous notification would want to run after the AV scanner made any relevant access decisions so as to not send notification about an event that was denied. Signed-off-by: Eric Paris --- fs/notify/group.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index 9e9eb406afdd..ada913fd4f7f 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -89,10 +89,27 @@ void fsnotify_recalc_group_mask(struct fsnotify_group *group) void fsnotify_add_vfsmount_group(struct fsnotify_group *group) { + struct fsnotify_group *group_iter; + unsigned int priority = group->priority; + mutex_lock(&fsnotify_grp_mutex); - if (!group->on_vfsmount_group_list) + if (!group->on_vfsmount_group_list) { + list_for_each_entry(group_iter, &fsnotify_vfsmount_groups, + vfsmount_group_list) { + /* insert in front of this one? */ + if (priority < group_iter->priority) { + /* list_add_tail() insert in front of group_iter */ + list_add_tail_rcu(&group->inode_group_list, + &group_iter->inode_group_list); + goto out; + } + } + + /* apparently we need to be the last entry */ list_add_tail_rcu(&group->vfsmount_group_list, &fsnotify_vfsmount_groups); + } +out: group->on_vfsmount_group_list = 1; mutex_unlock(&fsnotify_grp_mutex); @@ -100,10 +117,27 @@ void fsnotify_add_vfsmount_group(struct fsnotify_group *group) void fsnotify_add_inode_group(struct fsnotify_group *group) { + struct fsnotify_group *group_iter; + unsigned int priority = group->priority; + mutex_lock(&fsnotify_grp_mutex); - if (!group->on_inode_group_list) + /* add to global group list, priority 0 first, UINT_MAX last */ + if (!group->on_inode_group_list) { + list_for_each_entry(group_iter, &fsnotify_inode_groups, + inode_group_list) { + if (priority < group_iter->priority) { + /* list_add_tail() insert in front of group_iter */ + list_add_tail_rcu(&group->inode_group_list, + &group_iter->inode_group_list); + goto out; + } + } + + /* apparently we need to be the last entry */ list_add_tail_rcu(&group->inode_group_list, &fsnotify_inode_groups); + } +out: group->on_inode_group_list = 1; mutex_unlock(&fsnotify_grp_mutex); @@ -226,6 +260,8 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) spin_lock_init(&group->mark_lock); INIT_LIST_HEAD(&group->marks_list); + group->priority = UINT_MAX; + group->ops = ops; return group; -- cgit v1.2.2 From 08ae89380a8210a9965d04083e1de78cb8bca4b1 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Thu, 27 May 2010 09:41:40 -0400 Subject: fanotify: drop the useless priority argument The priority argument in fanotify is useless. Kill it. Signed-off-by: Eric Paris --- fs/notify/group.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index ada913fd4f7f..7ac65ed4735b 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -90,7 +90,6 @@ void fsnotify_recalc_group_mask(struct fsnotify_group *group) void fsnotify_add_vfsmount_group(struct fsnotify_group *group) { struct fsnotify_group *group_iter; - unsigned int priority = group->priority; mutex_lock(&fsnotify_grp_mutex); @@ -98,7 +97,7 @@ void fsnotify_add_vfsmount_group(struct fsnotify_group *group) list_for_each_entry(group_iter, &fsnotify_vfsmount_groups, vfsmount_group_list) { /* insert in front of this one? */ - if (priority < group_iter->priority) { + if (group < group_iter) { /* list_add_tail() insert in front of group_iter */ list_add_tail_rcu(&group->inode_group_list, &group_iter->inode_group_list); @@ -118,15 +117,14 @@ out: void fsnotify_add_inode_group(struct fsnotify_group *group) { struct fsnotify_group *group_iter; - unsigned int priority = group->priority; mutex_lock(&fsnotify_grp_mutex); - /* add to global group list, priority 0 first, UINT_MAX last */ + /* add to global group list */ if (!group->on_inode_group_list) { list_for_each_entry(group_iter, &fsnotify_inode_groups, inode_group_list) { - if (priority < group_iter->priority) { + if (group < group_iter) { /* list_add_tail() insert in front of group_iter */ list_add_tail_rcu(&group->inode_group_list, &group_iter->inode_group_list); @@ -260,8 +258,6 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) spin_lock_init(&group->mark_lock); INIT_LIST_HEAD(&group->marks_list); - group->priority = UINT_MAX; - group->ops = ops; return group; -- cgit v1.2.2 From 75c1be487a690db43da2c1234fcacd84c982803c Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Wed, 28 Jul 2010 10:18:38 -0400 Subject: fsnotify: srcu to protect read side of inode and vfsmount locks Currently reading the inode->i_fsnotify_marks or vfsmount->mnt_fsnotify_marks lists are protected by a spinlock on both the read and the write side. This patch protects the read side of those lists with a new single srcu. Signed-off-by: Eric Paris --- fs/notify/group.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index 7ac65ed4735b..48d3a6d6e47a 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -30,8 +30,6 @@ /* protects writes to fsnotify_groups and fsnotify_mask */ 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 inode filesystem notifications */ LIST_HEAD(fsnotify_inode_groups); /* all groups registered to receive mount point filesystem notifications */ @@ -50,18 +48,17 @@ void fsnotify_recalc_global_mask(void) struct fsnotify_group *group; __u32 inode_mask = 0; __u32 vfsmount_mask = 0; - int idx; - idx = srcu_read_lock(&fsnotify_grp_srcu); + mutex_lock(&fsnotify_grp_mutex); list_for_each_entry_rcu(group, &fsnotify_inode_groups, inode_group_list) inode_mask |= group->mask; list_for_each_entry_rcu(group, &fsnotify_vfsmount_groups, vfsmount_group_list) vfsmount_mask |= group->mask; - - srcu_read_unlock(&fsnotify_grp_srcu, idx); fsnotify_inode_mask = inode_mask; fsnotify_vfsmount_mask = vfsmount_mask; + + mutex_unlock(&fsnotify_grp_mutex); } /* @@ -168,6 +165,8 @@ static void fsnotify_destroy_group(struct fsnotify_group *group) /* clear all inode marks for this group */ fsnotify_clear_marks_by_group(group); + synchronize_srcu(&fsnotify_mark_srcu); + /* past the point of no return, matches the initial value of 1 */ if (atomic_dec_and_test(&group->num_marks)) fsnotify_final_destroy_group(group); @@ -216,12 +215,7 @@ void fsnotify_put_group(struct fsnotify_group *group) */ __fsnotify_evict_group(group); - /* - * now it's off the list, so the only thing we might care about is - * srcu access.... - */ mutex_unlock(&fsnotify_grp_mutex); - synchronize_srcu(&fsnotify_grp_srcu); /* and now it is really dead. _Nothing_ could be seeing it */ fsnotify_recalc_global_mask(); -- cgit v1.2.2 From 03930979afa63e079e9aefd4d3dd429240711027 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Wed, 28 Jul 2010 10:18:39 -0400 Subject: fsnotify: remove the global masks Because we walk the object->fsnotify_marks list instead of the global fsnotify groups list we don't need the fsnotify_inode_mask and fsnotify_vfsmount_mask as these were simply shortcuts in fsnotify() for performance. They are now extra checks, rip them out. Signed-off-by: Eric Paris --- fs/notify/group.c | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index 48d3a6d6e47a..8da532dd6026 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -34,54 +34,21 @@ static DEFINE_MUTEX(fsnotify_grp_mutex); LIST_HEAD(fsnotify_inode_groups); /* all groups registered to receive mount point filesystem notifications */ LIST_HEAD(fsnotify_vfsmount_groups); -/* bitwise OR of all events (FS_*) interesting to some group on this system */ -__u32 fsnotify_inode_mask; -/* bitwise OR of all events (FS_*) interesting to some group on this system */ -__u32 fsnotify_vfsmount_mask; - -/* - * When a new group registers or changes it's set of interesting events - * this function updates the fsnotify_mask to contain all interesting events - */ -void fsnotify_recalc_global_mask(void) -{ - struct fsnotify_group *group; - __u32 inode_mask = 0; - __u32 vfsmount_mask = 0; - - mutex_lock(&fsnotify_grp_mutex); - list_for_each_entry_rcu(group, &fsnotify_inode_groups, inode_group_list) - inode_mask |= group->mask; - list_for_each_entry_rcu(group, &fsnotify_vfsmount_groups, vfsmount_group_list) - vfsmount_mask |= group->mask; - - fsnotify_inode_mask = inode_mask; - fsnotify_vfsmount_mask = vfsmount_mask; - - mutex_unlock(&fsnotify_grp_mutex); -} /* * Update the group->mask by running all of the marks associated with this - * group and finding the bitwise | of all of the mark->mask. If we change - * the group->mask we need to update the global mask of events interesting - * to the system. + * group and finding the bitwise | of all of the mark->mask. */ void fsnotify_recalc_group_mask(struct fsnotify_group *group) { __u32 mask = 0; - __u32 old_mask = group->mask; struct fsnotify_mark *mark; spin_lock(&group->mark_lock); list_for_each_entry(mark, &group->marks_list, g_list) mask |= mark->mask; - spin_unlock(&group->mark_lock); - group->mask = mask; - - if (old_mask != mask) - fsnotify_recalc_global_mask(); + spin_unlock(&group->mark_lock); } void fsnotify_add_vfsmount_group(struct fsnotify_group *group) @@ -217,8 +184,6 @@ void fsnotify_put_group(struct fsnotify_group *group) mutex_unlock(&fsnotify_grp_mutex); - /* and now it is really dead. _Nothing_ could be seeing it */ - fsnotify_recalc_global_mask(); fsnotify_destroy_group(group); } -- cgit v1.2.2 From 43709a288ed03aa0e2979ab63dd089b3889645c4 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Wed, 28 Jul 2010 10:18:39 -0400 Subject: fsnotify: remove group->mask group->mask is now useless. It was originally a shortcut for fsnotify to save on performance. These checks are now redundant, so we remove them. Signed-off-by: Eric Paris --- fs/notify/group.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index 8da532dd6026..fc0d966b270f 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -35,22 +35,6 @@ LIST_HEAD(fsnotify_inode_groups); /* all groups registered to receive mount point filesystem notifications */ LIST_HEAD(fsnotify_vfsmount_groups); -/* - * Update the group->mask by running all of the marks associated with this - * group and finding the bitwise | of all of the mark->mask. - */ -void fsnotify_recalc_group_mask(struct fsnotify_group *group) -{ - __u32 mask = 0; - struct fsnotify_mark *mark; - - spin_lock(&group->mark_lock); - list_for_each_entry(mark, &group->marks_list, g_list) - mask |= mark->mask; - group->mask = mask; - spin_unlock(&group->mark_lock); -} - void fsnotify_add_vfsmount_group(struct fsnotify_group *group) { struct fsnotify_group *group_iter; -- cgit v1.2.2 From 02436668d98385f5b5d9ffb695a37dadf98ed8a8 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Wed, 28 Jul 2010 10:18:39 -0400 Subject: fsnotify: remove global fsnotify groups lists The global fsnotify groups lists were invented as a way to increase the performance of fsnotify by shortcutting events which were not interesting. With the changes to walk the object lists rather than global groups lists these shortcuts are not useful. Signed-off-by: Eric Paris --- fs/notify/group.c | 107 +----------------------------------------------------- 1 file changed, 2 insertions(+), 105 deletions(-) (limited to 'fs/notify/group.c') diff --git a/fs/notify/group.c b/fs/notify/group.c index fc0d966b270f..d309f38449cb 100644 --- a/fs/notify/group.c +++ b/fs/notify/group.c @@ -28,67 +28,6 @@ #include -/* protects writes to fsnotify_groups and fsnotify_mask */ -static DEFINE_MUTEX(fsnotify_grp_mutex); -/* all groups registered to receive inode filesystem notifications */ -LIST_HEAD(fsnotify_inode_groups); -/* all groups registered to receive mount point filesystem notifications */ -LIST_HEAD(fsnotify_vfsmount_groups); - -void fsnotify_add_vfsmount_group(struct fsnotify_group *group) -{ - struct fsnotify_group *group_iter; - - mutex_lock(&fsnotify_grp_mutex); - - if (!group->on_vfsmount_group_list) { - list_for_each_entry(group_iter, &fsnotify_vfsmount_groups, - vfsmount_group_list) { - /* insert in front of this one? */ - if (group < group_iter) { - /* list_add_tail() insert in front of group_iter */ - list_add_tail_rcu(&group->inode_group_list, - &group_iter->inode_group_list); - goto out; - } - } - - /* apparently we need to be the last entry */ - list_add_tail_rcu(&group->vfsmount_group_list, &fsnotify_vfsmount_groups); - } -out: - group->on_vfsmount_group_list = 1; - - mutex_unlock(&fsnotify_grp_mutex); -} - -void fsnotify_add_inode_group(struct fsnotify_group *group) -{ - struct fsnotify_group *group_iter; - - mutex_lock(&fsnotify_grp_mutex); - - /* add to global group list */ - if (!group->on_inode_group_list) { - list_for_each_entry(group_iter, &fsnotify_inode_groups, - inode_group_list) { - if (group < group_iter) { - /* list_add_tail() insert in front of group_iter */ - list_add_tail_rcu(&group->inode_group_list, - &group_iter->inode_group_list); - goto out; - } - } - - /* apparently we need to be the last entry */ - list_add_tail_rcu(&group->inode_group_list, &fsnotify_inode_groups); - } -out: - group->on_inode_group_list = 1; - - mutex_unlock(&fsnotify_grp_mutex); -} - /* * Final freeing of a group */ @@ -123,52 +62,13 @@ static void fsnotify_destroy_group(struct fsnotify_group *group) fsnotify_final_destroy_group(group); } -/* - * Remove this group from the global list of groups that will get events - * this can be done even if there are still references and things still using - * this group. This just stops the group from getting new events. - */ -static void __fsnotify_evict_group(struct fsnotify_group *group) -{ - BUG_ON(!mutex_is_locked(&fsnotify_grp_mutex)); - - if (group->on_inode_group_list) - list_del_rcu(&group->inode_group_list); - group->on_inode_group_list = 0; - if (group->on_vfsmount_group_list) - list_del_rcu(&group->vfsmount_group_list); - group->on_vfsmount_group_list = 0; -} - -/* - * Called when a group is no longer interested in getting events. This can be - * used if a group is misbehaving or if for some reason a group should no longer - * get any filesystem events. - */ -void fsnotify_evict_group(struct fsnotify_group *group) -{ - mutex_lock(&fsnotify_grp_mutex); - __fsnotify_evict_group(group); - mutex_unlock(&fsnotify_grp_mutex); -} - /* * Drop a reference to a group. Free it if it's through. */ void fsnotify_put_group(struct fsnotify_group *group) { - if (!atomic_dec_and_mutex_lock(&group->refcnt, &fsnotify_grp_mutex)) - return; - - /* - * OK, now we know that there's no other users *and* we hold mutex, - * so no new references will appear - */ - __fsnotify_evict_group(group); - - mutex_unlock(&fsnotify_grp_mutex); - - fsnotify_destroy_group(group); + if (atomic_dec_and_test(&group->refcnt)) + fsnotify_destroy_group(group); } /* @@ -195,9 +95,6 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) init_waitqueue_head(&group->notification_waitq); group->max_events = UINT_MAX; - INIT_LIST_HEAD(&group->inode_group_list); - INIT_LIST_HEAD(&group->vfsmount_group_list); - spin_lock_init(&group->mark_lock); INIT_LIST_HEAD(&group->marks_list); -- cgit v1.2.2