Skip to content

Commit c738fba

Browse files
amir73iljankara
authored andcommitted
fsnotify: fold fsnotify() call into fsnotify_parent()
All (two) callers of fsnotify_parent() also call fsnotify() to notify the child inode. Move the second fsnotify() call into fsnotify_parent(). This will allow more flexibility in making decisions about which of the two event falvors should be sent. Using 'goto notify_child' in the inline helper seems a bit strange, but it mimics the code in __fsnotify_parent() for clarity and the goto pattern will become less strage after following patches are applied. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 71d7341 commit c738fba

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

fs/notify/fsnotify.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,20 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode)
142142
spin_unlock(&inode->i_lock);
143143
}
144144

145-
/* Notify this dentry's parent about a child's events. */
145+
/*
146+
* Notify this dentry's parent about a child's events with child name info
147+
* if parent is watching.
148+
* Notify also the child without name info if child inode is watching.
149+
*/
146150
int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
147-
int data_type)
151+
int data_type)
148152
{
149153
struct dentry *parent;
150154
struct inode *p_inode;
151155
int ret = 0;
152156

153157
if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED))
154-
return 0;
158+
goto notify_child;
155159

156160
parent = dget_parent(dentry);
157161
p_inode = parent->d_inode;
@@ -161,18 +165,23 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
161165
} else if (p_inode->i_fsnotify_mask & mask & ALL_FSNOTIFY_EVENTS) {
162166
struct name_snapshot name;
163167

164-
/* we are notifying a parent so come up with the new mask which
165-
* specifies these are events which came from a child. */
166-
mask |= FS_EVENT_ON_CHILD;
167-
168+
/*
169+
* We are notifying a parent, so set a flag in mask to inform
170+
* backend that event has information about a child entry.
171+
*/
168172
take_dentry_name_snapshot(&name, dentry);
169-
ret = fsnotify(p_inode, mask, data, data_type, &name.name, 0);
173+
ret = fsnotify(p_inode, mask | FS_EVENT_ON_CHILD, data,
174+
data_type, &name.name, 0);
170175
release_dentry_name_snapshot(&name);
171176
}
172177

173178
dput(parent);
174179

175-
return ret;
180+
if (ret)
181+
return ret;
182+
183+
notify_child:
184+
return fsnotify(d_inode(dentry), mask, data, data_type, NULL, 0);
176185
}
177186
EXPORT_SYMBOL_GPL(__fsnotify_parent);
178187

include/linux/fsnotify.h

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,44 +48,37 @@ static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry,
4848
static inline int fsnotify_parent(struct dentry *dentry, __u32 mask,
4949
const void *data, int data_type)
5050
{
51+
struct inode *inode = d_inode(dentry);
52+
53+
if (S_ISDIR(inode->i_mode))
54+
mask |= FS_ISDIR;
55+
5156
if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED))
52-
return 0;
57+
goto notify_child;
5358

5459
return __fsnotify_parent(dentry, mask, data, data_type);
60+
61+
notify_child:
62+
return fsnotify(inode, mask, data, data_type, NULL, 0);
5563
}
5664

5765
/*
58-
* Simple wrappers to consolidate calls fsnotify_parent()/fsnotify() when
59-
* an event is on a file/dentry.
66+
* Simple wrappers to consolidate calls to fsnotify_parent() when an event
67+
* is on a file/dentry.
6068
*/
6169
static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask)
6270
{
63-
struct inode *inode = d_inode(dentry);
64-
65-
if (S_ISDIR(inode->i_mode))
66-
mask |= FS_ISDIR;
67-
68-
fsnotify_parent(dentry, mask, inode, FSNOTIFY_EVENT_INODE);
69-
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
71+
fsnotify_parent(dentry, mask, d_inode(dentry), FSNOTIFY_EVENT_INODE);
7072
}
7173

7274
static inline int fsnotify_file(struct file *file, __u32 mask)
7375
{
7476
const struct path *path = &file->f_path;
75-
struct inode *inode = file_inode(file);
76-
int ret;
7777

7878
if (file->f_mode & FMODE_NONOTIFY)
7979
return 0;
8080

81-
if (S_ISDIR(inode->i_mode))
82-
mask |= FS_ISDIR;
83-
84-
ret = fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH);
85-
if (ret)
86-
return ret;
87-
88-
return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
81+
return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH);
8982
}
9083

9184
/* Simple call site for access decisions */

0 commit comments

Comments
 (0)