linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] fsnotify: fsnotify_obtain_group kzalloc cleanup
@ 2009-10-25 20:26 Eric Paris
  2009-10-25 20:27 ` [PATCH 2/5] fsnotify: fsnotify_obtain_group should be fsnotify_alloc_group Eric Paris
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Eric Paris @ 2009-10-25 20:26 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel; +Cc: agruen

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 <eparis@redhat.com>
---

 fs/notify/group.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/fs/notify/group.c b/fs/notify/group.c
index 62fb896..934860e 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;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/5] fsnotify: fsnotify_obtain_group should be fsnotify_alloc_group
  2009-10-25 20:26 [PATCH 1/5] fsnotify: fsnotify_obtain_group kzalloc cleanup Eric Paris
@ 2009-10-25 20:27 ` Eric Paris
  2009-10-25 20:27 ` [PATCH 3/5] fsnotify: rename fsnotify_groups to fsnotify_inode_groups Eric Paris
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Paris @ 2009-10-25 20:27 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel; +Cc: agruen

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 <eparis@redhat.com>
---

 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(-)

diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
index 8c568a0..9781bcc 100644
--- a/fs/notify/dnotify/dnotify.c
+++ b/fs/notify/dnotify/dnotify.c
@@ -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;
diff --git a/fs/notify/group.c b/fs/notify/group.c
index 934860e..1d20d26 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 */
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index 4393043..c0ba6cb 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -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;
 
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 57e503d..7d3c03e 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -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 */
diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c
index d9aab73..f8f3ac3 100644
--- a/kernel/audit_tree.c
+++ b/kernel/audit_tree.c
@@ -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");
 
diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
index 10ec0e2..57898b3 100644
--- a/kernel/audit_watch.c
+++ b/kernel/audit_watch.c
@@ -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");

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/5] fsnotify: rename fsnotify_groups to fsnotify_inode_groups
  2009-10-25 20:26 [PATCH 1/5] fsnotify: fsnotify_obtain_group kzalloc cleanup Eric Paris
  2009-10-25 20:27 ` [PATCH 2/5] fsnotify: fsnotify_obtain_group should be fsnotify_alloc_group Eric Paris
@ 2009-10-25 20:27 ` Eric Paris
  2009-10-25 20:27 ` [PATCH 4/5] fsnotify: initialize the group->num_marks in a better place Eric Paris
  2009-10-25 20:27 ` [PATCH 5/5] fsnotify: add groups to fsnotify_inode_groups when registering inode watch Eric Paris
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Paris @ 2009-10-25 20:27 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel; +Cc: agruen

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 <eparis@redhat.com>
---

 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(-)

diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index d4b0272..30655d1 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -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))
diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h
index 4dc2408..ec5aee4 100644
--- a/fs/notify/fsnotify.h
+++ b/fs/notify/fsnotify.h
@@ -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);
diff --git a/fs/notify/group.c b/fs/notify/group.c
index 1d20d26..73d2c30 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;
 }
 
 /*
@@ -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);
 
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 7d3c03e..5d2854d 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -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 {


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/5] fsnotify: initialize the group->num_marks in a better place
  2009-10-25 20:26 [PATCH 1/5] fsnotify: fsnotify_obtain_group kzalloc cleanup Eric Paris
  2009-10-25 20:27 ` [PATCH 2/5] fsnotify: fsnotify_obtain_group should be fsnotify_alloc_group Eric Paris
  2009-10-25 20:27 ` [PATCH 3/5] fsnotify: rename fsnotify_groups to fsnotify_inode_groups Eric Paris
@ 2009-10-25 20:27 ` Eric Paris
  2009-10-25 20:27 ` [PATCH 5/5] fsnotify: add groups to fsnotify_inode_groups when registering inode watch Eric Paris
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Paris @ 2009-10-25 20:27 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel; +Cc: agruen

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 <eparis@redhat.com>
---

 fs/notify/group.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/notify/group.c b/fs/notify/group.c
index 73d2c30..f8c2f0f 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);
 }
 
@@ -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;
 


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 5/5] fsnotify: add groups to fsnotify_inode_groups when registering inode watch
  2009-10-25 20:26 [PATCH 1/5] fsnotify: fsnotify_obtain_group kzalloc cleanup Eric Paris
                   ` (2 preceding siblings ...)
  2009-10-25 20:27 ` [PATCH 4/5] fsnotify: initialize the group->num_marks in a better place Eric Paris
@ 2009-10-25 20:27 ` Eric Paris
  3 siblings, 0 replies; 5+ messages in thread
From: Eric Paris @ 2009-10-25 20:27 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel; +Cc: agruen

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 <eparis@redhat.com>
---

 fs/notify/fsnotify.h   |    2 ++
 fs/notify/group.c      |   18 ++++++++----------
 fs/notify/inode_mark.c |    7 +++++++
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h
index ec5aee4..5bd2241 100644
--- a/fs/notify/fsnotify.h
+++ b/fs/notify/fsnotify.h
@@ -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);
 
diff --git a/fs/notify/group.c b/fs/notify/group.c
index f8c2f0f..ac74e91 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);
 }
 
 /*
@@ -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();
 
diff --git a/fs/notify/inode_mark.c b/fs/notify/inode_mark.c
index 574c5c6..42b3f39 100644
--- a/fs/notify/inode_mark.c
+++ b/fs/notify/inode_mark.c
@@ -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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-10-25 20:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-25 20:26 [PATCH 1/5] fsnotify: fsnotify_obtain_group kzalloc cleanup Eric Paris
2009-10-25 20:27 ` [PATCH 2/5] fsnotify: fsnotify_obtain_group should be fsnotify_alloc_group Eric Paris
2009-10-25 20:27 ` [PATCH 3/5] fsnotify: rename fsnotify_groups to fsnotify_inode_groups Eric Paris
2009-10-25 20:27 ` [PATCH 4/5] fsnotify: initialize the group->num_marks in a better place Eric Paris
2009-10-25 20:27 ` [PATCH 5/5] fsnotify: add groups to fsnotify_inode_groups when registering inode watch Eric Paris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).