History

Merge tag 'fsnotify_for_v5.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs

Pull fsnotify updates from Jan Kara: "This implements the fanotify FAN_DIR_MODIFY event. This event reports the name in a directory under which a change happened and together with the directory filehandle and fstatat() allows reliable and efficient implementation of directory synchronization" * tag 'fsnotify_for_v5.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: fanotify: Fix the checks in fanotify_fsid_equal fanotify: report name info for FAN_DIR_MODIFY event fanotify: record name info for FAN_DIR_MODIFY event fanotify: Drop fanotify_event_has_fid() fanotify: prepare to report both parent and child fid's fanotify: send FAN_DIR_MODIFY event flavor with dir inode and name fanotify: divorce fanotify_path_event and fanotify_fid_event fanotify: Store fanotify handles differently fanotify: Simplify create_fd() fanotify: fix merging marks masks with FAN_ONDIR fanotify: merge duplicate events on parent and child fsnotify: replace inode pointer with an object id fsnotify: simplify arguments passing to fsnotify_parent() fsnotify: use helpers to access data by data_type fsnotify: funnel all dirent events through fsnotify_name() fsnotify: factor helpers fsnotify_dentry() and fsnotify_file() fsnotify: tidy up FS_ and FAN_ constants

Linus Torvalds committed 6 years ago

Commit b6ff1072 parents 74e934b 6def1a112 files · +637 −363Browse files

Showing the changes to include/linux (3 of 12 files). Show all

Unified · Split

3 files
  1. include/linux/fanotify.h +2 −1
  2. include/linux/fsnotify.h +58 −80
  3. include/linux/fsnotify_backend.h +49 −21
