Skip to content

Commit 25b229d

Browse files
author
Al Viro
committed
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. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent f4ec3a3 commit 25b229d

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

‎fs/kernfs/file.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ static void kernfs_notify_workfn(struct work_struct *work)
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,22 +897,23 @@ static void kernfs_notify_workfn(struct work_struct *work)
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;
902904

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

910912
kernfs_put(parent);
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‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask
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)
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,
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‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static inline int fsnotify_dirent(struct inode *dir, struct dentry *dentry,
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,
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,
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)
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
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‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ struct fsnotify_mark {
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,
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
}

0 commit comments

Comments
 (0)