Skip to content

Commit 82ace1e

Browse files
amir73iljankara
authored andcommitted
fsnotify: create helper fsnotify_inode()
Simple helper to consolidate biolerplate code. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 497b0c5 commit 82ace1e

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

fs/kernfs/file.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -910,10 +910,8 @@ static void kernfs_notify_workfn(struct work_struct *work)
910910
kernfs_put(parent);
911911
}
912912

913-
if (!p_inode) {
914-
fsnotify(inode, FS_MODIFY, inode, FSNOTIFY_EVENT_INODE,
915-
NULL, 0);
916-
}
913+
if (!p_inode)
914+
fsnotify_inode(inode, FS_MODIFY);
917915

918916
iput(inode);
919917
}

fs/notify/fsnotify.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void fsnotify_unmount_inodes(struct super_block *sb)
7474
iput(iput_inode);
7575

7676
/* for each watch, send FS_UNMOUNT and then remove it */
77-
fsnotify(inode, FS_UNMOUNT, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
77+
fsnotify_inode(inode, FS_UNMOUNT);
7878

7979
fsnotify_inode_delete(inode);
8080

include/linux/fsnotify.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry,
3838
fsnotify_name(dir, mask, d_inode(dentry), &dentry->d_name, 0);
3939
}
4040

41+
static inline void fsnotify_inode(struct inode *inode, __u32 mask)
42+
{
43+
if (S_ISDIR(inode->i_mode))
44+
mask |= FS_ISDIR;
45+
46+
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
47+
}
48+
4149
/* Notify this dentry's parent about a child's events. */
4250
static inline int fsnotify_parent(struct dentry *dentry, __u32 mask,
4351
const void *data, int data_type)
@@ -105,12 +113,7 @@ static inline int fsnotify_perm(struct file *file, int mask)
105113
*/
106114
static inline void fsnotify_link_count(struct inode *inode)
107115
{
108-
__u32 mask = FS_ATTRIB;
109-
110-
if (S_ISDIR(inode->i_mode))
111-
mask |= FS_ISDIR;
112-
113-
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
116+
fsnotify_inode(inode, FS_ATTRIB);
114117
}
115118

116119
/*
@@ -125,7 +128,6 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
125128
u32 fs_cookie = fsnotify_get_cookie();
126129
__u32 old_dir_mask = FS_MOVED_FROM;
127130
__u32 new_dir_mask = FS_MOVED_TO;
128-
__u32 mask = FS_MOVE_SELF;
129131
const struct qstr *new_name = &moved->d_name;
130132

131133
if (old_dir == new_dir)
@@ -134,7 +136,6 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
134136
if (isdir) {
135137
old_dir_mask |= FS_ISDIR;
136138
new_dir_mask |= FS_ISDIR;
137-
mask |= FS_ISDIR;
138139
}
139140

140141
fsnotify_name(old_dir, old_dir_mask, source, old_name, fs_cookie);
@@ -144,7 +145,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
144145
fsnotify_link_count(target);
145146

146147
if (source)
147-
fsnotify(source, mask, source, FSNOTIFY_EVENT_INODE, NULL, 0);
148+
fsnotify_inode(source, FS_MOVE_SELF);
148149
audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE);
149150
}
150151

@@ -169,12 +170,7 @@ static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt)
169170
*/
170171
static inline void fsnotify_inoderemove(struct inode *inode)
171172
{
172-
__u32 mask = FS_DELETE_SELF;
173-
174-
if (S_ISDIR(inode->i_mode))
175-
mask |= FS_ISDIR;
176-
177-
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
173+
fsnotify_inode(inode, FS_DELETE_SELF);
178174
__fsnotify_inode_delete(inode);
179175
}
180176

kernel/trace/trace.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,8 +1543,7 @@ static void latency_fsnotify_workfn(struct work_struct *work)
15431543
{
15441544
struct trace_array *tr = container_of(work, struct trace_array,
15451545
fsnotify_work);
1546-
fsnotify(tr->d_max_latency->d_inode, FS_MODIFY,
1547-
tr->d_max_latency->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
1546+
fsnotify_inode(tr->d_max_latency->d_inode, FS_MODIFY);
15481547
}
15491548

15501549
static void latency_fsnotify_workfn_irq(struct irq_work *iwork)

0 commit comments

Comments
 (0)