Skip to content

Commit 74be0cc

Browse files
committed
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 <eparis@redhat.com>
1 parent cac69da commit 74be0cc

6 files changed

Lines changed: 7 additions & 70 deletions

File tree

‎fs/notify/dnotify/dnotify.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,7 @@ static int __init dnotify_init(void)
433433
dnotify_struct_cache = KMEM_CACHE(dnotify_struct, SLAB_PANIC);
434434
dnotify_mark_entry_cache = KMEM_CACHE(dnotify_mark_entry, SLAB_PANIC);
435435

436-
dnotify_group = fsnotify_obtain_group(DNOTIFY_GROUP_NUM,
437-
0, &dnotify_fsnotify_ops);
436+
dnotify_group = fsnotify_obtain_group(0, &dnotify_fsnotify_ops);
438437
if (IS_ERR(dnotify_group))
439438
panic("unable to allocate fsnotify group for dnotify\n");
440439
return 0;

‎fs/notify/group.c‎

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

80-
/*
81-
* Take a reference to a group so things found under the fsnotify_grp_mutex
82-
* can't get freed under us
83-
*/
84-
static void fsnotify_get_group(struct fsnotify_group *group)
85-
{
86-
atomic_inc(&group->refcnt);
87-
}
88-
8980
/*
9081
* Final freeing of a group
9182
*/
@@ -170,41 +161,15 @@ void fsnotify_put_group(struct fsnotify_group *group)
170161
fsnotify_destroy_group(group);
171162
}
172163

173-
/*
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-
*/
178-
static 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-
199164
/*
200165
* Either finds an existing group which matches the group_num, mask, and ops or
201166
* creates a new group and adds it to the global group list. In either case we
202167
* take a reference for the group returned.
203168
*/
204-
struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask,
169+
struct fsnotify_group *fsnotify_obtain_group(__u32 mask,
205170
const struct fsnotify_ops *ops)
206171
{
207-
struct fsnotify_group *group, *tgroup;
172+
struct fsnotify_group *group;
208173

209174
/* very low use, simpler locking if we just always alloc */
210175
group = kzalloc(sizeof(struct fsnotify_group), GFP_KERNEL);
@@ -214,7 +179,6 @@ struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask,
214179
atomic_set(&group->refcnt, 1);
215180

216181
group->on_group_list = 0;
217-
group->group_num = group_num;
218182
group->mask = mask;
219183

220184
mutex_init(&group->notification_mutex);
@@ -230,14 +194,6 @@ struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask,
230194
group->ops = ops;
231195

232196
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-
}
241197

242198
/* group not found, add a new one */
243199
list_add_rcu(&group->group_list, &fsnotify_groups);

‎fs/notify/inotify/inotify_user.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ int inotify_max_user_watches __read_mostly;
5151
static struct kmem_cache *inotify_inode_mark_cachep __read_mostly;
5252
struct kmem_cache *event_priv_cachep __read_mostly;
5353

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-
*/
58-
static atomic_t inotify_grp_num;
59-
6054
#ifdef CONFIG_SYSCTL
6155

6256
#include <linux/sysctl.h>
@@ -700,11 +694,8 @@ static int inotify_update_watch(struct fsnotify_group *group, struct inode *inod
700694
static struct fsnotify_group *inotify_new_group(struct user_struct *user, unsigned int max_events)
701695
{
702696
struct fsnotify_group *group;
703-
unsigned int grp_num;
704697

705-
/* fsnotify_obtain_group took a reference to group, we put this when we kill the file in the end */
706-
grp_num = (INOTIFY_GROUP_NUM - atomic_inc_return(&inotify_grp_num));
707-
group = fsnotify_obtain_group(grp_num, 0, &inotify_fsnotify_ops);
698+
group = fsnotify_obtain_group(0, &inotify_fsnotify_ops);
708699
if (IS_ERR(group))
709700
return group;
710701

‎include/linux/fsnotify_backend.h‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@
6060

6161
#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO)
6262

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-
6963
struct fsnotify_group;
7064
struct fsnotify_event;
7165
struct fsnotify_mark_entry;
@@ -124,7 +118,6 @@ struct fsnotify_group {
124118
* closed.
125119
*/
126120
atomic_t refcnt; /* things with interest in this group */
127-
unsigned int group_num; /* simply prevents accidental group collision */
128121

129122
const struct fsnotify_ops *ops; /* how this group handles things */
130123

@@ -312,8 +305,7 @@ static inline void __fsnotify_d_instantiate(struct dentry *dentry, struct inode
312305
/* must call when a group changes its ->mask */
313306
extern void fsnotify_recalc_global_mask(void);
314307
/* get a reference to an existing or create a new group */
315-
extern struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num,
316-
__u32 mask,
308+
extern struct fsnotify_group *fsnotify_obtain_group(__u32 mask,
317309
const struct fsnotify_ops *ops);
318310
/* run all marks associated with this group and update group->mask */
319311
extern void fsnotify_recalc_group_mask(struct fsnotify_group *group);

‎kernel/audit_tree.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,7 @@ static int __init audit_tree_init(void)
937937
{
938938
int i;
939939

940-
audit_tree_group = fsnotify_obtain_group(AUDIT_TREE_GROUP_NUM,
941-
0, &audit_tree_ops);
940+
audit_tree_group = fsnotify_obtain_group(0, &audit_tree_ops);
942941
if (IS_ERR(audit_tree_group))
943942
audit_panic("cannot initialize fsnotify group for rectree watches");
944943

‎kernel/audit_watch.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ static const struct fsnotify_ops audit_watch_fsnotify_ops = {
577577

578578
static int __init audit_watch_init(void)
579579
{
580-
audit_watch_group = fsnotify_obtain_group(AUDIT_WATCH_GROUP_NUM, AUDIT_FS_WATCH,
580+
audit_watch_group = fsnotify_obtain_group(AUDIT_FS_WATCH,
581581
&audit_watch_fsnotify_ops);
582582
if (IS_ERR(audit_watch_group)) {
583583
audit_watch_group = NULL;

0 commit comments

Comments
 (0)