mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
fsnotify: factor helpers fsnotify_dentry() and fsnotify_file()
Most of the code in fsnotify hooks is boiler plate of one or the other. Link: https://lore.kernel.org/r/20200319151022.31456-3-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
6473ea760c
commit
eae36a2b83
1 changed files with 37 additions and 62 deletions
|
@ -41,16 +41,36 @@ static inline int fsnotify_parent(const struct path *path,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Simple wrapper to consolidate calls fsnotify_parent()/fsnotify() when
|
* Simple wrappers to consolidate calls fsnotify_parent()/fsnotify() when
|
||||||
* an event is on a path.
|
* an event is on a file/dentry.
|
||||||
*/
|
*/
|
||||||
static inline int fsnotify_path(struct inode *inode, const struct path *path,
|
static inline void fsnotify_dentry(struct dentry *dentry, __u32 mask)
|
||||||
__u32 mask)
|
|
||||||
{
|
{
|
||||||
int ret = fsnotify_parent(path, NULL, mask);
|
struct inode *inode = d_inode(dentry);
|
||||||
|
|
||||||
|
if (S_ISDIR(inode->i_mode))
|
||||||
|
mask |= FS_ISDIR;
|
||||||
|
|
||||||
|
fsnotify_parent(NULL, dentry, mask);
|
||||||
|
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int fsnotify_file(struct file *file, __u32 mask)
|
||||||
|
{
|
||||||
|
const struct path *path = &file->f_path;
|
||||||
|
struct inode *inode = file_inode(file);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (file->f_mode & FMODE_NONOTIFY)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (S_ISDIR(inode->i_mode))
|
||||||
|
mask |= FS_ISDIR;
|
||||||
|
|
||||||
|
ret = fsnotify_parent(path, NULL, mask);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
|
return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,19 +78,16 @@ static inline int fsnotify_path(struct inode *inode, const struct path *path,
|
||||||
static inline int fsnotify_perm(struct file *file, int mask)
|
static inline int fsnotify_perm(struct file *file, int mask)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
const struct path *path = &file->f_path;
|
|
||||||
struct inode *inode = file_inode(file);
|
|
||||||
__u32 fsnotify_mask = 0;
|
__u32 fsnotify_mask = 0;
|
||||||
|
|
||||||
if (file->f_mode & FMODE_NONOTIFY)
|
|
||||||
return 0;
|
|
||||||
if (!(mask & (MAY_READ | MAY_OPEN)))
|
if (!(mask & (MAY_READ | MAY_OPEN)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (mask & MAY_OPEN) {
|
if (mask & MAY_OPEN) {
|
||||||
fsnotify_mask = FS_OPEN_PERM;
|
fsnotify_mask = FS_OPEN_PERM;
|
||||||
|
|
||||||
if (file->f_flags & __FMODE_EXEC) {
|
if (file->f_flags & __FMODE_EXEC) {
|
||||||
ret = fsnotify_path(inode, path, FS_OPEN_EXEC_PERM);
|
ret = fsnotify_file(file, FS_OPEN_EXEC_PERM);
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -79,10 +96,7 @@ static inline int fsnotify_perm(struct file *file, int mask)
|
||||||
fsnotify_mask = FS_ACCESS_PERM;
|
fsnotify_mask = FS_ACCESS_PERM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (S_ISDIR(inode->i_mode))
|
return fsnotify_file(file, fsnotify_mask);
|
||||||
fsnotify_mask |= FS_ISDIR;
|
|
||||||
|
|
||||||
return fsnotify_path(inode, path, fsnotify_mask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -229,15 +243,7 @@ static inline void fsnotify_rmdir(struct inode *dir, struct dentry *dentry)
|
||||||
*/
|
*/
|
||||||
static inline void fsnotify_access(struct file *file)
|
static inline void fsnotify_access(struct file *file)
|
||||||
{
|
{
|
||||||
const struct path *path = &file->f_path;
|
fsnotify_file(file, FS_ACCESS);
|
||||||
struct inode *inode = file_inode(file);
|
|
||||||
__u32 mask = FS_ACCESS;
|
|
||||||
|
|
||||||
if (S_ISDIR(inode->i_mode))
|
|
||||||
mask |= FS_ISDIR;
|
|
||||||
|
|
||||||
if (!(file->f_mode & FMODE_NONOTIFY))
|
|
||||||
fsnotify_path(inode, path, mask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -245,15 +251,7 @@ static inline void fsnotify_access(struct file *file)
|
||||||
*/
|
*/
|
||||||
static inline void fsnotify_modify(struct file *file)
|
static inline void fsnotify_modify(struct file *file)
|
||||||
{
|
{
|
||||||
const struct path *path = &file->f_path;
|
fsnotify_file(file, FS_MODIFY);
|
||||||
struct inode *inode = file_inode(file);
|
|
||||||
__u32 mask = FS_MODIFY;
|
|
||||||
|
|
||||||
if (S_ISDIR(inode->i_mode))
|
|
||||||
mask |= FS_ISDIR;
|
|
||||||
|
|
||||||
if (!(file->f_mode & FMODE_NONOTIFY))
|
|
||||||
fsnotify_path(inode, path, mask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -261,16 +259,12 @@ static inline void fsnotify_modify(struct file *file)
|
||||||
*/
|
*/
|
||||||
static inline void fsnotify_open(struct file *file)
|
static inline void fsnotify_open(struct file *file)
|
||||||
{
|
{
|
||||||
const struct path *path = &file->f_path;
|
|
||||||
struct inode *inode = file_inode(file);
|
|
||||||
__u32 mask = FS_OPEN;
|
__u32 mask = FS_OPEN;
|
||||||
|
|
||||||
if (S_ISDIR(inode->i_mode))
|
|
||||||
mask |= FS_ISDIR;
|
|
||||||
if (file->f_flags & __FMODE_EXEC)
|
if (file->f_flags & __FMODE_EXEC)
|
||||||
mask |= FS_OPEN_EXEC;
|
mask |= FS_OPEN_EXEC;
|
||||||
|
|
||||||
fsnotify_path(inode, path, mask);
|
fsnotify_file(file, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -278,16 +272,10 @@ static inline void fsnotify_open(struct file *file)
|
||||||
*/
|
*/
|
||||||
static inline void fsnotify_close(struct file *file)
|
static inline void fsnotify_close(struct file *file)
|
||||||
{
|
{
|
||||||
const struct path *path = &file->f_path;
|
__u32 mask = (file->f_mode & FMODE_WRITE) ? FS_CLOSE_WRITE :
|
||||||
struct inode *inode = file_inode(file);
|
FS_CLOSE_NOWRITE;
|
||||||
fmode_t mode = file->f_mode;
|
|
||||||
__u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
|
|
||||||
|
|
||||||
if (S_ISDIR(inode->i_mode))
|
fsnotify_file(file, mask);
|
||||||
mask |= FS_ISDIR;
|
|
||||||
|
|
||||||
if (!(file->f_mode & FMODE_NONOTIFY))
|
|
||||||
fsnotify_path(inode, path, mask);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -295,14 +283,7 @@ static inline void fsnotify_close(struct file *file)
|
||||||
*/
|
*/
|
||||||
static inline void fsnotify_xattr(struct dentry *dentry)
|
static inline void fsnotify_xattr(struct dentry *dentry)
|
||||||
{
|
{
|
||||||
struct inode *inode = dentry->d_inode;
|
fsnotify_dentry(dentry, FS_ATTRIB);
|
||||||
__u32 mask = FS_ATTRIB;
|
|
||||||
|
|
||||||
if (S_ISDIR(inode->i_mode))
|
|
||||||
mask |= FS_ISDIR;
|
|
||||||
|
|
||||||
fsnotify_parent(NULL, dentry, mask);
|
|
||||||
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -311,7 +292,6 @@ static inline void fsnotify_xattr(struct dentry *dentry)
|
||||||
*/
|
*/
|
||||||
static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
|
static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
|
||||||
{
|
{
|
||||||
struct inode *inode = dentry->d_inode;
|
|
||||||
__u32 mask = 0;
|
__u32 mask = 0;
|
||||||
|
|
||||||
if (ia_valid & ATTR_UID)
|
if (ia_valid & ATTR_UID)
|
||||||
|
@ -332,13 +312,8 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
|
||||||
if (ia_valid & ATTR_MODE)
|
if (ia_valid & ATTR_MODE)
|
||||||
mask |= FS_ATTRIB;
|
mask |= FS_ATTRIB;
|
||||||
|
|
||||||
if (mask) {
|
if (mask)
|
||||||
if (S_ISDIR(inode->i_mode))
|
fsnotify_dentry(dentry, mask);
|
||||||
mask |= FS_ISDIR;
|
|
||||||
|
|
||||||
fsnotify_parent(NULL, dentry, mask);
|
|
||||||
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _LINUX_FS_NOTIFY_H */
|
#endif /* _LINUX_FS_NOTIFY_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue