aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/notify/dnotify/dnotify.c3
-rw-r--r--fs/notify/group.c48
-rw-r--r--fs/notify/inotify/inotify_user.c11
-rw-r--r--include/linux/fsnotify_backend.h10
-rw-r--r--kernel/audit_tree.c3
-rw-r--r--kernel/audit_watch.c2
6 files changed, 7 insertions, 70 deletions
diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
index a213b83a59cf..1f46aeac3387 100644
--- a/fs/notify/dnotify/dnotify.c
+++ b/fs/notify/dnotify/dnotify.c
@@ -433,8 +433,7 @@ static int __init dnotify_init(void)
433 dnotify_struct_cache = KMEM_CACHE(dnotify_struct, SLAB_PANIC); 433 dnotify_struct_cache = KMEM_CACHE(dnotify_struct, SLAB_PANIC);
434 dnotify_mark_entry_cache = KMEM_CACHE(dnotify_mark_entry, SLAB_PANIC); 434 dnotify_mark_entry_cache = KMEM_CACHE(dnotify_mark_entry, SLAB_PANIC);
435 435
436 dnotify_group = fsnotify_obtain_group(DNOTIFY_GROUP_NUM, 436 dnotify_group = fsnotify_obtain_group(0, &dnotify_fsnotify_ops);
437 0, &dnotify_fsnotify_ops);
438 if (IS_ERR(dnotify_group)) 437 if (IS_ERR(dnotify_group))
439 panic("unable to allocate fsnotify group for dnotify\n"); 438 panic("unable to allocate fsnotify group for dnotify\n");
440 return 0; 439 return 0;
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
@@ -78,15 +78,6 @@ void fsnotify_recalc_group_mask(struct fsnotify_group *group)
78} 78}
79 79
80/* 80/*
81 * Take a reference to a group so things found under the fsnotify_grp_mutex
82 * can't get freed under us
83 */
84static void fsnotify_get_group(struct fsnotify_group *group)
85{
86 atomic_inc(&group->refcnt);
87}
88
89/*
90 * Final freeing of a group 81 * Final freeing of a group
91 */ 82 */
92void fsnotify_final_destroy_group(struct fsnotify_group *group) 83void fsnotify_final_destroy_group(struct fsnotify_group *group)
@@ -171,40 +162,14 @@ void fsnotify_put_group(struct fsnotify_group *group)
171} 162}
172 163
173/* 164/*
174 * Simply run the fsnotify_groups list and find a group which matches
175 * the given parameters. If a group is found we take a reference to that
176 * group.
177 */
178static struct fsnotify_group *fsnotify_find_group(unsigned int group_num, __u32 mask,
179 const struct fsnotify_ops *ops)
180{
181 struct fsnotify_group *group_iter;
182 struct fsnotify_group *group = NULL;
183
184 BUG_ON(!mutex_is_locked(&fsnotify_grp_mutex));
185
186 list_for_each_entry_rcu(group_iter, &fsnotify_groups, group_list) {
187 if (group_iter->group_num == group_num) {
188 if ((group_iter->mask == mask) &&
189 (group_iter->ops == ops)) {
190 fsnotify_get_group(group_iter);
191 group = group_iter;
192 } else
193 group = ERR_PTR(-EEXIST);
194 }
195 }
196 return group;
197}
198
199/*
200 * Either finds an existing group which matches the group_num, mask, and ops or 165 * Either finds an existing group which matches the group_num, mask, and ops or
201 * creates a new group and adds it to the global group list. In either case we 166 * creates a new group and adds it to the global group list. In either case we
202 * take a reference for the group returned. 167 * take a reference for the group returned.
203 */ 168 */
204struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask, 169struct fsnotify_group *fsnotify_obtain_group(__u32 mask,
205 const struct fsnotify_ops *ops) 170 const struct fsnotify_ops *ops)
206{ 171{
207 struct fsnotify_group *group, *tgroup; 172 struct fsnotify_group *group;
208 173
209 /* very low use, simpler locking if we just always alloc */ 174 /* very low use, simpler locking if we just always alloc */
210 group = kzalloc(sizeof(struct fsnotify_group), GFP_KERNEL); 175 group = kzalloc(sizeof(struct fsnotify_group), GFP_KERNEL);
@@ -214,7 +179,6 @@ struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask,
214 atomic_set(&group->refcnt, 1); 179 atomic_set(&group->refcnt, 1);
215 180
216 group->on_group_list = 0; 181 group->on_group_list = 0;
217 group->group_num = group_num;
218 group->mask = mask; 182 group->mask = mask;
219 183
220 mutex_init(&group->notification_mutex); 184 mutex_init(&group->notification_mutex);
@@ -230,14 +194,6 @@ struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask,
230 group->ops = ops; 194 group->ops = ops;
231 195
232 mutex_lock(&fsnotify_grp_mutex); 196 mutex_lock(&fsnotify_grp_mutex);
233 tgroup = fsnotify_find_group(group_num, mask, ops);
234 if (tgroup) {
235 /* group already exists */
236 mutex_unlock(&fsnotify_grp_mutex);
237 /* destroy the new one we made */
238 fsnotify_put_group(group);
239 return tgroup;
240 }
241 197
242 /* group not found, add a new one */ 198 /* group not found, add a new one */
243 list_add_rcu(&group->group_list, &fsnotify_groups); 199 list_add_rcu(&group->group_list, &fsnotify_groups);
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index cbe16df326f8..cae317f5bd9d 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -51,12 +51,6 @@ int inotify_max_user_watches __read_mostly;
51static struct kmem_cache *inotify_inode_mark_cachep __read_mostly; 51static struct kmem_cache *inotify_inode_mark_cachep __read_mostly;
52struct kmem_cache *event_priv_cachep __read_mostly; 52struct kmem_cache *event_priv_cachep __read_mostly;
53 53
54/*
55 * When inotify registers a new group it increments this and uses that
56 * value as an offset to set the fsnotify group "name" and priority.
57 */
58static atomic_t inotify_grp_num;
59
60#ifdef CONFIG_SYSCTL 54#ifdef CONFIG_SYSCTL
61 55
62#include <linux/sysctl.h> 56#include <linux/sysctl.h>
@@ -700,11 +694,8 @@ retry:
700static struct fsnotify_group *inotify_new_group(struct user_struct *user, unsigned int max_events) 694static struct fsnotify_group *inotify_new_group(struct user_struct *user, unsigned int max_events)
701{ 695{
702 struct fsnotify_group *group; 696 struct fsnotify_group *group;
703 unsigned int grp_num;
704 697
705 /* fsnotify_obtain_group took a reference to group, we put this when we kill the file in the end */ 698 group = fsnotify_obtain_group(0, &inotify_fsnotify_ops);
706 grp_num = (INOTIFY_GROUP_NUM - atomic_inc_return(&inotify_grp_num));
707 group = fsnotify_obtain_group(grp_num, 0, &inotify_fsnotify_ops);
708 if (IS_ERR(group)) 699 if (IS_ERR(group))
709 return group; 700 return group;
710 701
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 427f6ffab127..57e503d017c8 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -60,12 +60,6 @@
60 60
61#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO) 61#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO)
62 62
63/* listeners that hard code group numbers near the top */
64#define DNOTIFY_GROUP_NUM UINT_MAX
65#define AUDIT_WATCH_GROUP_NUM (DNOTIFY_GROUP_NUM-1)
66#define AUDIT_TREE_GROUP_NUM (AUDIT_WATCH_GROUP_NUM-1)
67#define INOTIFY_GROUP_NUM (AUDIT_TREE_GROUP_NUM-1)
68
69struct fsnotify_group; 63struct fsnotify_group;
70struct fsnotify_event; 64struct fsnotify_event;
71struct fsnotify_mark_entry; 65struct fsnotify_mark_entry;
@@ -124,7 +118,6 @@ struct fsnotify_group {
124 * closed. 118 * closed.
125 */ 119 */
126 atomic_t refcnt; /* things with interest in this group */ 120 atomic_t refcnt; /* things with interest in this group */
127 unsigned int group_num; /* simply prevents accidental group collision */
128 121
129 const struct fsnotify_ops *ops; /* how this group handles things */ 122 const struct fsnotify_ops *ops; /* how this group handles things */
130 123
@@ -312,8 +305,7 @@ static inline void __fsnotify_d_instantiate(struct dentry *dentry, struct inode
312/* must call when a group changes its ->mask */ 305/* must call when a group changes its ->mask */
313extern void fsnotify_recalc_global_mask(void); 306extern void fsnotify_recalc_global_mask(void);
314/* get a reference to an existing or create a new group */ 307/* get a reference to an existing or create a new group */
315extern struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, 308extern struct fsnotify_group *fsnotify_obtain_group(__u32 mask,
316 __u32 mask,
317 const struct fsnotify_ops *ops); 309 const struct fsnotify_ops *ops);
318/* run all marks associated with this group and update group->mask */ 310/* run all marks associated with this group and update group->mask */
319extern void fsnotify_recalc_group_mask(struct fsnotify_group *group); 311extern void fsnotify_recalc_group_mask(struct fsnotify_group *group);
diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c
index e3d63b596ef0..59065e72a2eb 100644
--- a/kernel/audit_tree.c
+++ b/kernel/audit_tree.c
@@ -937,8 +937,7 @@ static int __init audit_tree_init(void)
937{ 937{
938 int i; 938 int i;
939 939
940 audit_tree_group = fsnotify_obtain_group(AUDIT_TREE_GROUP_NUM, 940 audit_tree_group = fsnotify_obtain_group(0, &audit_tree_ops);
941 0, &audit_tree_ops);
942 if (IS_ERR(audit_tree_group)) 941 if (IS_ERR(audit_tree_group))
943 audit_panic("cannot initialize fsnotify group for rectree watches"); 942 audit_panic("cannot initialize fsnotify group for rectree watches");
944 943
diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
index 85c43aa292e0..c500104d38c2 100644
--- a/kernel/audit_watch.c
+++ b/kernel/audit_watch.c
@@ -577,7 +577,7 @@ static const struct fsnotify_ops audit_watch_fsnotify_ops = {
577 577
578static int __init audit_watch_init(void) 578static int __init audit_watch_init(void)
579{ 579{
580 audit_watch_group = fsnotify_obtain_group(AUDIT_WATCH_GROUP_NUM, AUDIT_FS_WATCH, 580 audit_watch_group = fsnotify_obtain_group(AUDIT_FS_WATCH,
581 &audit_watch_fsnotify_ops); 581 &audit_watch_fsnotify_ops);
582 if (IS_ERR(audit_watch_group)) { 582 if (IS_ERR(audit_watch_group)) {
583 audit_watch_group = NULL; 583 audit_watch_group = NULL;