mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-05-04 14:23:46 +00:00
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/20200708111156.24659-2-amir73il@gmail.com Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz>
This commit is contained in:
parent
71d734103e
commit
c738fbabb0
2 changed files with 35 additions and 33 deletions
|
@ -142,7 +142,11 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode)
|
||||||
spin_unlock(&inode->i_lock);
|
spin_unlock(&inode->i_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Notify this dentry's parent about a child's events. */
|
/*
|
||||||
|
* Notify this dentry's parent about a child's events with child name info
|
||||||
|
* if parent is watching.
|
||||||
|
* Notify also the child without name info if child inode is watching.
|
||||||
|
*/
|
||||||
int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
|
int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
|
||||||
int data_type)
|
int data_type)
|
||||||
{
|
{
|
||||||
|
@ -151,7 +155,7 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED))
|
if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED))
|
||||||
return 0;
|
goto notify_child;
|
||||||
|
|
||||||
parent = dget_parent(dentry);
|
parent = dget_parent(dentry);
|
||||||
p_inode = parent->d_inode;
|
p_inode = parent->d_inode;
|
||||||
|
@ -161,18 +165,23 @@ int __fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
|
||||||
} else if (p_inode->i_fsnotify_mask & mask & ALL_FSNOTIFY_EVENTS) {
|
} else if (p_inode->i_fsnotify_mask & mask & ALL_FSNOTIFY_EVENTS) {
|
||||||
struct name_snapshot name;
|
struct name_snapshot name;
|
||||||
|
|
||||||
/* we are notifying a parent so come up with the new mask which
|
/*
|
||||||
* specifies these are events which came from a child. */
|
* We are notifying a parent, so set a flag in mask to inform
|
||||||
mask |= FS_EVENT_ON_CHILD;
|
* backend that event has information about a child entry.
|
||||||
|
*/
|
||||||
take_dentry_name_snapshot(&name, dentry);
|
take_dentry_name_snapshot(&name, dentry);
|
||||||
ret = fsnotify(p_inode, mask, data, data_type, &name.name, 0);
|
ret = fsnotify(p_inode, mask | FS_EVENT_ON_CHILD, data,
|
||||||
|
data_type, &name.name, 0);
|
||||||
release_dentry_name_snapshot(&name);
|
release_dentry_name_snapshot(&name);
|
||||||
}
|
}
|
||||||
|
|
||||||
dput(parent);
|
dput(parent);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
notify_child:
|
||||||
|
return fsnotify(d_inode(dentry), mask, data, data_type, NULL, 0);
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(__fsnotify_parent);
|
EXPORT_SYMBOL_GPL(__fsnotify_parent);
|
||||||
|
|
||||||
|
|
|
@ -47,45 +47,38 @@ static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry,
|
||||||
/* Notify this dentry's parent about a child's events. */
|
/* Notify this dentry's parent about a child's events. */
|
||||||
static inline int fsnotify_parent(struct dentry *dentry, __u32 mask,
|
static inline int fsnotify_parent(struct dentry *dentry, __u32 mask,
|
||||||
const void *data, int data_type)
|
const void *data, int data_type)
|
||||||
{
|
|
||||||
if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return __fsnotify_parent(dentry, mask, data, data_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Simple wrappers to consolidate calls fsnotify_parent()/fsnotify() when
|
|
||||||
* an event is on a file/dentry.
|
|
||||||
*/
|
|
||||||
static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask)
|
|
||||||
{
|
{
|
||||||
struct inode *inode = d_inode(dentry);
|
struct inode *inode = d_inode(dentry);
|
||||||
|
|
||||||
if (S_ISDIR(inode->i_mode))
|
if (S_ISDIR(inode->i_mode))
|
||||||
mask |= FS_ISDIR;
|
mask |= FS_ISDIR;
|
||||||
|
|
||||||
fsnotify_parent(dentry, mask, inode, FSNOTIFY_EVENT_INODE);
|
if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED))
|
||||||
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
|
goto notify_child;
|
||||||
|
|
||||||
|
return __fsnotify_parent(dentry, mask, data, data_type);
|
||||||
|
|
||||||
|
notify_child:
|
||||||
|
return fsnotify(inode, mask, data, data_type, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Simple wrappers to consolidate calls to fsnotify_parent() when an event
|
||||||
|
* is on a file/dentry.
|
||||||
|
*/
|
||||||
|
static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask)
|
||||||
|
{
|
||||||
|
fsnotify_parent(dentry, mask, d_inode(dentry), FSNOTIFY_EVENT_INODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int fsnotify_file(struct file *file, __u32 mask)
|
static inline int fsnotify_file(struct file *file, __u32 mask)
|
||||||
{
|
{
|
||||||
const struct path *path = &file->f_path;
|
const struct path *path = &file->f_path;
|
||||||
struct inode *inode = file_inode(file);
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (file->f_mode & FMODE_NONOTIFY)
|
if (file->f_mode & FMODE_NONOTIFY)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (S_ISDIR(inode->i_mode))
|
return fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH);
|
||||||
mask |= FS_ISDIR;
|
|
||||||
|
|
||||||
ret = fsnotify_parent(path->dentry, mask, path, FSNOTIFY_EVENT_PATH);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Simple call site for access decisions */
|
/* Simple call site for access decisions */
|
||||||
|
|
Loading…
Add table
Reference in a new issue