\n
-----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEq1nRK9aeMoq1VSgcnJ2qBz9kQNkFAl6LFJ0ACgkQnJ2qBz9k QNkSUQgAzwaescnHeVTF7/Zg9Uj2xrfrTJZ1E+Mn9qnd/0/z/asVV+RKfY7Gnu7h g19inDI4ZESFz2gWz4jwJD1c2/yMZb8vnae4ye3dtCv2yjG/0JxCeue6vjwsWqmO 4jbSgk8YNQqzwEFVMzNp43ZJr3CFooLCIsJcL8q4yYk8Kt4pDUPmQ1vBvAc6k9vK BKMBvp926tbomP27nq0n0CjvHy7ipDGMl4H6i4vBxHRfbDPih2x9VEklK3JatC1n 4AKS6IYJrkZVdOjli+DrResbcWxyT4db5tPio5MU0RDnVhNZT2cHyNVXf5EpRJqP 72pa7gfPu1Rx1+tU8bDR/daSveou2A== =fkCV -----END PGP SIGNATURE----- Merge tag 'fsnotify_for_v5.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs Pull fsnotify updates from Jan Kara: "This implements the fanotify FAN_DIR_MODIFY event. This event reports the name in a directory under which a change happened and together with the directory filehandle and fstatat() allows reliable and efficient implementation of directory synchronization" * tag 'fsnotify_for_v5.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs: fanotify: Fix the checks in fanotify_fsid_equal fanotify: report name info for FAN_DIR_MODIFY event fanotify: record name info for FAN_DIR_MODIFY event fanotify: Drop fanotify_event_has_fid() fanotify: prepare to report both parent and child fid's fanotify: send FAN_DIR_MODIFY event flavor with dir inode and name fanotify: divorce fanotify_path_event and fanotify_fid_event fanotify: Store fanotify handles differently fanotify: Simplify create_fd() fanotify: fix merging marks masks with FAN_ONDIR fanotify: merge duplicate events on parent and child fsnotify: replace inode pointer with an object id fsnotify: simplify arguments passing to fsnotify_parent() fsnotify: use helpers to access data by data_type fsnotify: funnel all dirent events through fsnotify_name() fsnotify: factor helpers fsnotify_dentry() and fsnotify_file() fsnotify: tidy up FS_ and FAN_ constants
This commit is contained in:
commit
b6ff10700d
12 changed files with 642 additions and 368 deletions
|
|
@ -47,7 +47,8 @@
|
|||
* Directory entry modification events - reported only to directory
|
||||
* where entry is modified and not to a watching parent.
|
||||
*/
|
||||
#define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE)
|
||||
#define FANOTIFY_DIRENT_EVENTS (FAN_MOVE | FAN_CREATE | FAN_DELETE | \
|
||||
FAN_DIR_MODIFY)
|
||||
|
||||
/* Events that can only be reported with data type FSNOTIFY_EVENT_INODE */
|
||||
#define FANOTIFY_INODE_EVENTS (FANOTIFY_DIRENT_EVENTS | \
|
||||
|
|
|
|||
|
|
@ -18,39 +18,63 @@
|
|||
#include <linux/bug.h>
|
||||
|
||||
/*
|
||||
* Notify this @dir inode about a change in the directory entry @dentry.
|
||||
* Notify this @dir inode about a change in a child directory entry.
|
||||
* The directory entry may have turned positive or negative or its inode may
|
||||
* have changed (i.e. renamed over).
|
||||
*
|
||||
* Unlike fsnotify_parent(), the event will be reported regardless of the
|
||||
* FS_EVENT_ON_CHILD mask on the parent inode.
|
||||
*/
|
||||
static inline int fsnotify_dirent(struct inode *dir, struct dentry *dentry,
|
||||
__u32 mask)
|
||||
static inline void fsnotify_name(struct inode *dir, __u32 mask,
|
||||
struct inode *child,
|
||||
const struct qstr *name, u32 cookie)
|
||||
{
|
||||
return fsnotify(dir, mask, d_inode(dentry), FSNOTIFY_EVENT_INODE,
|
||||
&dentry->d_name, 0);
|
||||
fsnotify(dir, mask, child, FSNOTIFY_EVENT_INODE, name, cookie);
|
||||
/*
|
||||
* Send another flavor of the event without child inode data and
|
||||
* without the specific event type (e.g. FS_CREATE|FS_IS_DIR).
|
||||
* The name is relative to the dir inode the event is reported to.
|
||||
*/
|
||||
fsnotify(dir, FS_DIR_MODIFY, dir, FSNOTIFY_EVENT_INODE, name, 0);
|
||||
}
|
||||
|
||||
/* Notify this dentry's parent about a child's events. */
|
||||
static inline int fsnotify_parent(const struct path *path,
|
||||
struct dentry *dentry, __u32 mask)
|
||||
static inline void fsnotify_dirent(struct inode *dir, struct dentry *dentry,
|
||||
__u32 mask)
|
||||
{
|
||||
if (!dentry)
|
||||
dentry = path->dentry;
|
||||
|
||||
return __fsnotify_parent(path, dentry, mask);
|
||||
fsnotify_name(dir, mask, d_inode(dentry), &dentry->d_name, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Simple wrapper to consolidate calls fsnotify_parent()/fsnotify() when
|
||||
* an event is on a path.
|
||||
* Simple wrappers to consolidate calls fsnotify_parent()/fsnotify() when
|
||||
* an event is on a file/dentry.
|
||||
*/
|
||||
static inline int fsnotify_path(struct inode *inode, const struct path *path,
|
||||
__u32 mask)
|
||||
static inline void fsnotify_dentry(struct dentry *dentry, __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(dentry, mask, inode, FSNOTIFY_EVENT_INODE);
|
||||
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->dentry, mask, path, FSNOTIFY_EVENT_PATH);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
|
||||
}
|
||||
|
||||
|
|
@ -58,19 +82,16 @@ static inline int fsnotify_path(struct inode *inode, const struct path *path,
|
|||
static inline int fsnotify_perm(struct file *file, int mask)
|
||||
{
|
||||
int ret;
|
||||
const struct path *path = &file->f_path;
|
||||
struct inode *inode = file_inode(file);
|
||||
__u32 fsnotify_mask = 0;
|
||||
|
||||
if (file->f_mode & FMODE_NONOTIFY)
|
||||
return 0;
|
||||
if (!(mask & (MAY_READ | MAY_OPEN)))
|
||||
return 0;
|
||||
|
||||
if (mask & MAY_OPEN) {
|
||||
fsnotify_mask = FS_OPEN_PERM;
|
||||
|
||||
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)
|
||||
return ret;
|
||||
|
|
@ -79,10 +100,7 @@ static inline int fsnotify_perm(struct file *file, int mask)
|
|||
fsnotify_mask = FS_ACCESS_PERM;
|
||||
}
|
||||
|
||||
if (S_ISDIR(inode->i_mode))
|
||||
fsnotify_mask |= FS_ISDIR;
|
||||
|
||||
return fsnotify_path(inode, path, fsnotify_mask);
|
||||
return fsnotify_file(file, fsnotify_mask);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -122,10 +140,8 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
|
|||
mask |= FS_ISDIR;
|
||||
}
|
||||
|
||||
fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name,
|
||||
fs_cookie);
|
||||
fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE, new_name,
|
||||
fs_cookie);
|
||||
fsnotify_name(old_dir, old_dir_mask, source, old_name, fs_cookie);
|
||||
fsnotify_name(new_dir, new_dir_mask, source, new_name, fs_cookie);
|
||||
|
||||
if (target)
|
||||
fsnotify_link_count(target);
|
||||
|
|
@ -180,12 +196,13 @@ static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
|
|||
* Note: We have to pass also the linked inode ptr as some filesystems leave
|
||||
* new_dentry->d_inode NULL and instantiate inode pointer later
|
||||
*/
|
||||
static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
|
||||
static inline void fsnotify_link(struct inode *dir, struct inode *inode,
|
||||
struct dentry *new_dentry)
|
||||
{
|
||||
fsnotify_link_count(inode);
|
||||
audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE);
|
||||
|
||||
fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, &new_dentry->d_name, 0);
|
||||
fsnotify_name(dir, FS_CREATE, inode, &new_dentry->d_name, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -229,15 +246,7 @@ static inline void fsnotify_rmdir(struct inode *dir, struct dentry *dentry)
|
|||
*/
|
||||
static inline void fsnotify_access(struct file *file)
|
||||
{
|
||||
const struct path *path = &file->f_path;
|
||||
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);
|
||||
fsnotify_file(file, FS_ACCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -245,15 +254,7 @@ static inline void fsnotify_access(struct file *file)
|
|||
*/
|
||||
static inline void fsnotify_modify(struct file *file)
|
||||
{
|
||||
const struct path *path = &file->f_path;
|
||||
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);
|
||||
fsnotify_file(file, FS_MODIFY);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -261,16 +262,12 @@ static inline void fsnotify_modify(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;
|
||||
|
||||
if (S_ISDIR(inode->i_mode))
|
||||
mask |= FS_ISDIR;
|
||||
if (file->f_flags & __FMODE_EXEC)
|
||||
mask |= FS_OPEN_EXEC;
|
||||
|
||||
fsnotify_path(inode, path, mask);
|
||||
fsnotify_file(file, mask);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -278,16 +275,10 @@ static inline void fsnotify_open(struct file *file)
|
|||
*/
|
||||
static inline void fsnotify_close(struct file *file)
|
||||
{
|
||||
const struct path *path = &file->f_path;
|
||||
struct inode *inode = file_inode(file);
|
||||
fmode_t mode = file->f_mode;
|
||||
__u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
|
||||
__u32 mask = (file->f_mode & FMODE_WRITE) ? FS_CLOSE_WRITE :
|
||||
FS_CLOSE_NOWRITE;
|
||||
|
||||
if (S_ISDIR(inode->i_mode))
|
||||
mask |= FS_ISDIR;
|
||||
|
||||
if (!(file->f_mode & FMODE_NONOTIFY))
|
||||
fsnotify_path(inode, path, mask);
|
||||
fsnotify_file(file, mask);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -295,14 +286,7 @@ static inline void fsnotify_close(struct file *file)
|
|||
*/
|
||||
static inline void fsnotify_xattr(struct dentry *dentry)
|
||||
{
|
||||
struct inode *inode = dentry->d_inode;
|
||||
__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);
|
||||
fsnotify_dentry(dentry, FS_ATTRIB);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -311,7 +295,6 @@ static inline void fsnotify_xattr(struct dentry *dentry)
|
|||
*/
|
||||
static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
|
||||
{
|
||||
struct inode *inode = dentry->d_inode;
|
||||
__u32 mask = 0;
|
||||
|
||||
if (ia_valid & ATTR_UID)
|
||||
|
|
@ -332,13 +315,8 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
|
|||
if (ia_valid & ATTR_MODE)
|
||||
mask |= FS_ATTRIB;
|
||||
|
||||
if (mask) {
|
||||
if (S_ISDIR(inode->i_mode))
|
||||
mask |= FS_ISDIR;
|
||||
|
||||
fsnotify_parent(NULL, dentry, mask);
|
||||
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
|
||||
}
|
||||
if (mask)
|
||||
fsnotify_dentry(dentry, mask);
|
||||
}
|
||||
|
||||
#endif /* _LINUX_FS_NOTIFY_H */
|
||||
|
|
|
|||
|
|
@ -47,18 +47,18 @@
|
|||
#define FS_OPEN_PERM 0x00010000 /* open event in an permission hook */
|
||||
#define FS_ACCESS_PERM 0x00020000 /* access event in a permissions hook */
|
||||
#define FS_OPEN_EXEC_PERM 0x00040000 /* open/exec event in a permission hook */
|
||||
#define FS_DIR_MODIFY 0x00080000 /* Directory entry was modified */
|
||||
|
||||
#define FS_EXCL_UNLINK 0x04000000 /* do not send events if object is unlinked */
|
||||
#define FS_ISDIR 0x40000000 /* event occurred against dir */
|
||||
#define FS_IN_ONESHOT 0x80000000 /* only send event once */
|
||||
|
||||
#define FS_DN_RENAME 0x10000000 /* file renamed */
|
||||
#define FS_DN_MULTISHOT 0x20000000 /* dnotify multishot */
|
||||
|
||||
/* This inode cares about things that happen to its children. Always set for
|
||||
* dnotify and inotify. */
|
||||
#define FS_EVENT_ON_CHILD 0x08000000
|
||||
|
||||
#define FS_DN_RENAME 0x10000000 /* file renamed */
|
||||
#define FS_DN_MULTISHOT 0x20000000 /* dnotify multishot */
|
||||
#define FS_ISDIR 0x40000000 /* event occurred against dir */
|
||||
#define FS_IN_ONESHOT 0x80000000 /* only send event once */
|
||||
|
||||
#define FS_MOVE (FS_MOVED_FROM | FS_MOVED_TO)
|
||||
|
||||
/*
|
||||
|
|
@ -67,7 +67,8 @@
|
|||
* The watching parent may get an FS_ATTRIB|FS_EVENT_ON_CHILD event
|
||||
* when a directory entry inside a child subdir changes.
|
||||
*/
|
||||
#define ALL_FSNOTIFY_DIRENT_EVENTS (FS_CREATE | FS_DELETE | FS_MOVE)
|
||||
#define ALL_FSNOTIFY_DIRENT_EVENTS (FS_CREATE | FS_DELETE | FS_MOVE | \
|
||||
FS_DIR_MODIFY)
|
||||
|
||||
#define ALL_FSNOTIFY_PERM_EVENTS (FS_OPEN_PERM | FS_ACCESS_PERM | \
|
||||
FS_OPEN_EXEC_PERM)
|
||||
|
|
@ -133,8 +134,7 @@ struct fsnotify_ops {
|
|||
*/
|
||||
struct fsnotify_event {
|
||||
struct list_head list;
|
||||
/* inode may ONLY be dereferenced during handle_event(). */
|
||||
struct inode *inode; /* either the inode the event happened to or its parent */
|
||||
unsigned long objectid; /* identifier for queue merges */
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -213,10 +213,36 @@ struct fsnotify_group {
|
|||
};
|
||||
};
|
||||
|
||||
/* when calling fsnotify tell it if the data is a path or inode */
|
||||
#define FSNOTIFY_EVENT_NONE 0
|
||||
#define FSNOTIFY_EVENT_PATH 1
|
||||
#define FSNOTIFY_EVENT_INODE 2
|
||||
/* When calling fsnotify tell it if the data is a path or inode */
|
||||
enum fsnotify_data_type {
|
||||
FSNOTIFY_EVENT_NONE,
|
||||
FSNOTIFY_EVENT_PATH,
|
||||
FSNOTIFY_EVENT_INODE,
|
||||
};
|
||||
|
||||
static inline const struct inode *fsnotify_data_inode(const void *data,
|
||||
int data_type)
|
||||
{
|
||||
switch (data_type) {
|
||||
case FSNOTIFY_EVENT_INODE:
|
||||
return data;
|
||||
case FSNOTIFY_EVENT_PATH:
|
||||
return d_inode(((const struct path *)data)->dentry);
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline const struct path *fsnotify_data_path(const void *data,
|
||||
int data_type)
|
||||
{
|
||||
switch (data_type) {
|
||||
case FSNOTIFY_EVENT_PATH:
|
||||
return data;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
enum fsnotify_obj_type {
|
||||
FSNOTIFY_OBJ_TYPE_INODE,
|
||||
|
|
@ -351,9 +377,10 @@ struct fsnotify_mark {
|
|||
/* called from the vfs helpers */
|
||||
|
||||
/* main fsnotify call to send events */
|
||||
extern int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
|
||||
const struct qstr *name, u32 cookie);
|
||||
extern int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask);
|
||||
extern int fsnotify(struct inode *to_tell, __u32 mask, const void *data,
|
||||
int data_type, const struct qstr *name, u32 cookie);
|
||||
extern int fsnotify_parent(struct dentry *dentry, __u32 mask, const void *data,
|
||||
int data_type);
|
||||
extern void __fsnotify_inode_delete(struct inode *inode);
|
||||
extern void __fsnotify_vfsmount_delete(struct vfsmount *mnt);
|
||||
extern void fsnotify_sb_delete(struct super_block *sb);
|
||||
|
|
@ -500,21 +527,22 @@ extern void fsnotify_finish_user_wait(struct fsnotify_iter_info *iter_info);
|
|||
extern bool fsnotify_prepare_user_wait(struct fsnotify_iter_info *iter_info);
|
||||
|
||||
static inline void fsnotify_init_event(struct fsnotify_event *event,
|
||||
struct inode *inode)
|
||||
unsigned long objectid)
|
||||
{
|
||||
INIT_LIST_HEAD(&event->list);
|
||||
event->inode = inode;
|
||||
event->objectid = objectid;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static inline int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is,
|
||||
const struct qstr *name, u32 cookie)
|
||||
static inline int fsnotify(struct inode *to_tell, __u32 mask, const void *data,
|
||||
int data_type, const struct qstr *name, u32 cookie)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask)
|
||||
static inline int fsnotify_parent(struct dentry *dentry, __u32 mask,
|
||||
const void *data, int data_type)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue