History

fsnotify(): switch to passing const struct qstr * for file_name

Note that in fnsotify_move() and fsnotify_link() we are guaranteed that dentry->d_name won't change during the fsnotify() evaluation (by having the parent directory locked exclusive), so we don't need to fetch dentry->d_name.name in the callers. In fsnotify_dirent() the same stability of dentry->d_name is also true, but it's a bit more convoluted - there is one callchain (devpts_pty_new() -> fsnotify_create() -> fsnotify_dirent()) where the parent is _not_ locked, but on devpts ->d_name of everything is unchanging; it has neither explicit nor implicit renames.

Al Viro committed 7 years ago

Commit 25b229d1 parent f4ec3a34 files · +15 −13Browse files

Unified · Split

4 files
  1. fs/kernfs/file.c +4 −2
  2. fs/notify/fsnotify.c +4 −4
  3. include/linux/fsnotify.h +5 −5
  4. include/linux/fsnotify_backend.h +2 −2
fs/kernfs/file.c+4−2
@@ -885,6 +885,7 @@ repeat: · 884 unmodified lines
885885 list_for_each_entry(info, &kernfs_root(kn)->supers, node) {
886886 struct kernfs_node *parent;
887887 struct inode *inode;
888+ struct qstr name;
888889
889890 /*
890891 * We want fsnotify_modify() on @kn but as the
@@ -896,6 +897,7 @@ repeat: · 5 unmodified lines
896897 if (!inode)
897898 continue;
898899
900+ name = (struct qstr)QSTR_INIT(kn->name, strlen(kn->name));
899901 parent = kernfs_get_parent(kn);
900902 if (parent) {
901903 struct inode *p_inode;
@@ -903,7 +905,7 @@ repeat: · 1 unmodified line
903905 p_inode = ilookup(info->sb, parent->id.ino);
904906 if (p_inode) {
905907 fsnotify(p_inode, FS_MODIFY | FS_EVENT_ON_CHILD,
906− inode, FSNOTIFY_EVENT_INODE, kn->name, 0);
908+ inode, FSNOTIFY_EVENT_INODE, &name, 0);
907909 iput(p_inode);
908910 }
909911
@@ -911,7 +913,7 @@ repeat: · 1 unmodified line
911913 }
912914
913915 fsnotify(inode, FS_MODIFY, inode, FSNOTIFY_EVENT_INODE,
914− kn->name, 0);
916+ &name, 0);
915917 iput(inode);
916918 }
917919
fs/notify/fsnotify.c+4−4
@@ -179,10 +179,10 @@ int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask · 178 unmodified lines
179179 take_dentry_name_snapshot(&name, dentry);
180180 if (path)
181181 ret = fsnotify(p_inode, mask, path, FSNOTIFY_EVENT_PATH,
182− name.name.name, 0);
182+ &name.name, 0);
183183 else
184184 ret = fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE,
185− name.name.name, 0);
185+ &name.name, 0);
186186 release_dentry_name_snapshot(&name);
187187 }
188188
@@ -325,7 +325,7 @@ static void fsnotify_iter_next(struct fsnotify_iter_info *iter_info) · 136 unmodified lines
325325 * notification event in whatever means they feel necessary.
326326 */
327327 int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
328− const unsigned char *file_name, u32 cookie)
328+ const struct qstr *file_name, u32 cookie)
329329 {
330330 struct fsnotify_iter_info iter_info = {};
331331 struct super_block *sb = to_tell->i_sb;
@@ -379,7 +379,7 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, · 47 unmodified lines
379379 */
380380 while (fsnotify_iter_select_report_types(&iter_info)) {
381381 ret = send_to_group(to_tell, mask, data, data_is, cookie,
382− file_name, &iter_info);
382+ file_name->name, &iter_info);
383383
384384 if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS))
385385 goto out;
include/linux/fsnotify.h+5−5
@@ -27,7 +27,7 @@ static inline int fsnotify_dirent(struct inode *dir, struct dentry *dentry, · 26 unmodified lines
2727 __u32 mask)
2828 {
2929 return fsnotify(dir, mask, d_inode(dentry), FSNOTIFY_EVENT_INODE,
30− dentry->d_name.name, 0);
30+ &dentry->d_name, 0);
3131 }
3232
3333 /* Notify this dentry's parent about a child's events. */
@@ -111,7 +111,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, · 77 unmodified lines
111111 __u32 old_dir_mask = FS_MOVED_FROM;
112112 __u32 new_dir_mask = FS_MOVED_TO;
113113 __u32 mask = FS_MOVE_SELF;
114− const unsigned char *new_name = moved->d_name.name;
114+ const struct qstr *new_name = &moved->d_name;
115115
116116 if (old_dir == new_dir)
117117 old_dir_mask |= FS_DN_RENAME;
@@ -122,7 +122,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, · 4 unmodified lines
122122 mask |= FS_ISDIR;
123123 }
124124
125− fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name->name,
125+ fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name,
126126 fs_cookie);
127127 fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE, new_name,
128128 fs_cookie);
@@ -178,7 +178,7 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) · 49 unmodified lines
178178 take_dentry_name_snapshot(&name, dentry);
179179
180180 fsnotify(d_inode(parent), mask, d_inode(dentry), FSNOTIFY_EVENT_INODE,
181− name.name.name, 0);
181+ &name.name, 0);
182182
183183 release_dentry_name_snapshot(&name);
184184 dput(parent);
@@ -218,7 +218,7 @@ static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct · 33 unmodified lines
218218 fsnotify_link_count(inode);
219219 audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE);
220220
221− fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0);
221+ fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, &new_dentry->d_name, 0);
222222 }
223223
224224 /*
include/linux/fsnotify_backend.h+2−2
@@ -350,7 +350,7 @@ struct fsnotify_mark { · 349 unmodified lines
350350
351351 /* main fsnotify call to send events */
352352 extern int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
353− const unsigned char *name, u32 cookie);
353+ const struct qstr *name, u32 cookie);
354354 extern int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask);
355355 extern void __fsnotify_inode_delete(struct inode *inode);
356356 extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);
@@ -505,7 +505,7 @@ static inline void fsnotify_init_event(struct fsnotify_event *event, · 148 unmodified lines
505505 #else
506506
507507 static inline int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
508− const unsigned char *name, u32 cookie)
508+ const struct qstr *name, u32 cookie)
509509 {
510510 return 0;
511511 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t