include/linux/fanotify.h+2−1
@@ -47,7 +47,8 @@ · 46 unmodified lines
47 * Directory entry modification events - reported only to directory47 * Directory entry modification events - reported only to directory
48 * where entry is modified and not to a watching parent.48 * where entry is modified and not to a watching parent.
49 */49 */
50#define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE)50#define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE | \
51 FAN_DIR_MODIFY)
51 52
52/* Events that can only be reported with data type FSNOTIFY_EVENT_INODE */53/* Events that can only be reported with data type FSNOTIFY_EVENT_INODE */
53#define FANOTIFY_INODE_EVENTS (FANOTIFY_DIRENT_EVENTS | \54#define FANOTIFY_INODE_EVENTS (FANOTIFY_DIRENT_EVENTS | \
include/linux/fsnotify.h+58−80
@@ -18,39 +18,63 @@ · 17 unmodified lines
18#include <linux/bug.h>18#include <linux/bug.h>
19 19
20/*20/*
21 * Notify this @dir inode about a change in the directory entry @dentry.21 * Notify this @dir inode about a change in a child directory entry.
22 * The directory entry may have turned positive or negative or its inode may
23 * have changed (i.e. renamed over).
22 *24 *
23 * Unlike fsnotify_parent(), the event will be reported regardless of the25 * Unlike fsnotify_parent(), the event will be reported regardless of the
24 * FS_EVENT_ON_CHILD mask on the parent inode.26 * FS_EVENT_ON_CHILD mask on the parent inode.
25 */27 */
26static inline int fsnotify_dirent(struct inode *dir, struct dentry *dentry,28static inline void fsnotify_name(struct inode *dir, __u32 mask,
27 __u32 mask)29 struct inode *child,
30 const struct qstr *name, u32 cookie)
28{31{
29 return fsnotify(dir, mask, d_inode(dentry), FSNOTIFY_EVENT_INODE,32 fsnotify(dir, mask, child, FSNOTIFY_EVENT_INODE, name, cookie);
30 &dentry->d_name, 0);33 /*
34 * Send another flavor of the event without child inode data and
35 * without the specific event type (e.g. FS_CREATE|FS_IS_DIR).
36 * The name is relative to the dir inode the event is reported to.
37 */
38 fsnotify(dir, FS_DIR_MODIFY, dir, FSNOTIFY_EVENT_INODE, name, 0);
31}39}
32 40
33/* Notify this dentry's parent about a child's events. */41static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry,
34static inline int fsnotify_parent(const struct path *path,42 __u32 mask)
35 struct dentry *dentry, __u32 mask)
36{43{
37 if (!dentry)44 fsnotify_name(dir, mask, d_inode(dentry), &dentry->d_name, 0);
38 dentry = path->dentry;
39
40 return __fsnotify_parent(path, dentry, mask);
41}45}
42 46
43/*47/*
44 * Simple wrapper to consolidate calls fsnotify_parent()/fsnotify() when48 * Simple wrappers to consolidate calls fsnotify_parent()/fsnotify() when
45 * an event is on a path.49 * an event is on a file/dentry.
46 */50 */
47static inline int fsnotify_path(struct inode *inode, const struct path *path,51static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask)
48 __u32 mask)52{
53 struct inode *inode = d_inode(dentry);
54
55 if (S_ISDIR(inode->i_mode))
56 mask |= FS_ISDIR;
57
58 fsnotify_parent(dentry, mask, inode, FSNOTIFY_EVENT_INODE);
59 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
60}
61
62static inline int fsnotify_file(struct file *file, __u32 mask)
49{63{
50 int ret = fsnotify_parent(path, NULL, mask);64 const struct path *path = &file->f_path;
65 struct inode *inode = file_inode(file);
66 int ret;
67
68 if (file->f_mode & FMODE_NONOTIFY)
69 return 0;
70
71 if (S_ISDIR(inode->i_mode))
72 mask |= FS_ISDIR;
51 73
74 ret = fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH);
52 if (ret)75 if (ret)
53 return ret;76 return ret;
77
54 return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);78 return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
55}79}
56 80
@@ -58,19 +82,16 @@ static inline int fsnotify_path(struct inode *inode, const struct path *path, · 1 unmodified line
58static inline int fsnotify_perm(struct file *file, int mask)82static inline int fsnotify_perm(struct file *file, int mask)
59{83{
60 int ret;84 int ret;
61 const struct path *path = &file->f_path;
62 struct inode *inode = file_inode(file);
63 __u32 fsnotify_mask = 0;85 __u32 fsnotify_mask = 0;
64 86
65 if (file->f_mode & FMODE_NONOTIFY)
66 return 0;
67 if (!(mask & (MAY_READ | MAY_OPEN)))87 if (!(mask & (MAY_READ | MAY_OPEN)))
68 return 0;88 return 0;
89
69 if (mask & MAY_OPEN) {90 if (mask & MAY_OPEN) {
70 fsnotify_mask = FS_OPEN_PERM;91 fsnotify_mask = FS_OPEN_PERM;
71 92
72 if (file->f_flags & __FMODE_EXEC) {93 if (file->f_flags & __FMODE_EXEC) {
73 ret = fsnotify_path(inode, path, FS_OPEN_EXEC_PERM);94 ret = fsnotify_file(file, FS_OPEN_EXEC_PERM);
74 95
75 if (ret)96 if (ret)
76 return ret;97 return ret;
@@ -79,10 +100,7 @@ static inline int fsnotify_perm(struct file *file, int mask) · 2 unmodified lines
79 fsnotify_mask = FS_ACCESS_PERM;100 fsnotify_mask = FS_ACCESS_PERM;
80 }101 }
81 102
82 if (S_ISDIR(inode->i_mode))103 return fsnotify_file(file, fsnotify_mask);
83 fsnotify_mask |= FS_ISDIR;
84
85 return fsnotify_path(inode, path, fsnotify_mask);
86}104}
87 105
88/*106/*
@@ -122,10 +140,8 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, · 33 unmodified lines
122 mask |= FS_ISDIR;140 mask |= FS_ISDIR;
123 }141 }
124 142
125 fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name,143 fsnotify_name(old_dir, old_dir_mask, source, old_name, fs_cookie);
126 fs_cookie);144 fsnotify_name(new_dir, new_dir_mask, source, new_name, fs_cookie);
127 fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE, new_name,
128 fs_cookie);
129 145
130 if (target)146 if (target)
131 fsnotify_link_count(target);147 fsnotify_link_count(target);
@@ -180,12 +196,13 @@ static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) · 48 unmodified lines
180 * Note: We have to pass also the linked inode ptr as some filesystems leave196 * Note: We have to pass also the linked inode ptr as some filesystems leave
181 * new_dentry->d_inode NULL and instantiate inode pointer later197 * new_dentry->d_inode NULL and instantiate inode pointer later
182 */198 */
183static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)199static inline void fsnotify_link(struct inode *dir, struct inode *inode,
200 struct dentry *new_dentry)
184{201{
185 fsnotify_link_count(inode);202 fsnotify_link_count(inode);
186 audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE);203 audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE);
187 204
188 fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, &new_dentry->d_name, 0);205 fsnotify_name(dir, FS_CREATE, inode, &new_dentry->d_name, 0);
189}206}
190 207
191/*208/*
@@ -229,15 +246,7 @@ static inline void fsnotify_rmdir(struct inode *dir, struct dentry *dentry) · 37 unmodified lines
229 */246 */
230static inline void fsnotify_access(struct file *file)247static inline void fsnotify_access(struct file *file)
231{248{
232 const struct path *path = &file->f_path;249 fsnotify_file(file, FS_ACCESS);
233 struct inode *inode = file_inode(file);
234 __u32 mask = FS_ACCESS;
235
236 if (S_ISDIR(inode->i_mode))
237 mask |= FS_ISDIR;
238
239 if (!(file->f_mode & FMODE_NONOTIFY))
240 fsnotify_path(inode, path, mask);
241}250}
242 251
243/*252/*
@@ -245,15 +254,7 @@ static inline void fsnotify_access(struct file *file) · 1 unmodified line
245 */254 */
246static inline void fsnotify_modify(struct file *file)255static inline void fsnotify_modify(struct file *file)
247{256{
248 const struct path *path = &file->f_path;257 fsnotify_file(file, FS_MODIFY);
249 struct inode *inode = file_inode(file);
250 __u32 mask = FS_MODIFY;
251
252 if (S_ISDIR(inode->i_mode))
253 mask |= FS_ISDIR;
254
255 if (!(file->f_mode & FMODE_NONOTIFY))
256 fsnotify_path(inode, path, mask);
257}258}
258 259
259/*260/*
@@ -261,16 +262,12 @@ static inline void fsnotify_modify(struct file *file) · 1 unmodified line
261 */262 */
262static inline void fsnotify_open(struct file *file)263static inline void fsnotify_open(struct file *file)
263{264{
264 const struct path *path = &file->f_path;
265 struct inode *inode = file_inode(file);
266 __u32 mask = FS_OPEN;265 __u32 mask = FS_OPEN;
267 266
268 if (S_ISDIR(inode->i_mode))
269 mask |= FS_ISDIR;
270 if (file->f_flags & __FMODE_EXEC)267 if (file->f_flags & __FMODE_EXEC)
271 mask |= FS_OPEN_EXEC;268 mask |= FS_OPEN_EXEC;
272 269
273 fsnotify_path(inode, path, mask);270 fsnotify_file(file, mask);
274}271}
275 272
276/*273/*
@@ -278,16 +275,10 @@ static inline void fsnotify_open(struct file *file) · 1 unmodified line
278 */275 */
279static inline void fsnotify_close(struct file *file)276static inline void fsnotify_close(struct file *file)
280{277{
281 const struct path *path = &file->f_path;278 __u32 mask = (file->f_mode & FMODE_WRITE) ? FS_CLOSE_WRITE :
282 struct inode *inode = file_inode(file);279 FS_CLOSE_NOWRITE;
283 fmode_t mode = file->f_mode;
284 __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
285 280
286 if (S_ISDIR(inode->i_mode))281 fsnotify_file(file, mask);
287 mask |= FS_ISDIR;
288
289 if (!(file->f_mode & FMODE_NONOTIFY))
290 fsnotify_path(inode, path, mask);
291}282}
292 283
293/*284/*
@@ -295,14 +286,7 @@ static inline void fsnotify_close(struct file *file) · 1 unmodified line
295 */286 */
296static inline void fsnotify_xattr(struct dentry *dentry)287static inline void fsnotify_xattr(struct dentry *dentry)
297{288{
298 struct inode *inode = dentry->d_inode;289 fsnotify_dentry(dentry, FS_ATTRIB);
299 __u32 mask = FS_ATTRIB;
300
301 if (S_ISDIR(inode->i_mode))
302 mask |= FS_ISDIR;
303
304 fsnotify_parent(NULL, dentry, mask);
305 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
306}290}
307 291
308/*292/*
@@ -311,7 +295,6 @@ static inline void fsnotify_xattr(struct dentry *dentry) · 2 unmodified lines
311 */295 */
312static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)296static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
313{297{
314 struct inode *inode = dentry->d_inode;
315 __u32 mask = 0;298 __u32 mask = 0;
316 299
317 if (ia_valid & ATTR_UID)300 if (ia_valid & ATTR_UID)
@@ -332,13 +315,8 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) · 14 unmodified lines
332 if (ia_valid & ATTR_MODE)315 if (ia_valid & ATTR_MODE)
333 mask |= FS_ATTRIB;316 mask |= FS_ATTRIB;
334 317
335 if (mask) {318 if (mask)
336 if (S_ISDIR(inode->i_mode))319 fsnotify_dentry(dentry, mask);
337 mask |= FS_ISDIR;
338
339 fsnotify_parent(NULL, dentry, mask);
340 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
341 }
342}320}
343 321
344#endif /* _LINUX_FS_NOTIFY_H */322#endif /* _LINUX_FS_NOTIFY_H */
include/linux/fsnotify_backend.h+49−21
@@ -47,18 +47,18 @@ · 46 unmodified lines
47#define FS_OPEN_PERM 0x00010000 /* open event in an permission hook */47#define FS_OPEN_PERM 0x00010000 /* open event in an permission hook */
48#define FS_ACCESS_PERM 0x00020000 /* access event in a permissions hook */48#define FS_ACCESS_PERM 0x00020000 /* access event in a permissions hook */
49#define FS_OPEN_EXEC_PERM 0x00040000 /* open/exec event in a permission hook */49#define FS_OPEN_EXEC_PERM 0x00040000 /* open/exec event in a permission hook */
50#define FS_DIR_MODIFY 0x00080000 /* Directory entry was modified */
50 51
51#define FS_EXCL_UNLINK 0x04000000 /* do not send events if object is unlinked */52#define FS_EXCL_UNLINK 0x04000000 /* do not send events if object is unlinked */
52#define FS_ISDIR 0x40000000 /* event occurred against dir */
53#define FS_IN_ONESHOT 0x80000000 /* only send event once */
54
55#define FS_DN_RENAME 0x10000000 /* file renamed */
56#define FS_DN_MULTISHOT 0x20000000 /* dnotify multishot */
57
58/* This inode cares about things that happen to its children. Always set for53/* This inode cares about things that happen to its children. Always set for
59 * dnotify and inotify. */54 * dnotify and inotify. */
60#define FS_EVENT_ON_CHILD 0x0800000055#define FS_EVENT_ON_CHILD 0x08000000
61 56
57#define FS_DN_RENAME 0x10000000 /* file renamed */
58#define FS_DN_MULTISHOT 0x20000000 /* dnotify multishot */
59#define FS_ISDIR 0x40000000 /* event occurred against dir */
60#define FS_IN_ONESHOT 0x80000000 /* only send event once */
61
62#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO)62#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO)
63 63
64/*64/*
@@ -67,7 +67,8 @@ · 2 unmodified lines
67 * The watching parent may get an FS_ATTRIB|FS_EVENT_ON_CHILD event67 * The watching parent may get an FS_ATTRIB|FS_EVENT_ON_CHILD event
68 * when a directory entry inside a child subdir changes.68 * when a directory entry inside a child subdir changes.
69 */69 */
70#define ALL_FSNOTIFY_DIRENT_EVENTS (FS_CREATE | FS_DELETE | FS_MOVE)70#define ALL_FSNOTIFY_DIRENT_EVENTS (FS_CREATE | FS_DELETE | FS_MOVE | \
71 FS_DIR_MODIFY)
71 72
72#define ALL_FSNOTIFY_PERM_EVENTS (FS_OPEN_PERM | FS_ACCESS_PERM | \73#define ALL_FSNOTIFY_PERM_EVENTS (FS_OPEN_PERM | FS_ACCESS_PERM | \
73 FS_OPEN_EXEC_PERM)74 FS_OPEN_EXEC_PERM)
@@ -133,8 +134,7 @@ struct fsnotify_ops { · 59 unmodified lines
133 */134 */
134struct fsnotify_event {135struct fsnotify_event {
135 struct list_head list;136 struct list_head list;
136 /* inode may ONLY be dereferenced during handle_event(). */137 unsigned long objectid; /* identifier for queue merges */
137 struct inode *inode; /* either the inode the event happened to or its parent */
138};138};
139 139
140/*140/*
@@ -213,10 +213,36 @@ struct fsnotify_group { · 72 unmodified lines
213 };213 };
214};214};
215 215
216/* when calling fsnotify tell it if the data is a path or inode */216/* When calling fsnotify tell it if the data is a path or inode */
217#define FSNOTIFY_EVENT_NONE 0217enum fsnotify_data_type {
218#define FSNOTIFY_EVENT_PATH 1218 FSNOTIFY_EVENT_NONE,
219#define FSNOTIFY_EVENT_INODE 2219 FSNOTIFY_EVENT_PATH,
220 FSNOTIFY_EVENT_INODE,
221};
222
223static inline const struct inode *fsnotify_data_inode(const void *data,
224 int data_type)
225{
226 switch (data_type) {
227 case FSNOTIFY_EVENT_INODE:
228 return data;
229 case FSNOTIFY_EVENT_PATH:
230 return d_inode(((const struct path *)data)->dentry);
231 default:
232 return NULL;
233 }
234}
235
236static inline const struct path *fsnotify_data_path(const void *data,
237 int data_type)
238{
239 switch (data_type) {
240 case FSNOTIFY_EVENT_PATH:
241 return data;
242 default:
243 return NULL;
244 }
245}
220 246
221enum fsnotify_obj_type {247enum fsnotify_obj_type {
222 FSNOTIFY_OBJ_TYPE_INODE,248 FSNOTIFY_OBJ_TYPE_INODE,
@@ -351,9 +377,10 @@ struct fsnotify_mark { · 128 unmodified lines
351/* called from the vfs helpers */377/* called from the vfs helpers */
352 378
353/* main fsnotify call to send events */379/* main fsnotify call to send events */
354extern int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,380extern int fsnotify(struct inode *to_tell, __u32 mask, const void *data,
355 const struct qstr *name, u32 cookie);381 int data_type, const struct qstr *name, u32 cookie);
356extern int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask);382extern int fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
383 int data_type);
357extern void __fsnotify_inode_delete(struct inode *inode);384extern void __fsnotify_inode_delete(struct inode *inode);
358extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);385extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);
359extern void fsnotify_sb_delete(struct super_block *sb);386extern void fsnotify_sb_delete(struct super_block *sb);
@@ -500,21 +527,22 @@ extern void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info); · 140 unmodified lines
500extern bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info);527extern bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info);
501 528
502static inline void fsnotify_init_event(struct fsnotify_event *event,529static inline void fsnotify_init_event(struct fsnotify_event *event,
503 struct inode *inode)530 unsigned long objectid)
504{531{
505 INIT_LIST_HEAD(&event->list);532 INIT_LIST_HEAD(&event->list);
506 event->inode = inode;533 event->objectid = objectid;
507}534}
508 535
509#else536#else
510 537
511static inline int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,538static inline int fsnotify(struct inode *to_tell, __u32 mask, const void *data,
512 const struct qstr *name, u32 cookie)539 int data_type, const struct qstr *name, u32 cookie)
513{540{
514 return 0;541 return 0;
515}542}
516 543
517static inline int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask)544static inline int fsnotify_parent(struct dentry *dentry, __u32 mask,
545 const void *data, int data_type)
518{546{
519 return 0;547 return 0;
520}548}