Commit cf71f3cf authored by Eric Paris's avatar Eric Paris

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: default avatarEric Paris <eparis@redhat.com>
parent 9514271c
...@@ -432,8 +432,7 @@ static int __init dnotify_init(void) ...@@ -432,8 +432,7 @@ static int __init dnotify_init(void)
dnotify_struct_cache = KMEM_CACHE(dnotify_struct, SLAB_PANIC); dnotify_struct_cache = KMEM_CACHE(dnotify_struct, SLAB_PANIC);
dnotify_mark_entry_cache = KMEM_CACHE(dnotify_mark_entry, SLAB_PANIC); dnotify_mark_entry_cache = KMEM_CACHE(dnotify_mark_entry, SLAB_PANIC);
dnotify_group = fsnotify_obtain_group(DNOTIFY_GROUP_NUM, dnotify_group = fsnotify_obtain_group(0, &dnotify_fsnotify_ops);
0, &dnotify_fsnotify_ops);
if (IS_ERR(dnotify_group)) if (IS_ERR(dnotify_group))
panic("unable to allocate fsnotify group for dnotify\n"); panic("unable to allocate fsnotify group for dnotify\n");
return 0; return 0;
......
...@@ -77,15 +77,6 @@ void fsnotify_recalc_group_mask(struct fsnotify_group *group) ...@@ -77,15 +77,6 @@ void fsnotify_recalc_group_mask(struct fsnotify_group *group)
fsnotify_recalc_global_mask(); 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 * Final freeing of a group
*/ */
...@@ -170,41 +161,15 @@ void fsnotify_put_group(struct fsnotify_group *group) ...@@ -170,41 +161,15 @@ void fsnotify_put_group(struct fsnotify_group *group)
fsnotify_destroy_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 * 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 * creates a new group and adds it to the global group list. In either case we
* take a reference for the group returned. * 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) const struct fsnotify_ops *ops)
{ {
struct fsnotify_group *group, *tgroup; struct fsnotify_group *group;
/* very low use, simpler locking if we just always alloc */ /* very low use, simpler locking if we just always alloc */
group = kzalloc(sizeof(struct fsnotify_group), GFP_KERNEL); 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,7 +179,6 @@ struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask,
atomic_set(&group->refcnt, 1); atomic_set(&group->refcnt, 1);
group->on_group_list = 0; group->on_group_list = 0;
group->group_num = group_num;
group->mask = mask; group->mask = mask;
mutex_init(&group->notification_mutex); mutex_init(&group->notification_mutex);
...@@ -230,14 +194,6 @@ struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask, ...@@ -230,14 +194,6 @@ struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask,
group->ops = ops; group->ops = ops;
mutex_lock(&fsnotify_grp_mutex); 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 */ /* group not found, add a new one */
list_add_rcu(&group->group_list, &fsnotify_groups); list_add_rcu(&group->group_list, &fsnotify_groups);
......
...@@ -55,12 +55,6 @@ int inotify_max_user_watches __read_mostly; ...@@ -55,12 +55,6 @@ int inotify_max_user_watches __read_mostly;
static struct kmem_cache *inotify_inode_mark_cachep __read_mostly; static struct kmem_cache *inotify_inode_mark_cachep __read_mostly;
struct kmem_cache *event_priv_cachep __read_mostly; struct kmem_cache *event_priv_cachep __read_mostly;
/*
* When inotify registers a new group it increments this and uses that
* value as an offset to set the fsnotify group "name" and priority.
*/
static atomic_t inotify_grp_num;
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
#include <linux/sysctl.h> #include <linux/sysctl.h>
...@@ -714,11 +708,8 @@ retry: ...@@ -714,11 +708,8 @@ retry:
static struct fsnotify_group *inotify_new_group(struct user_struct *user, unsigned int max_events) static struct fsnotify_group *inotify_new_group(struct user_struct *user, unsigned int max_events)
{ {
struct fsnotify_group *group; struct fsnotify_group *group;
unsigned int grp_num;
/* fsnotify_obtain_group took a reference to group, we put this when we kill the file in the end */ group = fsnotify_obtain_group(0, &inotify_fsnotify_ops);
grp_num = (INOTIFY_GROUP_NUM - atomic_inc_return(&inotify_grp_num));
group = fsnotify_obtain_group(grp_num, 0, &inotify_fsnotify_ops);
if (IS_ERR(group)) if (IS_ERR(group))
return group; return group;
......
...@@ -60,12 +60,6 @@ ...@@ -60,12 +60,6 @@
#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO) #define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO)
/* listeners that hard code group numbers near the top */
#define DNOTIFY_GROUP_NUM UINT_MAX
#define AUDIT_WATCH_GROUP_NUM (DNOTIFY_GROUP_NUM-1)
#define AUDIT_TREE_GROUP_NUM (AUDIT_WATCH_GROUP_NUM-1)
#define INOTIFY_GROUP_NUM (AUDIT_TREE_GROUP_NUM-1)
struct fsnotify_group; struct fsnotify_group;
struct fsnotify_event; struct fsnotify_event;
struct fsnotify_mark_entry; struct fsnotify_mark_entry;
...@@ -124,7 +118,6 @@ struct fsnotify_group { ...@@ -124,7 +118,6 @@ struct fsnotify_group {
* closed. * closed.
*/ */
atomic_t refcnt; /* things with interest in this group */ atomic_t refcnt; /* things with interest in this group */
unsigned int group_num; /* simply prevents accidental group collision */
const struct fsnotify_ops *ops; /* how this group handles things */ const struct fsnotify_ops *ops; /* how this group handles things */
...@@ -312,8 +305,7 @@ static inline void __fsnotify_d_instantiate(struct dentry *dentry, struct inode ...@@ -312,8 +305,7 @@ static inline void __fsnotify_d_instantiate(struct dentry *dentry, struct inode
/* must call when a group changes its ->mask */ /* must call when a group changes its ->mask */
extern void fsnotify_recalc_global_mask(void); extern void fsnotify_recalc_global_mask(void);
/* get a reference to an existing or create a new group */ /* get a reference to an existing or create a new group */
extern struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, extern struct fsnotify_group *fsnotify_obtain_group(__u32 mask,
__u32 mask,
const struct fsnotify_ops *ops); const struct fsnotify_ops *ops);
/* run all marks associated with this group and update group->mask */ /* run all marks associated with this group and update group->mask */
extern void fsnotify_recalc_group_mask(struct fsnotify_group *group); extern void fsnotify_recalc_group_mask(struct fsnotify_group *group);
......
...@@ -976,8 +976,7 @@ static int __init audit_tree_init(void) ...@@ -976,8 +976,7 @@ static int __init audit_tree_init(void)
{ {
int i; int i;
audit_tree_group = fsnotify_obtain_group(AUDIT_TREE_GROUP_NUM, audit_tree_group = fsnotify_obtain_group(0, &audit_tree_ops);
0, &audit_tree_ops);
if (IS_ERR(audit_tree_group)) if (IS_ERR(audit_tree_group))
audit_panic("cannot initialize inotify handle for rectree watches"); audit_panic("cannot initialize inotify handle for rectree watches");
......
...@@ -576,7 +576,7 @@ static const struct fsnotify_ops audit_watch_fsnotify_ops = { ...@@ -576,7 +576,7 @@ static const struct fsnotify_ops audit_watch_fsnotify_ops = {
static int __init audit_watch_init(void) static int __init audit_watch_init(void)
{ {
audit_watch_group = fsnotify_obtain_group(AUDIT_WATCH_GROUP_NUM, AUDIT_FS_WATCH, audit_watch_group = fsnotify_obtain_group(AUDIT_FS_WATCH,
&audit_watch_fsnotify_ops); &audit_watch_fsnotify_ops);
if (IS_ERR(audit_watch_group)) { if (IS_ERR(audit_watch_group)) {
audit_watch_group = NULL; audit_watch_group = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment