linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Paris <eparis@redhat.com>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: agruen@suse.de
Subject: [PATCH 5/5] fsnotify: add groups to fsnotify_inode_groups when registering inode watch
Date: Sun, 25 Oct 2009 16:27:20 -0400	[thread overview]
Message-ID: <20091025202719.11501.63937.stgit@paris.rdu.redhat.com> (raw)
In-Reply-To: <20091025202655.11501.70437.stgit@paris.rdu.redhat.com>

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


      parent reply	other threads:[~2009-10-25 20:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Eric Paris [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091025202719.11501.63937.stgit@paris.rdu.redhat.com \
    --to=eparis@redhat.com \
    --cc=agruen@suse.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).