aboutsummaryrefslogtreecommitdiffstats
path: root/fs/notify/group.c
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2009-05-21 17:01:26 -0400
committerEric Paris <eparis@redhat.com>2009-06-11 14:57:53 -0400
commit3be25f49b9d6a97eae9bcb96d3292072b7658bd8 (patch)
tree36f7d96481a47a6bde3c2f961346e940698111e0 /fs/notify/group.c
parentfsnotify: unified filesystem notification backend (diff)
downloadlinux-dev-3be25f49b9d6a97eae9bcb96d3292072b7658bd8.tar.xz
linux-dev-3be25f49b9d6a97eae9bcb96d3292072b7658bd8.zip
fsnotify: add marks to inodes so groups can interpret how to handle those inodes
This patch creates a way for fsnotify groups to attach marks to inodes. These marks have little meaning to the generic fsnotify infrastructure and thus their meaning should be interpreted by the group that attached them to the inode's list. dnotify and inotify will make use of these markings to indicate which inodes are of interest to their respective groups. But this implementation has the useful property that in the future other listeners could actually use the marks for the exact opposite reason, aka to indicate which inodes it had NO interest in. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Al Viro <viro@zeniv.linux.org.uk> Cc: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/notify/group.c')
-rw-r--r--fs/notify/group.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/fs/notify/group.c b/fs/notify/group.c
index c6812953b968..a29d2fa67927 100644
--- a/fs/notify/group.c
+++ b/fs/notify/group.c
@@ -55,6 +55,29 @@ void fsnotify_recalc_global_mask(void)
}
/*
+ * Update the group->mask by running all of the marks associated with this
+ * group and finding the bitwise | of all of the mark->mask. If we change
+ * the group->mask we need to update the global mask of events interesting
+ * to the system.
+ */
+void fsnotify_recalc_group_mask(struct fsnotify_group *group)
+{
+ __u32 mask = 0;
+ __u32 old_mask = group->mask;
+ struct fsnotify_mark_entry *entry;
+
+ spin_lock(&group->mark_lock);
+ list_for_each_entry(entry, &group->mark_entries, g_list)
+ mask |= entry->mask;
+ spin_unlock(&group->mark_lock);
+
+ group->mask = mask;
+
+ if (old_mask != 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
*/
@@ -66,7 +89,7 @@ static void fsnotify_get_group(struct fsnotify_group *group)
/*
* Final freeing of a group
*/
-static void fsnotify_destroy_group(struct fsnotify_group *group)
+void fsnotify_final_destroy_group(struct fsnotify_group *group)
{
if (group->ops->free_group_priv)
group->ops->free_group_priv(group);
@@ -75,6 +98,24 @@ static void fsnotify_destroy_group(struct fsnotify_group *group)
}
/*
+ * Trying to get rid of a group. We need to first get rid of any outstanding
+ * allocations and then free the group. Remember that fsnotify_clear_marks_by_group
+ * could miss marks that are being freed by inode and those marks could still
+ * hold a reference to this group (via group->num_marks) If we get into that
+ * situtation, the fsnotify_final_destroy_group will get called when that final
+ * mark is freed.
+ */
+static void fsnotify_destroy_group(struct fsnotify_group *group)
+{
+ /* clear all inode mark entries for this group */
+ fsnotify_clear_marks_by_group(group);
+
+ /* past the point of no return, matches the initial value of 1 */
+ if (atomic_dec_and_test(&group->num_marks))
+ fsnotify_final_destroy_group(group);
+}
+
+/*
* Remove this group from the global list of groups that will get events
* this can be done even if there are still references and things still using
* this group. This just stops the group from getting new events.
@@ -173,6 +214,10 @@ struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask,
group->group_num = group_num;
group->mask = mask;
+ spin_lock_init(&group->mark_lock);
+ atomic_set(&group->num_marks, 0);
+ INIT_LIST_HEAD(&group->mark_entries);
+
group->ops = ops;
mutex_lock(&fsnotify_grp_mutex);
@@ -188,6 +233,8 @@ struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num, __u32 mask,
/* 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 */
+ atomic_inc(&group->num_marks);
mutex_unlock(&fsnotify_grp_mutex);