aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/file_table.c9
-rw-r--r--fs/notify/fanotify/fanotify.c8
-rw-r--r--fs/notify/fanotify/fanotify_user.c6
-rw-r--r--fs/notify/fsnotify.c12
-rw-r--r--fs/notify/inotify/inotify_fsnotify.c12
-rw-r--r--fs/notify/notification.c33
-rw-r--r--include/linux/fsnotify.h37
-rw-r--r--include/linux/fsnotify_backend.h16
-rw-r--r--kernel/audit_watch.c4
9 files changed, 61 insertions, 76 deletions
diff --git a/fs/file_table.c b/fs/file_table.c
index 2fc3b3c08911..edecd36fed9b 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -230,15 +230,6 @@ static void __fput(struct file *file)
230 might_sleep(); 230 might_sleep();
231 231
232 fsnotify_close(file); 232 fsnotify_close(file);
233
234 /*
235 * fsnotify_create_event may have taken one or more references on this
236 * file. If it did so it left one reference for us to drop to make sure
237 * its calls to fput could not prematurely destroy the file.
238 */
239 if (atomic_long_read(&file->f_count))
240 return fput(file);
241
242 /* 233 /*
243 * The function eventpoll_release() should be the first called 234 * The function eventpoll_release() should be the first called
244 * in the file cleanup chain. 235 * in the file cleanup chain.
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index eb8f73c9c131..756566fe8449 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -17,9 +17,9 @@ static bool should_merge(struct fsnotify_event *old, struct fsnotify_event *new)
17 old->data_type == new->data_type && 17 old->data_type == new->data_type &&
18 old->tgid == new->tgid) { 18 old->tgid == new->tgid) {
19 switch (old->data_type) { 19 switch (old->data_type) {
20 case (FSNOTIFY_EVENT_FILE): 20 case (FSNOTIFY_EVENT_PATH):
21 if ((old->file->f_path.mnt == new->file->f_path.mnt) && 21 if ((old->path.mnt == new->path.mnt) &&
22 (old->file->f_path.dentry == new->file->f_path.dentry)) 22 (old->path.dentry == new->path.dentry))
23 return true; 23 return true;
24 case (FSNOTIFY_EVENT_NONE): 24 case (FSNOTIFY_EVENT_NONE):
25 return true; 25 return true;
@@ -174,7 +174,7 @@ static bool fanotify_should_send_event(struct fsnotify_group *group,
174 return false; 174 return false;
175 175
176 /* if we don't have enough info to send an event to userspace say no */ 176 /* if we don't have enough info to send an event to userspace say no */
177 if (data_type != FSNOTIFY_EVENT_FILE) 177 if (data_type != FSNOTIFY_EVENT_PATH)
178 return false; 178 return false;
179 179
180 if (inode_mark && vfsmnt_mark) { 180 if (inode_mark && vfsmnt_mark) {
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index 25a3b4dfcf61..032b837fcd11 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -65,7 +65,7 @@ static int create_fd(struct fsnotify_group *group, struct fsnotify_event *event)
65 if (client_fd < 0) 65 if (client_fd < 0)
66 return client_fd; 66 return client_fd;
67 67
68 if (event->data_type != FSNOTIFY_EVENT_FILE) { 68 if (event->data_type != FSNOTIFY_EVENT_PATH) {
69 WARN_ON(1); 69 WARN_ON(1);
70 put_unused_fd(client_fd); 70 put_unused_fd(client_fd);
71 return -EINVAL; 71 return -EINVAL;
@@ -75,8 +75,8 @@ static int create_fd(struct fsnotify_group *group, struct fsnotify_event *event)
75 * we need a new file handle for the userspace program so it can read even if it was 75 * we need a new file handle for the userspace program so it can read even if it was
76 * originally opened O_WRONLY. 76 * originally opened O_WRONLY.
77 */ 77 */
78 dentry = dget(event->file->f_path.dentry); 78 dentry = dget(event->path.dentry);
79 mnt = mntget(event->file->f_path.mnt); 79 mnt = mntget(event->path.mnt);
80 /* it's possible this event was an overflow event. in that case dentry and mnt 80 /* it's possible this event was an overflow event. in that case dentry and mnt
81 * are NULL; That's fine, just don't call dentry open */ 81 * are NULL; That's fine, just don't call dentry open */
82 if (dentry && mnt) 82 if (dentry && mnt)
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 4d2a82c1ceb1..3970392b2722 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -84,7 +84,7 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode)
84} 84}
85 85
86/* Notify this dentry's parent about a child's events. */ 86/* Notify this dentry's parent about a child's events. */
87void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask) 87void __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
88{ 88{
89 struct dentry *parent; 89 struct dentry *parent;
90 struct inode *p_inode; 90 struct inode *p_inode;
@@ -92,7 +92,7 @@ void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
92 bool should_update_children = false; 92 bool should_update_children = false;
93 93
94 if (!dentry) 94 if (!dentry)
95 dentry = file->f_path.dentry; 95 dentry = path->dentry;
96 96
97 if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED)) 97 if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED))
98 return; 98 return;
@@ -124,8 +124,8 @@ void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
124 * specifies these are events which came from a child. */ 124 * specifies these are events which came from a child. */
125 mask |= FS_EVENT_ON_CHILD; 125 mask |= FS_EVENT_ON_CHILD;
126 126
127 if (file) 127 if (path)
128 fsnotify(p_inode, mask, file, FSNOTIFY_EVENT_FILE, 128 fsnotify(p_inode, mask, path, FSNOTIFY_EVENT_PATH,
129 dentry->d_name.name, 0); 129 dentry->d_name.name, 0);
130 else 130 else
131 fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE, 131 fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE,
@@ -217,8 +217,8 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
217 /* global tests shouldn't care about events on child only the specific event */ 217 /* global tests shouldn't care about events on child only the specific event */
218 __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD); 218 __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD);
219 219
220 if (data_is == FSNOTIFY_EVENT_FILE) 220 if (data_is == FSNOTIFY_EVENT_PATH)
221 mnt = ((struct file *)data)->f_path.mnt; 221 mnt = ((struct path *)data)->mnt;
222 else 222 else
223 mnt = NULL; 223 mnt = NULL;
224 224
diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
index 5e73eeb2c697..a91b69a6a291 100644
--- a/fs/notify/inotify/inotify_fsnotify.c
+++ b/fs/notify/inotify/inotify_fsnotify.c
@@ -52,9 +52,9 @@ static bool event_compare(struct fsnotify_event *old, struct fsnotify_event *new
52 !strcmp(old->file_name, new->file_name)) 52 !strcmp(old->file_name, new->file_name))
53 return true; 53 return true;
54 break; 54 break;
55 case (FSNOTIFY_EVENT_FILE): 55 case (FSNOTIFY_EVENT_PATH):
56 if ((old->file->f_path.mnt == new->file->f_path.mnt) && 56 if ((old->path.mnt == new->path.mnt) &&
57 (old->file->f_path.dentry == new->file->f_path.dentry)) 57 (old->path.dentry == new->path.dentry))
58 return true; 58 return true;
59 break; 59 break;
60 case (FSNOTIFY_EVENT_NONE): 60 case (FSNOTIFY_EVENT_NONE):
@@ -147,10 +147,10 @@ static bool inotify_should_send_event(struct fsnotify_group *group, struct inode
147 __u32 mask, void *data, int data_type) 147 __u32 mask, void *data, int data_type)
148{ 148{
149 if ((inode_mark->mask & FS_EXCL_UNLINK) && 149 if ((inode_mark->mask & FS_EXCL_UNLINK) &&
150 (data_type == FSNOTIFY_EVENT_FILE)) { 150 (data_type == FSNOTIFY_EVENT_PATH)) {
151 struct file *file = data; 151 struct path *path = data;
152 152
153 if (d_unlinked(file->f_path.dentry)) 153 if (d_unlinked(path->dentry))
154 return false; 154 return false;
155 } 155 }
156 156
diff --git a/fs/notify/notification.c b/fs/notify/notification.c
index d6c435adc7a2..f39260f8f865 100644
--- a/fs/notify/notification.c
+++ b/fs/notify/notification.c
@@ -31,7 +31,6 @@
31 * allocated and used. 31 * allocated and used.
32 */ 32 */
33 33
34#include <linux/file.h>
35#include <linux/fs.h> 34#include <linux/fs.h>
36#include <linux/init.h> 35#include <linux/init.h>
37#include <linux/kernel.h> 36#include <linux/kernel.h>
@@ -90,8 +89,8 @@ void fsnotify_put_event(struct fsnotify_event *event)
90 if (atomic_dec_and_test(&event->refcnt)) { 89 if (atomic_dec_and_test(&event->refcnt)) {
91 pr_debug("%s: event=%p\n", __func__, event); 90 pr_debug("%s: event=%p\n", __func__, event);
92 91
93 if (event->data_type == FSNOTIFY_EVENT_FILE) 92 if (event->data_type == FSNOTIFY_EVENT_PATH)
94 fput(event->file); 93 path_put(&event->path);
95 94
96 BUG_ON(!list_empty(&event->private_data_list)); 95 BUG_ON(!list_empty(&event->private_data_list));
97 96
@@ -376,8 +375,8 @@ struct fsnotify_event *fsnotify_clone_event(struct fsnotify_event *old_event)
376 } 375 }
377 } 376 }
378 event->tgid = get_pid(old_event->tgid); 377 event->tgid = get_pid(old_event->tgid);
379 if (event->data_type == FSNOTIFY_EVENT_FILE) 378 if (event->data_type == FSNOTIFY_EVENT_PATH)
380 get_file(event->file); 379 path_get(&event->path);
381 380
382 return event; 381 return event;
383} 382}
@@ -424,22 +423,11 @@ struct fsnotify_event *fsnotify_create_event(struct inode *to_tell, __u32 mask,
424 event->data_type = data_type; 423 event->data_type = data_type;
425 424
426 switch (data_type) { 425 switch (data_type) {
427 case FSNOTIFY_EVENT_FILE: { 426 case FSNOTIFY_EVENT_PATH: {
428 event->file = data; 427 struct path *path = data;
429 /* 428 event->path.dentry = path->dentry;
430 * if this file is about to disappear hold an extra reference 429 event->path.mnt = path->mnt;
431 * until we return to __fput so we don't have to worry about 430 path_get(&event->path);
432 * future get/put destroying the file under us or generating
433 * additional events. Notice that we change f_mode without
434 * holding f_lock. This is safe since this is the only possible
435 * reference to this object in the kernel (it was about to be
436 * freed, remember?)
437 */
438 if (!atomic_long_read(&event->file->f_count)) {
439 event->file->f_mode |= FMODE_NONOTIFY;
440 get_file(event->file);
441 }
442 get_file(event->file);
443 break; 431 break;
444 } 432 }
445 case FSNOTIFY_EVENT_INODE: 433 case FSNOTIFY_EVENT_INODE:
@@ -447,7 +435,8 @@ struct fsnotify_event *fsnotify_create_event(struct inode *to_tell, __u32 mask,
447 break; 435 break;
448 case FSNOTIFY_EVENT_NONE: 436 case FSNOTIFY_EVENT_NONE:
449 event->inode = NULL; 437 event->inode = NULL;
450 event->file = NULL; 438 event->path.dentry = NULL;
439 event->path.mnt = NULL;
451 break; 440 break;
452 default: 441 default:
453 BUG(); 442 BUG();
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index e4e2204187ee..59d0df43ff9d 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -26,18 +26,19 @@ 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 file *file, struct dentry *dentry, __u32 mask) 29static inline void fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
30{ 30{
31 if (!dentry) 31 if (!dentry)
32 dentry = file->f_path.dentry; 32 dentry = path->dentry;
33 33
34 __fsnotify_parent(file, dentry, mask); 34 __fsnotify_parent(path, 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 inode *inode = file->f_path.dentry->d_inode; 40 struct path *path = &file->f_path;
41 struct inode *inode = path->dentry->d_inode;
41 __u32 fsnotify_mask = 0; 42 __u32 fsnotify_mask = 0;
42 43
43 if (file->f_mode & FMODE_NONOTIFY) 44 if (file->f_mode & FMODE_NONOTIFY)
@@ -51,7 +52,7 @@ static inline int fsnotify_perm(struct file *file, int mask)
51 else 52 else
52 BUG(); 53 BUG();
53 54
54 return fsnotify(inode, fsnotify_mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); 55 return fsnotify(inode, fsnotify_mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
55} 56}
56 57
57/* 58/*
@@ -186,15 +187,16 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
186 */ 187 */
187static inline void fsnotify_access(struct file *file) 188static inline void fsnotify_access(struct file *file)
188{ 189{
189 struct inode *inode = file->f_path.dentry->d_inode; 190 struct path *path = &file->f_path;
191 struct inode *inode = path->dentry->d_inode;
190 __u32 mask = FS_ACCESS; 192 __u32 mask = FS_ACCESS;
191 193
192 if (S_ISDIR(inode->i_mode)) 194 if (S_ISDIR(inode->i_mode))
193 mask |= FS_IN_ISDIR; 195 mask |= FS_IN_ISDIR;
194 196
195 if (!(file->f_mode & FMODE_NONOTIFY)) { 197 if (!(file->f_mode & FMODE_NONOTIFY)) {
196 fsnotify_parent(file, NULL, mask); 198 fsnotify_parent(path, NULL, mask);
197 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); 199 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
198 } 200 }
199} 201}
200 202
@@ -203,15 +205,16 @@ static inline void fsnotify_access(struct file *file)
203 */ 205 */
204static inline void fsnotify_modify(struct file *file) 206static inline void fsnotify_modify(struct file *file)
205{ 207{
206 struct inode *inode = file->f_path.dentry->d_inode; 208 struct path *path = &file->f_path;
209 struct inode *inode = path->dentry->d_inode;
207 __u32 mask = FS_MODIFY; 210 __u32 mask = FS_MODIFY;
208 211
209 if (S_ISDIR(inode->i_mode)) 212 if (S_ISDIR(inode->i_mode))
210 mask |= FS_IN_ISDIR; 213 mask |= FS_IN_ISDIR;
211 214
212 if (!(file->f_mode & FMODE_NONOTIFY)) { 215 if (!(file->f_mode & FMODE_NONOTIFY)) {
213 fsnotify_parent(file, NULL, mask); 216 fsnotify_parent(path, NULL, mask);
214 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); 217 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
215 } 218 }
216} 219}
217 220
@@ -220,15 +223,16 @@ static inline void fsnotify_modify(struct file *file)
220 */ 223 */
221static inline void fsnotify_open(struct file *file) 224static inline void fsnotify_open(struct file *file)
222{ 225{
223 struct inode *inode = file->f_path.dentry->d_inode; 226 struct path *path = &file->f_path;
227 struct inode *inode = path->dentry->d_inode;
224 __u32 mask = FS_OPEN; 228 __u32 mask = FS_OPEN;
225 229
226 if (S_ISDIR(inode->i_mode)) 230 if (S_ISDIR(inode->i_mode))
227 mask |= FS_IN_ISDIR; 231 mask |= FS_IN_ISDIR;
228 232
229 if (!(file->f_mode & FMODE_NONOTIFY)) { 233 if (!(file->f_mode & FMODE_NONOTIFY)) {
230 fsnotify_parent(file, NULL, mask); 234 fsnotify_parent(path, NULL, mask);
231 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); 235 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
232 } 236 }
233} 237}
234 238
@@ -237,6 +241,7 @@ static inline void fsnotify_open(struct file *file)
237 */ 241 */
238static inline void fsnotify_close(struct file *file) 242static inline void fsnotify_close(struct file *file)
239{ 243{
244 struct path *path = &file->f_path;
240 struct inode *inode = file->f_path.dentry->d_inode; 245 struct inode *inode = file->f_path.dentry->d_inode;
241 fmode_t mode = file->f_mode; 246 fmode_t mode = file->f_mode;
242 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE; 247 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
@@ -245,8 +250,8 @@ static inline void fsnotify_close(struct file *file)
245 mask |= FS_IN_ISDIR; 250 mask |= FS_IN_ISDIR;
246 251
247 if (!(file->f_mode & FMODE_NONOTIFY)) { 252 if (!(file->f_mode & FMODE_NONOTIFY)) {
248 fsnotify_parent(file, NULL, mask); 253 fsnotify_parent(path, NULL, mask);
249 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); 254 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
250 } 255 }
251} 256}
252 257
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 9bbfd7204b04..ed36fb57c426 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -203,20 +203,20 @@ struct fsnotify_event {
203 /* to_tell may ONLY be dereferenced during handle_event(). */ 203 /* to_tell may ONLY be dereferenced during handle_event(). */
204 struct inode *to_tell; /* either the inode the event happened to or its parent */ 204 struct inode *to_tell; /* either the inode the event happened to or its parent */
205 /* 205 /*
206 * depending on the event type we should have either a file or inode 206 * depending on the event type we should have either a path or inode
207 * We hold a reference on file, but NOT on inode. Since we have the ref on 207 * We hold a reference on path, but NOT on inode. Since we have the ref on
208 * the file, it may be dereferenced at any point during this object's 208 * the path, it may be dereferenced at any point during this object's
209 * lifetime. That reference is dropped when this object's refcnt hits 209 * lifetime. That reference is dropped when this object's refcnt hits
210 * 0. If this event contains an inode instead of a file, the inode may 210 * 0. If this event contains an inode instead of a path, the inode may
211 * ONLY be used during handle_event(). 211 * ONLY be used during handle_event().
212 */ 212 */
213 union { 213 union {
214 struct file *file; 214 struct path path;
215 struct inode *inode; 215 struct inode *inode;
216 }; 216 };
217/* when calling fsnotify tell it if the data is a path or inode */ 217/* when calling fsnotify tell it if the data is a path or inode */
218#define FSNOTIFY_EVENT_NONE 0 218#define FSNOTIFY_EVENT_NONE 0
219#define FSNOTIFY_EVENT_FILE 1 219#define FSNOTIFY_EVENT_PATH 1
220#define FSNOTIFY_EVENT_INODE 2 220#define FSNOTIFY_EVENT_INODE 2
221 int data_type; /* which of the above union we have */ 221 int data_type; /* which of the above union we have */
222 atomic_t refcnt; /* how many groups still are using/need to send this event */ 222 atomic_t refcnt; /* how many groups still are using/need to send this event */
@@ -293,7 +293,7 @@ struct fsnotify_mark {
293/* main fsnotify call to send events */ 293/* main fsnotify call to send events */
294extern int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, 294extern int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
295 const unsigned char *name, u32 cookie); 295 const unsigned char *name, u32 cookie);
296extern void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask); 296extern void __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask);
297extern void __fsnotify_inode_delete(struct inode *inode); 297extern void __fsnotify_inode_delete(struct inode *inode);
298extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt); 298extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);
299extern u32 fsnotify_get_cookie(void); 299extern u32 fsnotify_get_cookie(void);
@@ -422,7 +422,7 @@ static inline int fsnotify(struct inode *to_tell, __u32 mask, void *data, int da
422 return 0; 422 return 0;
423} 423}
424 424
425static inline void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask) 425static inline void __fsnotify_parent(struct path *path, struct dentry *dentry, __u32 mask)
426{} 426{}
427 427
428static inline void __fsnotify_inode_delete(struct inode *inode) 428static inline void __fsnotify_inode_delete(struct inode *inode)
diff --git a/kernel/audit_watch.c b/kernel/audit_watch.c
index 6bf2306be7d6..f0c9b2e7542d 100644
--- a/kernel/audit_watch.c
+++ b/kernel/audit_watch.c
@@ -526,8 +526,8 @@ static int audit_watch_handle_event(struct fsnotify_group *group,
526 BUG_ON(group != audit_watch_group); 526 BUG_ON(group != audit_watch_group);
527 527
528 switch (event->data_type) { 528 switch (event->data_type) {
529 case (FSNOTIFY_EVENT_FILE): 529 case (FSNOTIFY_EVENT_PATH):
530 inode = event->file->f_path.dentry->d_inode; 530 inode = event->path.dentry->d_inode;
531 break; 531 break;
532 case (FSNOTIFY_EVENT_INODE): 532 case (FSNOTIFY_EVENT_INODE):
533 inode = event->inode; 533 inode = event->inode;