aboutsummaryrefslogtreecommitdiffstats
path: root/fs/notify
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2009-05-21 17:01:29 -0400
committerEric Paris <eparis@redhat.com>2009-06-11 14:57:53 -0400
commitc28f7e56e9d95fb531dc3be8df2e7f52bee76d21 (patch)
treeefce13ed8c4f5b312ef0b77950489d52ef5a039a /fs/notify
parent3be25f49b9d6a97eae9bcb96d3292072b7658bd8 (diff)
fsnotify: parent event notification
inotify and dnotify both use a similar parent notification mechanism. We add a generic parent notification mechanism to fsnotify for both of these to use. This new machanism also adds the dentry flag optimization which exists for inotify to dnotify. 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')
-rw-r--r--fs/notify/fsnotify.c91
-rw-r--r--fs/notify/fsnotify.h5
-rw-r--r--fs/notify/inode_mark.c17
3 files changed, 113 insertions, 0 deletions
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index d5654629c659..7fc760067a62 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -35,6 +35,97 @@ void __fsnotify_inode_delete(struct inode *inode)
35EXPORT_SYMBOL_GPL(__fsnotify_inode_delete); 35EXPORT_SYMBOL_GPL(__fsnotify_inode_delete);
36 36
37/* 37/*
38 * Given an inode, first check if we care what happens to our children. Inotify
39 * and dnotify both tell their parents about events. If we care about any event
40 * on a child we run all of our children and set a dentry flag saying that the
41 * parent cares. Thus when an event happens on a child it can quickly tell if
42 * if there is a need to find a parent and send the event to the parent.
43 */
44void __fsnotify_update_child_dentry_flags(struct inode *inode)
45{
46 struct dentry *alias;
47 int watched;
48
49 if (!S_ISDIR(inode->i_mode))
50 return;
51
52 /* determine if the children should tell inode about their events */
53 watched = fsnotify_inode_watches_children(inode);
54
55 spin_lock(&dcache_lock);
56 /* run all of the dentries associated with this inode. Since this is a
57 * directory, there damn well better only be one item on this list */
58 list_for_each_entry(alias, &inode->i_dentry, d_alias) {
59 struct dentry *child;
60
61 /* run all of the children of the original inode and fix their
62 * d_flags to indicate parental interest (their parent is the
63 * original inode) */
64 list_for_each_entry(child, &alias->d_subdirs, d_u.d_child) {
65 if (!child->d_inode)
66 continue;
67
68 spin_lock(&child->d_lock);
69 if (watched)
70 child->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED;
71 else
72 child->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED;
73 spin_unlock(&child->d_lock);
74 }
75 }
76 spin_unlock(&dcache_lock);
77}
78
79/* Notify this dentry's parent about a child's events. */
80void __fsnotify_parent(struct dentry *dentry, __u32 mask)
81{
82 struct dentry *parent;
83 struct inode *p_inode;
84 bool send = false;
85 bool should_update_children = false;
86
87 if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED))
88 return;
89
90 spin_lock(&dentry->d_lock);
91 parent = dentry->d_parent;
92 p_inode = parent->d_inode;
93
94 if (fsnotify_inode_watches_children(p_inode)) {
95 if (p_inode->i_fsnotify_mask & mask) {
96 dget(parent);
97 send = true;
98 }
99 } else {
100 /*
101 * The parent doesn't care about events on it's children but
102 * at least one child thought it did. We need to run all the
103 * children and update their d_flags to let them know p_inode
104 * doesn't care about them any more.
105 */
106 dget(parent);
107 should_update_children = true;
108 }
109
110 spin_unlock(&dentry->d_lock);
111
112 if (send) {
113 /* we are notifying a parent so come up with the new mask which
114 * specifies these are events which came from a child. */
115 mask |= FS_EVENT_ON_CHILD;
116
117 fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE);
118 dput(parent);
119 }
120
121 if (unlikely(should_update_children)) {
122 __fsnotify_update_child_dentry_flags(p_inode);
123 dput(parent);
124 }
125}
126EXPORT_SYMBOL_GPL(__fsnotify_parent);
127
128/*
38 * This is the main call to fsnotify. The VFS calls into hook specific functions 129 * This is the main call to fsnotify. The VFS calls into hook specific functions
39 * in linux/fsnotify.h. Those functions then in turn call here. Here will call 130 * in linux/fsnotify.h. Those functions then in turn call here. Here will call
40 * out to all of the registered fsnotify_group. Those groups can then use the 131 * out to all of the registered fsnotify_group. Those groups can then use the
diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h
index 8ebcbe893c91..83b8ec0a8ec2 100644
--- a/fs/notify/fsnotify.h
+++ b/fs/notify/fsnotify.h
@@ -17,4 +17,9 @@ extern __u32 fsnotify_mask;
17extern void fsnotify_final_destroy_group(struct fsnotify_group *group); 17extern void fsnotify_final_destroy_group(struct fsnotify_group *group);
18/* run the list of all marks associated with inode and flag them to be freed */ 18/* run the list of all marks associated with inode and flag them to be freed */
19extern void fsnotify_clear_marks_by_inode(struct inode *inode); 19extern void fsnotify_clear_marks_by_inode(struct inode *inode);
20/*
21 * update the dentry->d_flags of all of inode's children to indicate if inode cares
22 * about events that happen to its children.
23 */
24extern void __fsnotify_update_child_dentry_flags(struct inode *inode);
20#endif /* __FS_NOTIFY_FSNOTIFY_H_ */ 25#endif /* __FS_NOTIFY_FSNOTIFY_H_ */
diff --git a/fs/notify/inode_mark.c b/fs/notify/inode_mark.c
index cdc154146974..a39534845b28 100644
--- a/fs/notify/inode_mark.c
+++ b/fs/notify/inode_mark.c
@@ -131,6 +131,8 @@ void fsnotify_recalc_inode_mask(struct inode *inode)
131 spin_lock(&inode->i_lock); 131 spin_lock(&inode->i_lock);
132 fsnotify_recalc_inode_mask_locked(inode); 132 fsnotify_recalc_inode_mask_locked(inode);
133 spin_unlock(&inode->i_lock); 133 spin_unlock(&inode->i_lock);
134
135 __fsnotify_update_child_dentry_flags(inode);
134} 136}
135 137
136/* 138/*
@@ -190,6 +192,19 @@ void fsnotify_destroy_mark_by_entry(struct fsnotify_mark_entry *entry)
190 group->ops->freeing_mark(entry, group); 192 group->ops->freeing_mark(entry, group);
191 193
192 /* 194 /*
195 * __fsnotify_update_child_dentry_flags(inode);
196 *
197 * I really want to call that, but we can't, we have no idea if the inode
198 * still exists the second we drop the entry->lock.
199 *
200 * The next time an event arrive to this inode from one of it's children
201 * __fsnotify_parent will see that the inode doesn't care about it's
202 * children and will update all of these flags then. So really this
203 * is just a lazy update (and could be a perf win...)
204 */
205
206
207 /*
193 * it's possible that this group tried to destroy itself, but this 208 * it's possible that this group tried to destroy itself, but this
194 * this mark was simultaneously being freed by inode. If that's the 209 * this mark was simultaneously being freed by inode. If that's the
195 * case, we finish freeing the group here. 210 * case, we finish freeing the group here.
@@ -323,6 +338,8 @@ int fsnotify_add_mark(struct fsnotify_mark_entry *entry,
323 if (lentry) { 338 if (lentry) {
324 ret = -EEXIST; 339 ret = -EEXIST;
325 fsnotify_put_mark(lentry); 340 fsnotify_put_mark(lentry);
341 } else {
342 __fsnotify_update_child_dentry_flags(inode);
326 } 343 }
327 344
328 return ret; 345 return ret;