Skip to content

Commit

Permalink
fsnotify: create helper fsnotify_inode()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
amir73il authored and jankara committed Jul 27, 2020
1 parent 497b0c5 commit 82ace1e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
6 changes: 2 additions & 4 deletions fs/kernfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,10 +910,8 @@ static void kernfs_notify_workfn(struct work_struct *work)
kernfs_put(parent);
}

if (!p_inode) {
fsnotify(inode, FS_MODIFY, inode, FSNOTIFY_EVENT_INODE,
NULL, 0);
}
if (!p_inode)
fsnotify_inode(inode, FS_MODIFY);

iput(inode);
}
Expand Down
2 changes: 1 addition & 1 deletion fs/notify/fsnotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static void fsnotify_unmount_inodes(struct super_block *sb)
iput(iput_inode);

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

fsnotify_inode_delete(inode);

Expand Down
26 changes: 11 additions & 15 deletions include/linux/fsnotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry,
fsnotify_name(dir, mask, d_inode(dentry), &dentry->d_name, 0);
}

static inline void fsnotify_inode(struct inode *inode, __u32 mask)
{
if (S_ISDIR(inode->i_mode))
mask |= FS_ISDIR;

fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
}

/* Notify this dentry's parent about a child's events. */
static inline int fsnotify_parent(struct dentry *dentry, __u32 mask,
const void *data, int data_type)
Expand Down Expand Up @@ -105,12 +113,7 @@ static inline int fsnotify_perm(struct file *file, int mask)
*/
static inline void fsnotify_link_count(struct inode *inode)
{
__u32 mask = FS_ATTRIB;

if (S_ISDIR(inode->i_mode))
mask |= FS_ISDIR;

fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
fsnotify_inode(inode, FS_ATTRIB);
}

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

if (old_dir == new_dir)
Expand All @@ -134,7 +136,6 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
if (isdir) {
old_dir_mask |= FS_ISDIR;
new_dir_mask |= FS_ISDIR;
mask |= FS_ISDIR;
}

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

if (source)
fsnotify(source, mask, source, FSNOTIFY_EVENT_INODE, NULL, 0);
fsnotify_inode(source, FS_MOVE_SELF);
audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE);
}

Expand All @@ -169,12 +170,7 @@ static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt)
*/
static inline void fsnotify_inoderemove(struct inode *inode)
{
__u32 mask = FS_DELETE_SELF;

if (S_ISDIR(inode->i_mode))
mask |= FS_ISDIR;

fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
fsnotify_inode(inode, FS_DELETE_SELF);
__fsnotify_inode_delete(inode);
}

Expand Down
3 changes: 1 addition & 2 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1543,8 +1543,7 @@ static void latency_fsnotify_workfn(struct work_struct *work)
{
struct trace_array *tr = container_of(work, struct trace_array,
fsnotify_work);
fsnotify(tr->d_max_latency->d_inode, FS_MODIFY,
tr->d_max_latency->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
fsnotify_inode(tr->d_max_latency->d_inode, FS_MODIFY);
}

static void latency_fsnotify_workfn_irq(struct irq_work *iwork)
Expand Down

0 comments on commit 82ace1e

Please sign in to comment.