aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2010-07-28 10:18:37 -0400
committerEric Paris <eparis@redhat.com>2010-07-28 10:18:51 -0400
commit3bcf3860a4ff9bbc522820b4b765e65e4deceb3e (patch)
tree1e235af133559062c6fdee840ff9698f1dee26a6 /include
parentf70ab54cc6c3907b0727ba332b3976f80f3846d0 (diff)
fsnotify: store struct file not struct path
Al explains that calling dentry_open() with a mnt/dentry pair is only garunteed to be safe if they are already used in an open struct file. To make sure this is the case don't store and use a struct path in fsnotify, always use a struct file. Signed-off-by: Eric Paris <eparis@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/linux/fsnotify.h37
-rw-r--r--include/linux/fsnotify_backend.h16
2 files changed, 24 insertions, 29 deletions
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index 59d0df43ff9d..e4e2204187ee 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -26,19 +26,18 @@ static inline void fsnotify_d_instantiate(struct dentry *dentry,
26} 26}
27 27
28/* Notify this dentry's parent about a child's events. */ 28/* Notify this dentry's parent about a child's events. */
29static inline void fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask) 29static inline void fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
30{ 30{
31 if (!dentry) 31 if (!dentry)
32 dentry = path->dentry; 32 dentry = file->f_path.dentry;
33 33
34 __fsnotify_parent(path, dentry, mask); 34 __fsnotify_parent(file, dentry, mask);
35} 35}
36 36
37/* simple call site for access decisions */ 37/* simple call site for access decisions */
38static inline int fsnotify_perm(struct file *file, int mask) 38static inline int fsnotify_perm(struct file *file, int mask)
39{ 39{
40 struct path *path = &file->f_path; 40 struct inode *inode = file->f_path.dentry->d_inode;
41 struct inode *inode = path->dentry->d_inode;
42 __u32 fsnotify_mask = 0; 41 __u32 fsnotify_mask = 0;
43 42
44 if (file->f_mode & FMODE_NONOTIFY) 43 if (file->f_mode & FMODE_NONOTIFY)
@@ -52,7 +51,7 @@ static inline int fsnotify_perm(struct file *file, int mask)
52 else 51 else
53 BUG(); 52 BUG();
54 53
55 return fsnotify(inode, fsnotify_mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); 54 return fsnotify(inode, fsnotify_mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
56} 55}
57 56
58/* 57/*
@@ -187,16 +186,15 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
187 */ 186 */
188static inline void fsnotify_access(struct file *file) 187static inline void fsnotify_access(struct file *file)
189{ 188{
190 struct path *path = &file->f_path; 189 struct inode *inode = file->f_path.dentry->d_inode;
191 struct inode *inode = path->dentry->d_inode;
192 __u32 mask = FS_ACCESS; 190 __u32 mask = FS_ACCESS;
193 191
194 if (S_ISDIR(inode->i_mode)) 192 if (S_ISDIR(inode->i_mode))
195 mask |= FS_IN_ISDIR; 193 mask |= FS_IN_ISDIR;
196 194
197 if (!(file->f_mode & FMODE_NONOTIFY)) { 195 if (!(file->f_mode & FMODE_NONOTIFY)) {
198 fsnotify_parent(path, NULL, mask); 196 fsnotify_parent(file, NULL, mask);
199 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); 197 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
200 } 198 }
201} 199}
202 200
@@ -205,16 +203,15 @@ static inline void fsnotify_access(struct file *file)
205 */ 203 */
206static inline void fsnotify_modify(struct file *file) 204static inline void fsnotify_modify(struct file *file)
207{ 205{
208 struct path *path = &file->f_path; 206 struct inode *inode = file->f_path.dentry->d_inode;
209 struct inode *inode = path->dentry->d_inode;
210 __u32 mask = FS_MODIFY; 207 __u32 mask = FS_MODIFY;
211 208
212 if (S_ISDIR(inode->i_mode)) 209 if (S_ISDIR(inode->i_mode))
213 mask |= FS_IN_ISDIR; 210 mask |= FS_IN_ISDIR;
214 211
215 if (!(file->f_mode & FMODE_NONOTIFY)) { 212 if (!(file->f_mode & FMODE_NONOTIFY)) {
216 fsnotify_parent(path, NULL, mask); 213 fsnotify_parent(file, NULL, mask);
217 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); 214 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
218 } 215 }
219} 216}
220 217
@@ -223,16 +220,15 @@ static inline void fsnotify_modify(struct file *file)
223 */ 220 */
224static inline void fsnotify_open(struct file *file) 221static inline void fsnotify_open(struct file *file)
225{ 222{
226 struct path *path = &file->f_path; 223 struct inode *inode = file->f_path.dentry->d_inode;
227 struct inode *inode = path->dentry->d_inode;
228 __u32 mask = FS_OPEN; 224 __u32 mask = FS_OPEN;
229 225
230 if (S_ISDIR(inode->i_mode)) 226 if (S_ISDIR(inode->i_mode))
231 mask |= FS_IN_ISDIR; 227 mask |= FS_IN_ISDIR;
232 228
233 if (!(file->f_mode & FMODE_NONOTIFY)) { 229 if (!(file->f_mode & FMODE_NONOTIFY)) {
234 fsnotify_parent(path, NULL, mask); 230 fsnotify_parent(file, NULL, mask);
235 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); 231 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
236 } 232 }
237} 233}
238 234
@@ -241,7 +237,6 @@ static inline void fsnotify_open(struct file *file)
241 */ 237 */
242static inline void fsnotify_close(struct file *file) 238static inline void fsnotify_close(struct file *file)
243{ 239{
244 struct path *path = &file->f_path;
245 struct inode *inode = file->f_path.dentry->d_inode; 240 struct inode *inode = file->f_path.dentry->d_inode;
246 fmode_t mode = file->f_mode; 241 fmode_t mode = file->f_mode;
247 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE; 242 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
@@ -250,8 +245,8 @@ static inline void fsnotify_close(struct file *file)
250 mask |= FS_IN_ISDIR; 245 mask |= FS_IN_ISDIR;
251 246
252 if (!(file->f_mode & FMODE_NONOTIFY)) { 247 if (!(file->f_mode & FMODE_NONOTIFY)) {
253 fsnotify_parent(path, NULL, mask); 248 fsnotify_parent(file, NULL, mask);
254 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0); 249 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
255 } 250 }
256} 251}
257 252
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 564b5ea4a831..3410d388163e 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -223,20 +223,20 @@ struct fsnotify_event {
223 /* to_tell may ONLY be dereferenced during handle_event(). */ 223 /* to_tell may ONLY be dereferenced during handle_event(). */
224 struct inode *to_tell; /* either the inode the event happened to or its parent */ 224 struct inode *to_tell; /* either the inode the event happened to or its parent */
225 /* 225 /*
226 * depending on the event type we should have either a path or inode 226 * depending on the event type we should have either a file or inode
227 * We hold a reference on path, but NOT on inode. Since we have the ref on 227 * We hold a reference on file, but NOT on inode. Since we have the ref on
228 * the path, it may be dereferenced at any point during this object's 228 * the file, it may be dereferenced at any point during this object's
229 * lifetime. That reference is dropped when this object's refcnt hits 229 * lifetime. That reference is dropped when this object's refcnt hits
230 * 0. If this event contains an inode instead of a path, the inode may 230 * 0. If this event contains an inode instead of a file, the inode may
231 * ONLY be used during handle_event(). 231 * ONLY be used during handle_event().
232 */ 232 */
233 union { 233 union {
234 struct path path; 234 struct file *file;
235 struct inode *inode; 235 struct inode *inode;
236 }; 236 };
237/* when calling fsnotify tell it if the data is a path or inode */ 237/* when calling fsnotify tell it if the data is a path or inode */
238#define FSNOTIFY_EVENT_NONE 0 238#define FSNOTIFY_EVENT_NONE 0
239#define FSNOTIFY_EVENT_PATH 1 239#define FSNOTIFY_EVENT_FILE 1
240#define FSNOTIFY_EVENT_INODE 2 240#define FSNOTIFY_EVENT_INODE 2
241 int data_type; /* which of the above union we have */ 241 int data_type; /* which of the above union we have */
242 atomic_t refcnt; /* how many groups still are using/need to send this event */ 242 atomic_t refcnt; /* how many groups still are using/need to send this event */
@@ -311,7 +311,7 @@ struct fsnotify_mark {
311/* main fsnotify call to send events */ 311/* main fsnotify call to send events */
312extern int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, 312extern int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
313 const unsigned char *name, u32 cookie); 313 const unsigned char *name, u32 cookie);
314extern void __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask); 314extern void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask);
315extern void __fsnotify_inode_delete(struct inode *inode); 315extern void __fsnotify_inode_delete(struct inode *inode);
316extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt); 316extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);
317extern u32 fsnotify_get_cookie(void); 317extern u32 fsnotify_get_cookie(void);
@@ -444,7 +444,7 @@ static inline int fsnotify(struct inode *to_tell, __u32 mask, void *data, int da
444 return 0; 444 return 0;
445} 445}
446 446
447static inline void __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask) 447static inline void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
448{} 448{}
449 449
450static inline void __fsnotify_inode_delete(struct inode *inode) 450static inline void __fsnotify_inode_delete(struct inode *inode)