aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-06-11 17:22:55 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-06-11 17:22:55 -0400
commit3bb66d7f8cc31537a3170c9bb82b38e538b984c5 (patch)
treee7174a8e9b805e056c3b0e510789a611ce4eeb1c /include
parent512626a04e72aca60effe111fa0333ed0b195d21 (diff)
parenta092ee20fd33d2df0990dcbf2235afc181612818 (diff)
Merge branch 'for-linus' of git://git.infradead.org/users/eparis/notify
* 'for-linus' of git://git.infradead.org/users/eparis/notify: fsnotify: allow groups to set freeing_mark to null inotify/dnotify: should_send_event shouldn't match on FS_EVENT_ON_CHILD dnotify: do not bother to lock entry->lock when reading mask dnotify: do not use ?true:false when assigning to a bool fsnotify: move events should indicate the event was on a child inotify: reimplement inotify using fsnotify fsnotify: handle filesystem unmounts with fsnotify marks fsnotify: fsnotify marks on inodes pin them in core fsnotify: allow groups to add private data to events fsnotify: add correlations between events fsnotify: include pathnames with entries when possible fsnotify: generic notification queue and waitq dnotify: reimplement dnotify using fsnotify fsnotify: parent event notification fsnotify: add marks to inodes so groups can interpret how to handle those inodes fsnotify: unified filesystem notification backend
Diffstat (limited to 'include')
-rw-r--r--include/linux/dcache.h4
-rw-r--r--include/linux/dnotify.h29
-rw-r--r--include/linux/fs.h6
-rw-r--r--include/linux/fsnotify.h199
-rw-r--r--include/linux/fsnotify_backend.h387
5 files changed, 521 insertions, 104 deletions
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index 15156364d196..97978004338d 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -180,10 +180,12 @@ d_iput: no no no yes
180#define DCACHE_REFERENCED 0x0008 /* Recently used, don't discard. */ 180#define DCACHE_REFERENCED 0x0008 /* Recently used, don't discard. */
181#define DCACHE_UNHASHED 0x0010 181#define DCACHE_UNHASHED 0x0010
182 182
183#define DCACHE_INOTIFY_PARENT_WATCHED 0x0020 /* Parent inode is watched */ 183#define DCACHE_INOTIFY_PARENT_WATCHED 0x0020 /* Parent inode is watched by inotify */
184 184
185#define DCACHE_COOKIE 0x0040 /* For use by dcookie subsystem */ 185#define DCACHE_COOKIE 0x0040 /* For use by dcookie subsystem */
186 186
187#define DCACHE_FSNOTIFY_PARENT_WATCHED 0x0080 /* Parent inode is watched by some fsnotify listener */
188
187extern spinlock_t dcache_lock; 189extern spinlock_t dcache_lock;
188extern seqlock_t rename_lock; 190extern seqlock_t rename_lock;
189 191
diff --git a/include/linux/dnotify.h b/include/linux/dnotify.h
index 102a902b4396..ecc06286226d 100644
--- a/include/linux/dnotify.h
+++ b/include/linux/dnotify.h
@@ -10,7 +10,7 @@
10 10
11struct dnotify_struct { 11struct dnotify_struct {
12 struct dnotify_struct * dn_next; 12 struct dnotify_struct * dn_next;
13 unsigned long dn_mask; 13 __u32 dn_mask;
14 int dn_fd; 14 int dn_fd;
15 struct file * dn_filp; 15 struct file * dn_filp;
16 fl_owner_t dn_owner; 16 fl_owner_t dn_owner;
@@ -21,23 +21,18 @@ struct dnotify_struct {
21 21
22#ifdef CONFIG_DNOTIFY 22#ifdef CONFIG_DNOTIFY
23 23
24extern void __inode_dir_notify(struct inode *, unsigned long); 24#define DNOTIFY_ALL_EVENTS (FS_DELETE | FS_DELETE_CHILD |\
25 FS_MODIFY | FS_MODIFY_CHILD |\
26 FS_ACCESS | FS_ACCESS_CHILD |\
27 FS_ATTRIB | FS_ATTRIB_CHILD |\
28 FS_CREATE | FS_DN_RENAME |\
29 FS_MOVED_FROM | FS_MOVED_TO)
30
25extern void dnotify_flush(struct file *, fl_owner_t); 31extern void dnotify_flush(struct file *, fl_owner_t);
26extern int fcntl_dirnotify(int, struct file *, unsigned long); 32extern int fcntl_dirnotify(int, struct file *, unsigned long);
27extern void dnotify_parent(struct dentry *, unsigned long);
28
29static inline void inode_dir_notify(struct inode *inode, unsigned long event)
30{
31 if (inode->i_dnotify_mask & (event))
32 __inode_dir_notify(inode, event);
33}
34 33
35#else 34#else
36 35
37static inline void __inode_dir_notify(struct inode *inode, unsigned long event)
38{
39}
40
41static inline void dnotify_flush(struct file *filp, fl_owner_t id) 36static inline void dnotify_flush(struct file *filp, fl_owner_t id)
42{ 37{
43} 38}
@@ -47,14 +42,6 @@ static inline int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
47 return -EINVAL; 42 return -EINVAL;
48} 43}
49 44
50static inline void dnotify_parent(struct dentry *dentry, unsigned long event)
51{
52}
53
54static inline void inode_dir_notify(struct inode *inode, unsigned long event)
55{
56}
57
58#endif /* CONFIG_DNOTIFY */ 45#endif /* CONFIG_DNOTIFY */
59 46
60#endif /* __KERNEL __ */ 47#endif /* __KERNEL __ */
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 83d6b4397245..323b5ce474c1 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -755,9 +755,9 @@ struct inode {
755 755
756 __u32 i_generation; 756 __u32 i_generation;
757 757
758#ifdef CONFIG_DNOTIFY 758#ifdef CONFIG_FSNOTIFY
759 unsigned long i_dnotify_mask; /* Directory notify events */ 759 __u32 i_fsnotify_mask; /* all events this inode cares about */
760 struct dnotify_struct *i_dnotify; /* for directory notifications */ 760 struct hlist_head i_fsnotify_mark_entries; /* fsnotify mark entries */
761#endif 761#endif
762 762
763#ifdef CONFIG_INOTIFY 763#ifdef CONFIG_INOTIFY
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index 00fbd5b245c9..936f9aa8bb97 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -13,6 +13,7 @@
13 13
14#include <linux/dnotify.h> 14#include <linux/dnotify.h>
15#include <linux/inotify.h> 15#include <linux/inotify.h>
16#include <linux/fsnotify_backend.h>
16#include <linux/audit.h> 17#include <linux/audit.h>
17 18
18/* 19/*
@@ -22,19 +23,45 @@
22static inline void fsnotify_d_instantiate(struct dentry *entry, 23static inline void fsnotify_d_instantiate(struct dentry *entry,
23 struct inode *inode) 24 struct inode *inode)
24{ 25{
26 __fsnotify_d_instantiate(entry, inode);
27
25 inotify_d_instantiate(entry, inode); 28 inotify_d_instantiate(entry, inode);
26} 29}
27 30
31/* Notify this dentry's parent about a child's events. */
32static inline void fsnotify_parent(struct dentry *dentry, __u32 mask)
33{
34 __fsnotify_parent(dentry, mask);
35
36 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
37}
38
28/* 39/*
29 * fsnotify_d_move - entry has been moved 40 * fsnotify_d_move - entry has been moved
30 * Called with dcache_lock and entry->d_lock held. 41 * Called with dcache_lock and entry->d_lock held.
31 */ 42 */
32static inline void fsnotify_d_move(struct dentry *entry) 43static inline void fsnotify_d_move(struct dentry *entry)
33{ 44{
45 /*
46 * On move we need to update entry->d_flags to indicate if the new parent
47 * cares about events from this entry.
48 */
49 __fsnotify_update_dcache_flags(entry);
50
34 inotify_d_move(entry); 51 inotify_d_move(entry);
35} 52}
36 53
37/* 54/*
55 * fsnotify_link_count - inode's link count changed
56 */
57static inline void fsnotify_link_count(struct inode *inode)
58{
59 inotify_inode_queue_event(inode, IN_ATTRIB, 0, NULL, NULL);
60
61 fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
62}
63
64/*
38 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir 65 * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
39 */ 66 */
40static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, 67static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
@@ -42,42 +69,62 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
42 int isdir, struct inode *target, struct dentry *moved) 69 int isdir, struct inode *target, struct dentry *moved)
43{ 70{
44 struct inode *source = moved->d_inode; 71 struct inode *source = moved->d_inode;
45 u32 cookie = inotify_get_cookie(); 72 u32 in_cookie = inotify_get_cookie();
73 u32 fs_cookie = fsnotify_get_cookie();
74 __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM);
75 __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO);
46 76
47 if (old_dir == new_dir) 77 if (old_dir == new_dir)
48 inode_dir_notify(old_dir, DN_RENAME); 78 old_dir_mask |= FS_DN_RENAME;
49 else {
50 inode_dir_notify(old_dir, DN_DELETE);
51 inode_dir_notify(new_dir, DN_CREATE);
52 }
53 79
54 if (isdir) 80 if (isdir) {
55 isdir = IN_ISDIR; 81 isdir = IN_ISDIR;
56 inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir,cookie,old_name, 82 old_dir_mask |= FS_IN_ISDIR;
83 new_dir_mask |= FS_IN_ISDIR;
84 }
85
86 inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir, in_cookie, old_name,
57 source); 87 source);
58 inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, cookie, new_name, 88 inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, in_cookie, new_name,
59 source); 89 source);
60 90
91 fsnotify(old_dir, old_dir_mask, old_dir, FSNOTIFY_EVENT_INODE, old_name, fs_cookie);
92 fsnotify(new_dir, new_dir_mask, new_dir, FSNOTIFY_EVENT_INODE, new_name, fs_cookie);
93
61 if (target) { 94 if (target) {
62 inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL, NULL); 95 inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL, NULL);
63 inotify_inode_is_dead(target); 96 inotify_inode_is_dead(target);
97
98 /* this is really a link_count change not a removal */
99 fsnotify_link_count(target);
64 } 100 }
65 101
66 if (source) { 102 if (source) {
67 inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL, NULL); 103 inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL, NULL);
104 fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
68 } 105 }
69 audit_inode_child(new_name, moved, new_dir); 106 audit_inode_child(new_name, moved, new_dir);
70} 107}
71 108
72/* 109/*
110 * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed
111 */
112static inline void fsnotify_inode_delete(struct inode *inode)
113{
114 __fsnotify_inode_delete(inode);
115}
116
117/*
73 * fsnotify_nameremove - a filename was removed from a directory 118 * fsnotify_nameremove - a filename was removed from a directory
74 */ 119 */
75static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) 120static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
76{ 121{
122 __u32 mask = FS_DELETE;
123
77 if (isdir) 124 if (isdir)
78 isdir = IN_ISDIR; 125 mask |= FS_IN_ISDIR;
79 dnotify_parent(dentry, DN_DELETE); 126
80 inotify_dentry_parent_queue_event(dentry, IN_DELETE|isdir, 0, dentry->d_name.name); 127 fsnotify_parent(dentry, mask);
81} 128}
82 129
83/* 130/*
@@ -87,14 +134,9 @@ static inline void fsnotify_inoderemove(struct inode *inode)
87{ 134{
88 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL, NULL); 135 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL, NULL);
89 inotify_inode_is_dead(inode); 136 inotify_inode_is_dead(inode);
90}
91 137
92/* 138 fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
93 * fsnotify_link_count - inode's link count changed 139 __fsnotify_inode_delete(inode);
94 */
95static inline void fsnotify_link_count(struct inode *inode)
96{
97 inotify_inode_queue_event(inode, IN_ATTRIB, 0, NULL, NULL);
98} 140}
99 141
100/* 142/*
@@ -102,10 +144,11 @@ static inline void fsnotify_link_count(struct inode *inode)
102 */ 144 */
103static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) 145static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
104{ 146{
105 inode_dir_notify(inode, DN_CREATE);
106 inotify_inode_queue_event(inode, IN_CREATE, 0, dentry->d_name.name, 147 inotify_inode_queue_event(inode, IN_CREATE, 0, dentry->d_name.name,
107 dentry->d_inode); 148 dentry->d_inode);
108 audit_inode_child(dentry->d_name.name, dentry, inode); 149 audit_inode_child(dentry->d_name.name, dentry, inode);
150
151 fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
109} 152}
110 153
111/* 154/*
@@ -115,11 +158,12 @@ static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
115 */ 158 */
116static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry) 159static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
117{ 160{
118 inode_dir_notify(dir, DN_CREATE);
119 inotify_inode_queue_event(dir, IN_CREATE, 0, new_dentry->d_name.name, 161 inotify_inode_queue_event(dir, IN_CREATE, 0, new_dentry->d_name.name,
120 inode); 162 inode);
121 fsnotify_link_count(inode); 163 fsnotify_link_count(inode);
122 audit_inode_child(new_dentry->d_name.name, new_dentry, dir); 164 audit_inode_child(new_dentry->d_name.name, new_dentry, dir);
165
166 fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0);
123} 167}
124 168
125/* 169/*
@@ -127,10 +171,13 @@ static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct
127 */ 171 */
128static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) 172static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
129{ 173{
130 inode_dir_notify(inode, DN_CREATE); 174 __u32 mask = (FS_CREATE | FS_IN_ISDIR);
131 inotify_inode_queue_event(inode, IN_CREATE | IN_ISDIR, 0, 175 struct inode *d_inode = dentry->d_inode;
132 dentry->d_name.name, dentry->d_inode); 176
177 inotify_inode_queue_event(inode, mask, 0, dentry->d_name.name, d_inode);
133 audit_inode_child(dentry->d_name.name, dentry, inode); 178 audit_inode_child(dentry->d_name.name, dentry, inode);
179
180 fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
134} 181}
135 182
136/* 183/*
@@ -139,14 +186,15 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
139static inline void fsnotify_access(struct dentry *dentry) 186static inline void fsnotify_access(struct dentry *dentry)
140{ 187{
141 struct inode *inode = dentry->d_inode; 188 struct inode *inode = dentry->d_inode;
142 u32 mask = IN_ACCESS; 189 __u32 mask = FS_ACCESS;
143 190
144 if (S_ISDIR(inode->i_mode)) 191 if (S_ISDIR(inode->i_mode))
145 mask |= IN_ISDIR; 192 mask |= FS_IN_ISDIR;
146 193
147 dnotify_parent(dentry, DN_ACCESS);
148 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
149 inotify_inode_queue_event(inode, mask, 0, NULL, NULL); 194 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
195
196 fsnotify_parent(dentry, mask);
197 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
150} 198}
151 199
152/* 200/*
@@ -155,14 +203,15 @@ static inline void fsnotify_access(struct dentry *dentry)
155static inline void fsnotify_modify(struct dentry *dentry) 203static inline void fsnotify_modify(struct dentry *dentry)
156{ 204{
157 struct inode *inode = dentry->d_inode; 205 struct inode *inode = dentry->d_inode;
158 u32 mask = IN_MODIFY; 206 __u32 mask = FS_MODIFY;
159 207
160 if (S_ISDIR(inode->i_mode)) 208 if (S_ISDIR(inode->i_mode))
161 mask |= IN_ISDIR; 209 mask |= FS_IN_ISDIR;
162 210
163 dnotify_parent(dentry, DN_MODIFY);
164 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
165 inotify_inode_queue_event(inode, mask, 0, NULL, NULL); 211 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
212
213 fsnotify_parent(dentry, mask);
214 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
166} 215}
167 216
168/* 217/*
@@ -171,13 +220,15 @@ static inline void fsnotify_modify(struct dentry *dentry)
171static inline void fsnotify_open(struct dentry *dentry) 220static inline void fsnotify_open(struct dentry *dentry)
172{ 221{
173 struct inode *inode = dentry->d_inode; 222 struct inode *inode = dentry->d_inode;
174 u32 mask = IN_OPEN; 223 __u32 mask = FS_OPEN;
175 224
176 if (S_ISDIR(inode->i_mode)) 225 if (S_ISDIR(inode->i_mode))
177 mask |= IN_ISDIR; 226 mask |= FS_IN_ISDIR;
178 227
179 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
180 inotify_inode_queue_event(inode, mask, 0, NULL, NULL); 228 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
229
230 fsnotify_parent(dentry, mask);
231 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
181} 232}
182 233
183/* 234/*
@@ -187,15 +238,16 @@ static inline void fsnotify_close(struct file *file)
187{ 238{
188 struct dentry *dentry = file->f_path.dentry; 239 struct dentry *dentry = file->f_path.dentry;
189 struct inode *inode = dentry->d_inode; 240 struct inode *inode = dentry->d_inode;
190 const char *name = dentry->d_name.name;
191 fmode_t mode = file->f_mode; 241 fmode_t mode = file->f_mode;
192 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE; 242 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
193 243
194 if (S_ISDIR(inode->i_mode)) 244 if (S_ISDIR(inode->i_mode))
195 mask |= IN_ISDIR; 245 mask |= FS_IN_ISDIR;
196 246
197 inotify_dentry_parent_queue_event(dentry, mask, 0, name);
198 inotify_inode_queue_event(inode, mask, 0, NULL, NULL); 247 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
248
249 fsnotify_parent(dentry, mask);
250 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
199} 251}
200 252
201/* 253/*
@@ -204,13 +256,15 @@ static inline void fsnotify_close(struct file *file)
204static inline void fsnotify_xattr(struct dentry *dentry) 256static inline void fsnotify_xattr(struct dentry *dentry)
205{ 257{
206 struct inode *inode = dentry->d_inode; 258 struct inode *inode = dentry->d_inode;
207 u32 mask = IN_ATTRIB; 259 __u32 mask = FS_ATTRIB;
208 260
209 if (S_ISDIR(inode->i_mode)) 261 if (S_ISDIR(inode->i_mode))
210 mask |= IN_ISDIR; 262 mask |= FS_IN_ISDIR;
211 263
212 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
213 inotify_inode_queue_event(inode, mask, 0, NULL, NULL); 264 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
265
266 fsnotify_parent(dentry, mask);
267 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
214} 268}
215 269
216/* 270/*
@@ -220,50 +274,37 @@ static inline void fsnotify_xattr(struct dentry *dentry)
220static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) 274static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
221{ 275{
222 struct inode *inode = dentry->d_inode; 276 struct inode *inode = dentry->d_inode;
223 int dn_mask = 0; 277 __u32 mask = 0;
224 u32 in_mask = 0; 278
279 if (ia_valid & ATTR_UID)
280 mask |= FS_ATTRIB;
281 if (ia_valid & ATTR_GID)
282 mask |= FS_ATTRIB;
283 if (ia_valid & ATTR_SIZE)
284 mask |= FS_MODIFY;
225 285
226 if (ia_valid & ATTR_UID) {
227 in_mask |= IN_ATTRIB;
228 dn_mask |= DN_ATTRIB;
229 }
230 if (ia_valid & ATTR_GID) {
231 in_mask |= IN_ATTRIB;
232 dn_mask |= DN_ATTRIB;
233 }
234 if (ia_valid & ATTR_SIZE) {
235 in_mask |= IN_MODIFY;
236 dn_mask |= DN_MODIFY;
237 }
238 /* both times implies a utime(s) call */ 286 /* both times implies a utime(s) call */
239 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) 287 if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
240 { 288 mask |= FS_ATTRIB;
241 in_mask |= IN_ATTRIB; 289 else if (ia_valid & ATTR_ATIME)
242 dn_mask |= DN_ATTRIB; 290 mask |= FS_ACCESS;
243 } else if (ia_valid & ATTR_ATIME) { 291 else if (ia_valid & ATTR_MTIME)
244 in_mask |= IN_ACCESS; 292 mask |= FS_MODIFY;
245 dn_mask |= DN_ACCESS; 293
246 } else if (ia_valid & ATTR_MTIME) { 294 if (ia_valid & ATTR_MODE)
247 in_mask |= IN_MODIFY; 295 mask |= FS_ATTRIB;
248 dn_mask |= DN_MODIFY;
249 }
250 if (ia_valid & ATTR_MODE) {
251 in_mask |= IN_ATTRIB;
252 dn_mask |= DN_ATTRIB;
253 }
254 296
255 if (dn_mask) 297 if (mask) {
256 dnotify_parent(dentry, dn_mask);
257 if (in_mask) {
258 if (S_ISDIR(inode->i_mode)) 298 if (S_ISDIR(inode->i_mode))
259 in_mask |= IN_ISDIR; 299 mask |= FS_IN_ISDIR;
260 inotify_inode_queue_event(inode, in_mask, 0, NULL, NULL); 300 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
261 inotify_dentry_parent_queue_event(dentry, in_mask, 0, 301
262 dentry->d_name.name); 302 fsnotify_parent(dentry, mask);
303 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
263 } 304 }
264} 305}
265 306
266#ifdef CONFIG_INOTIFY /* inotify helpers */ 307#if defined(CONFIG_INOTIFY) || defined(CONFIG_FSNOTIFY) /* notify helpers */
267 308
268/* 309/*
269 * fsnotify_oldname_init - save off the old filename before we change it 310 * fsnotify_oldname_init - save off the old filename before we change it
@@ -281,7 +322,7 @@ static inline void fsnotify_oldname_free(const char *old_name)
281 kfree(old_name); 322 kfree(old_name);
282} 323}
283 324
284#else /* CONFIG_INOTIFY */ 325#else /* CONFIG_INOTIFY || CONFIG_FSNOTIFY */
285 326
286static inline const char *fsnotify_oldname_init(const char *name) 327static inline const char *fsnotify_oldname_init(const char *name)
287{ 328{
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
new file mode 100644
index 000000000000..44848aa830dc
--- /dev/null
+++ b/include/linux/fsnotify_backend.h
@@ -0,0 +1,387 @@
1/*
2 * Filesystem access notification for Linux
3 *
4 * Copyright (C) 2008 Red Hat, Inc., Eric Paris <eparis@redhat.com>
5 */
6
7#ifndef __LINUX_FSNOTIFY_BACKEND_H
8#define __LINUX_FSNOTIFY_BACKEND_H
9
10#ifdef __KERNEL__
11
12#include <linux/idr.h> /* inotify uses this */
13#include <linux/fs.h> /* struct inode */
14#include <linux/list.h>
15#include <linux/path.h> /* struct path */
16#include <linux/spinlock.h>
17#include <linux/types.h>
18
19#include <asm/atomic.h>
20
21/*
22 * IN_* from inotfy.h lines up EXACTLY with FS_*, this is so we can easily
23 * convert between them. dnotify only needs conversion at watch creation
24 * so no perf loss there. fanotify isn't defined yet, so it can use the
25 * wholes if it needs more events.
26 */
27#define FS_ACCESS 0x00000001 /* File was accessed */
28#define FS_MODIFY 0x00000002 /* File was modified */
29#define FS_ATTRIB 0x00000004 /* Metadata changed */
30#define FS_CLOSE_WRITE 0x00000008 /* Writtable file was closed */
31#define FS_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */
32#define FS_OPEN 0x00000020 /* File was opened */
33#define FS_MOVED_FROM 0x00000040 /* File was moved from X */
34#define FS_MOVED_TO 0x00000080 /* File was moved to Y */
35#define FS_CREATE 0x00000100 /* Subfile was created */
36#define FS_DELETE 0x00000200 /* Subfile was deleted */
37#define FS_DELETE_SELF 0x00000400 /* Self was deleted */
38#define FS_MOVE_SELF 0x00000800 /* Self was moved */
39
40#define FS_UNMOUNT 0x00002000 /* inode on umount fs */
41#define FS_Q_OVERFLOW 0x00004000 /* Event queued overflowed */
42#define FS_IN_IGNORED 0x00008000 /* last inotify event here */
43
44#define FS_IN_ISDIR 0x40000000 /* event occurred against dir */
45#define FS_IN_ONESHOT 0x80000000 /* only send event once */
46
47#define FS_DN_RENAME 0x10000000 /* file renamed */
48#define FS_DN_MULTISHOT 0x20000000 /* dnotify multishot */
49
50/* This inode cares about things that happen to its children. Always set for
51 * dnotify and inotify. */
52#define FS_EVENT_ON_CHILD 0x08000000
53
54/* This is a list of all events that may get sent to a parernt based on fs event
55 * happening to inodes inside that directory */
56#define FS_EVENTS_POSS_ON_CHILD (FS_ACCESS | FS_MODIFY | FS_ATTRIB |\
57 FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | FS_OPEN |\
58 FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE |\
59 FS_DELETE)
60
61/* listeners that hard code group numbers near the top */
62#define DNOTIFY_GROUP_NUM UINT_MAX
63#define INOTIFY_GROUP_NUM (DNOTIFY_GROUP_NUM-1)
64
65struct fsnotify_group;
66struct fsnotify_event;
67struct fsnotify_mark_entry;
68struct fsnotify_event_private_data;
69
70/*
71 * Each group much define these ops. The fsnotify infrastructure will call
72 * these operations for each relevant group.
73 *
74 * should_send_event - given a group, inode, and mask this function determines
75 * if the group is interested in this event.
76 * handle_event - main call for a group to handle an fs event
77 * free_group_priv - called when a group refcnt hits 0 to clean up the private union
78 * freeing-mark - this means that a mark has been flagged to die when everything
79 * finishes using it. The function is supplied with what must be a
80 * valid group and inode to use to clean up.
81 */
82struct fsnotify_ops {
83 bool (*should_send_event)(struct fsnotify_group *group, struct inode *inode, __u32 mask);
84 int (*handle_event)(struct fsnotify_group *group, struct fsnotify_event *event);
85 void (*free_group_priv)(struct fsnotify_group *group);
86 void (*freeing_mark)(struct fsnotify_mark_entry *entry, struct fsnotify_group *group);
87 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
88};
89
90/*
91 * A group is a "thing" that wants to receive notification about filesystem
92 * events. The mask holds the subset of event types this group cares about.
93 * refcnt on a group is up to the implementor and at any moment if it goes 0
94 * everything will be cleaned up.
95 */
96struct fsnotify_group {
97 /*
98 * global list of all groups receiving events from fsnotify.
99 * anchored by fsnotify_groups and protected by either fsnotify_grp_mutex
100 * or fsnotify_grp_srcu depending on write vs read.
101 */
102 struct list_head group_list;
103
104 /*
105 * Defines all of the event types in which this group is interested.
106 * This mask is a bitwise OR of the FS_* events from above. Each time
107 * this mask changes for a group (if it changes) the correct functions
108 * must be called to update the global structures which indicate global
109 * interest in event types.
110 */
111 __u32 mask;
112
113 /*
114 * How the refcnt is used is up to each group. When the refcnt hits 0
115 * fsnotify will clean up all of the resources associated with this group.
116 * As an example, the dnotify group will always have a refcnt=1 and that
117 * will never change. Inotify, on the other hand, has a group per
118 * inotify_init() and the refcnt will hit 0 only when that fd has been
119 * closed.
120 */
121 atomic_t refcnt; /* things with interest in this group */
122 unsigned int group_num; /* simply prevents accidental group collision */
123
124 const struct fsnotify_ops *ops; /* how this group handles things */
125
126 /* needed to send notification to userspace */
127 struct mutex notification_mutex; /* protect the notification_list */
128 struct list_head notification_list; /* list of event_holder this group needs to send to userspace */
129 wait_queue_head_t notification_waitq; /* read() on the notification file blocks on this waitq */
130 unsigned int q_len; /* events on the queue */
131 unsigned int max_events; /* maximum events allowed on the list */
132
133 /* stores all fastapth entries assoc with this group so they can be cleaned on unregister */
134 spinlock_t mark_lock; /* protect mark_entries list */
135 atomic_t num_marks; /* 1 for each mark entry and 1 for not being
136 * past the point of no return when freeing
137 * a group */
138 struct list_head mark_entries; /* all inode mark entries for this group */
139
140 /* prevents double list_del of group_list. protected by global fsnotify_grp_mutex */
141 bool on_group_list;
142
143 /* groups can define private fields here or use the void *private */
144 union {
145 void *private;
146#ifdef CONFIG_INOTIFY_USER
147 struct inotify_group_private_data {
148 spinlock_t idr_lock;
149 struct idr idr;
150 u32 last_wd;
151 struct fasync_struct *fa; /* async notification */
152 struct user_struct *user;
153 } inotify_data;
154#endif
155 };
156};
157
158/*
159 * A single event can be queued in multiple group->notification_lists.
160 *
161 * each group->notification_list will point to an event_holder which in turns points
162 * to the actual event that needs to be sent to userspace.
163 *
164 * Seemed cheaper to create a refcnt'd event and a small holder for every group
165 * than create a different event for every group
166 *
167 */
168struct fsnotify_event_holder {
169 struct fsnotify_event *event;
170 struct list_head event_list;
171};
172
173/*
174 * Inotify needs to tack data onto an event. This struct lets us later find the
175 * correct private data of the correct group.
176 */
177struct fsnotify_event_private_data {
178 struct fsnotify_group *group;
179 struct list_head event_list;
180};
181
182/*
183 * all of the information about the original object we want to now send to
184 * a group. If you want to carry more info from the accessing task to the
185 * listener this structure is where you need to be adding fields.
186 */
187struct fsnotify_event {
188 /*
189 * If we create an event we are also likely going to need a holder
190 * to link to a group. So embed one holder in the event. Means only
191 * one allocation for the common case where we only have one group
192 */
193 struct fsnotify_event_holder holder;
194 spinlock_t lock; /* protection for the associated event_holder and private_list */
195 /* to_tell may ONLY be dereferenced during handle_event(). */
196 struct inode *to_tell; /* either the inode the event happened to or its parent */
197 /*
198 * depending on the event type we should have either a path or inode
199 * We hold a reference on path, but NOT on inode. Since we have the ref on
200 * the path, it may be dereferenced at any point during this object's
201 * lifetime. That reference is dropped when this object's refcnt hits
202 * 0. If this event contains an inode instead of a path, the inode may
203 * ONLY be used during handle_event().
204 */
205 union {
206 struct path path;
207 struct inode *inode;
208 };
209/* when calling fsnotify tell it if the data is a path or inode */
210#define FSNOTIFY_EVENT_NONE 0
211#define FSNOTIFY_EVENT_PATH 1
212#define FSNOTIFY_EVENT_INODE 2
213#define FSNOTIFY_EVENT_FILE 3
214 int data_type; /* which of the above union we have */
215 atomic_t refcnt; /* how many groups still are using/need to send this event */
216 __u32 mask; /* the type of access, bitwise OR for FS_* event types */
217
218 u32 sync_cookie; /* used to corrolate events, namely inotify mv events */
219 char *file_name;
220 size_t name_len;
221
222 struct list_head private_data_list; /* groups can store private data here */
223};
224
225/*
226 * a mark is simply an entry attached to an in core inode which allows an
227 * fsnotify listener to indicate they are either no longer interested in events
228 * of a type matching mask or only interested in those events.
229 *
230 * these are flushed when an inode is evicted from core and may be flushed
231 * when the inode is modified (as seen by fsnotify_access). Some fsnotify users
232 * (such as dnotify) will flush these when the open fd is closed and not at
233 * inode eviction or modification.
234 */
235struct fsnotify_mark_entry {
236 __u32 mask; /* mask this mark entry is for */
237 /* we hold ref for each i_list and g_list. also one ref for each 'thing'
238 * in kernel that found and may be using this mark. */
239 atomic_t refcnt; /* active things looking at this mark */
240 struct inode *inode; /* inode this entry is associated with */
241 struct fsnotify_group *group; /* group this mark entry is for */
242 struct hlist_node i_list; /* list of mark_entries by inode->i_fsnotify_mark_entries */
243 struct list_head g_list; /* list of mark_entries by group->i_fsnotify_mark_entries */
244 spinlock_t lock; /* protect group, inode, and killme */
245 struct list_head free_i_list; /* tmp list used when freeing this mark */
246 struct list_head free_g_list; /* tmp list used when freeing this mark */
247 void (*free_mark)(struct fsnotify_mark_entry *entry); /* called on final put+free */
248};
249
250#ifdef CONFIG_FSNOTIFY
251
252/* called from the vfs helpers */
253
254/* main fsnotify call to send events */
255extern void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
256 const char *name, u32 cookie);
257extern void __fsnotify_parent(struct dentry *dentry, __u32 mask);
258extern void __fsnotify_inode_delete(struct inode *inode);
259extern u32 fsnotify_get_cookie(void);
260
261static inline int fsnotify_inode_watches_children(struct inode *inode)
262{
263 /* FS_EVENT_ON_CHILD is set if the inode may care */
264 if (!(inode->i_fsnotify_mask & FS_EVENT_ON_CHILD))
265 return 0;
266 /* this inode might care about child events, does it care about the
267 * specific set of events that can happen on a child? */
268 return inode->i_fsnotify_mask & FS_EVENTS_POSS_ON_CHILD;
269}
270
271/*
272 * Update the dentry with a flag indicating the interest of its parent to receive
273 * filesystem events when those events happens to this dentry->d_inode.
274 */
275static inline void __fsnotify_update_dcache_flags(struct dentry *dentry)
276{
277 struct dentry *parent;
278
279 assert_spin_locked(&dcache_lock);
280 assert_spin_locked(&dentry->d_lock);
281
282 parent = dentry->d_parent;
283 if (fsnotify_inode_watches_children(parent->d_inode))
284 dentry->d_flags |= DCACHE_FSNOTIFY_PARENT_WATCHED;
285 else
286 dentry->d_flags &= ~DCACHE_FSNOTIFY_PARENT_WATCHED;
287}
288
289/*
290 * fsnotify_d_instantiate - instantiate a dentry for inode
291 * Called with dcache_lock held.
292 */
293static inline void __fsnotify_d_instantiate(struct dentry *dentry, struct inode *inode)
294{
295 if (!inode)
296 return;
297
298 assert_spin_locked(&dcache_lock);
299
300 spin_lock(&dentry->d_lock);
301 __fsnotify_update_dcache_flags(dentry);
302 spin_unlock(&dentry->d_lock);
303}
304
305/* called from fsnotify listeners, such as fanotify or dnotify */
306
307/* must call when a group changes its ->mask */
308extern void fsnotify_recalc_global_mask(void);
309/* get a reference to an existing or create a new group */
310extern struct fsnotify_group *fsnotify_obtain_group(unsigned int group_num,
311 __u32 mask,
312 const struct fsnotify_ops *ops);
313/* run all marks associated with this group and update group->mask */
314extern void fsnotify_recalc_group_mask(struct fsnotify_group *group);
315/* drop reference on a group from fsnotify_obtain_group */
316extern void fsnotify_put_group(struct fsnotify_group *group);
317
318/* take a reference to an event */
319extern void fsnotify_get_event(struct fsnotify_event *event);
320extern void fsnotify_put_event(struct fsnotify_event *event);
321/* find private data previously attached to an event and unlink it */
322extern struct fsnotify_event_private_data *fsnotify_remove_priv_from_event(struct fsnotify_group *group,
323 struct fsnotify_event *event);
324
325/* attach the event to the group notification queue */
326extern int fsnotify_add_notify_event(struct fsnotify_group *group, struct fsnotify_event *event,
327 struct fsnotify_event_private_data *priv);
328/* true if the group notification queue is empty */
329extern bool fsnotify_notify_queue_is_empty(struct fsnotify_group *group);
330/* return, but do not dequeue the first event on the notification queue */
331extern struct fsnotify_event *fsnotify_peek_notify_event(struct fsnotify_group *group);
332/* return AND dequeue the first event on the notification queue */
333extern struct fsnotify_event *fsnotify_remove_notify_event(struct fsnotify_group *group);
334
335/* functions used to manipulate the marks attached to inodes */
336
337/* run all marks associated with an inode and update inode->i_fsnotify_mask */
338extern void fsnotify_recalc_inode_mask(struct inode *inode);
339extern void fsnotify_init_mark(struct fsnotify_mark_entry *entry, void (*free_mark)(struct fsnotify_mark_entry *entry));
340/* find (and take a reference) to a mark associated with group and inode */
341extern struct fsnotify_mark_entry *fsnotify_find_mark_entry(struct fsnotify_group *group, struct inode *inode);
342/* attach the mark to both the group and the inode */
343extern int fsnotify_add_mark(struct fsnotify_mark_entry *entry, struct fsnotify_group *group, struct inode *inode);
344/* given a mark, flag it to be freed when all references are dropped */
345extern void fsnotify_destroy_mark_by_entry(struct fsnotify_mark_entry *entry);
346/* run all the marks in a group, and flag them to be freed */
347extern void fsnotify_clear_marks_by_group(struct fsnotify_group *group);
348extern void fsnotify_get_mark(struct fsnotify_mark_entry *entry);
349extern void fsnotify_put_mark(struct fsnotify_mark_entry *entry);
350extern void fsnotify_unmount_inodes(struct list_head *list);
351
352/* put here because inotify does some weird stuff when destroying watches */
353extern struct fsnotify_event *fsnotify_create_event(struct inode *to_tell, __u32 mask,
354 void *data, int data_is, const char *name,
355 u32 cookie);
356
357#else
358
359static inline void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
360 const char *name, u32 cookie)
361{}
362
363static inline void __fsnotify_parent(struct dentry *dentry, __u32 mask)
364{}
365
366static inline void __fsnotify_inode_delete(struct inode *inode)
367{}
368
369static inline void __fsnotify_update_dcache_flags(struct dentry *dentry)
370{}
371
372static inline void __fsnotify_d_instantiate(struct dentry *dentry, struct inode *inode)
373{}
374
375static inline u32 fsnotify_get_cookie(void)
376{
377 return 0;
378}
379
380static inline void fsnotify_unmount_inodes(struct list_head *list)
381{}
382
383#endif /* CONFIG_FSNOTIFY */
384
385#endif /* __KERNEL __ */
386
387#endif /* __LINUX_FSNOTIFY_BACKEND_H */