Commit b96ead47 authored by Eric Paris's avatar Eric Paris

fsnotify: send struct file when sending events to parents when possible

fanotify needs a path in order to open an fd to the object which changed.
Currently notifications to inode's parents are done using only the inode.
For some parental notification we have the entire file, send that so
fanotify can use it.
Signed-off-by: default avatarEric Paris <eparis@redhat.com>
parent bce8d165
...@@ -77,13 +77,16 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode) ...@@ -77,13 +77,16 @@ void __fsnotify_update_child_dentry_flags(struct inode *inode)
} }
/* Notify this dentry's parent about a child's events. */ /* Notify this dentry's parent about a child's events. */
void __fsnotify_parent(struct dentry *dentry, __u32 mask) void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
{ {
struct dentry *parent; struct dentry *parent;
struct inode *p_inode; struct inode *p_inode;
bool send = false; bool send = false;
bool should_update_children = false; bool should_update_children = false;
if (file)
dentry = file->f_path.dentry;
if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED)) if (!(dentry->d_flags & DCACHE_FSNOTIFY_PARENT_WATCHED))
return; return;
...@@ -114,8 +117,12 @@ void __fsnotify_parent(struct dentry *dentry, __u32 mask) ...@@ -114,8 +117,12 @@ void __fsnotify_parent(struct dentry *dentry, __u32 mask)
* specifies these are events which came from a child. */ * specifies these are events which came from a child. */
mask |= FS_EVENT_ON_CHILD; mask |= FS_EVENT_ON_CHILD;
fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE, if (file)
dentry->d_name.name, 0); fsnotify(p_inode, mask, file, FSNOTIFY_EVENT_FILE,
dentry->d_name.name, 0);
else
fsnotify(p_inode, mask, dentry->d_inode, FSNOTIFY_EVENT_INODE,
dentry->d_name.name, 0);
dput(parent); dput(parent);
} }
......
...@@ -29,9 +29,14 @@ static inline void fsnotify_d_instantiate(struct dentry *entry, ...@@ -29,9 +29,14 @@ static inline void fsnotify_d_instantiate(struct dentry *entry,
} }
/* Notify this dentry's parent about a child's events. */ /* Notify this dentry's parent about a child's events. */
static inline void fsnotify_parent(struct dentry *dentry, __u32 mask) static inline void fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
{ {
__fsnotify_parent(dentry, mask); BUG_ON(file && dentry);
if (file)
dentry = file->f_path.dentry;
__fsnotify_parent(file, dentry, mask);
inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name); inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
} }
...@@ -124,7 +129,7 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) ...@@ -124,7 +129,7 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
if (isdir) if (isdir)
mask |= FS_IN_ISDIR; mask |= FS_IN_ISDIR;
fsnotify_parent(dentry, mask); fsnotify_parent(NULL, dentry, mask);
} }
/* /*
...@@ -185,8 +190,7 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) ...@@ -185,8 +190,7 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
*/ */
static inline void fsnotify_access(struct file *file) static inline void fsnotify_access(struct file *file)
{ {
struct dentry *dentry = file->f_path.dentry; struct inode *inode = file->f_path.dentry->d_inode;
struct inode *inode = dentry->d_inode;
__u32 mask = FS_ACCESS; __u32 mask = FS_ACCESS;
if (S_ISDIR(inode->i_mode)) if (S_ISDIR(inode->i_mode))
...@@ -194,7 +198,7 @@ static inline void fsnotify_access(struct file *file) ...@@ -194,7 +198,7 @@ static inline void fsnotify_access(struct file *file)
inotify_inode_queue_event(inode, mask, 0, NULL, NULL); inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
fsnotify_parent(dentry, mask); fsnotify_parent(file, NULL, mask);
fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
} }
...@@ -203,8 +207,7 @@ static inline void fsnotify_access(struct file *file) ...@@ -203,8 +207,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)
{ {
struct dentry *dentry = file->f_path.dentry; struct inode *inode = file->f_path.dentry->d_inode;
struct inode *inode = dentry->d_inode;
__u32 mask = FS_MODIFY; __u32 mask = FS_MODIFY;
if (S_ISDIR(inode->i_mode)) if (S_ISDIR(inode->i_mode))
...@@ -212,7 +215,7 @@ static inline void fsnotify_modify(struct file *file) ...@@ -212,7 +215,7 @@ static inline void fsnotify_modify(struct file *file)
inotify_inode_queue_event(inode, mask, 0, NULL, NULL); inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
fsnotify_parent(dentry, mask); fsnotify_parent(file, NULL, mask);
fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
} }
...@@ -221,8 +224,7 @@ static inline void fsnotify_modify(struct file *file) ...@@ -221,8 +224,7 @@ static inline void fsnotify_modify(struct file *file)
*/ */
static inline void fsnotify_open(struct file *file) static inline void fsnotify_open(struct file *file)
{ {
struct dentry *dentry = file->f_path.dentry; struct inode *inode = file->f_path.dentry->d_inode;
struct inode *inode = dentry->d_inode;
__u32 mask = FS_OPEN; __u32 mask = FS_OPEN;
if (S_ISDIR(inode->i_mode)) if (S_ISDIR(inode->i_mode))
...@@ -230,7 +232,7 @@ static inline void fsnotify_open(struct file *file) ...@@ -230,7 +232,7 @@ static inline void fsnotify_open(struct file *file)
inotify_inode_queue_event(inode, mask, 0, NULL, NULL); inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
fsnotify_parent(dentry, mask); fsnotify_parent(file, NULL, mask);
fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
} }
...@@ -239,8 +241,7 @@ static inline void fsnotify_open(struct file *file) ...@@ -239,8 +241,7 @@ static inline void fsnotify_open(struct file *file)
*/ */
static inline void fsnotify_close(struct file *file) static inline void fsnotify_close(struct file *file)
{ {
struct dentry *dentry = file->f_path.dentry; struct inode *inode = file->f_path.dentry->d_inode;
struct inode *inode = dentry->d_inode;
fmode_t mode = file->f_mode; fmode_t mode = file->f_mode;
__u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE; __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
...@@ -249,7 +250,7 @@ static inline void fsnotify_close(struct file *file) ...@@ -249,7 +250,7 @@ static inline void fsnotify_close(struct file *file)
inotify_inode_queue_event(inode, mask, 0, NULL, NULL); inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
fsnotify_parent(dentry, mask); fsnotify_parent(file, NULL, mask);
fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
} }
...@@ -266,7 +267,7 @@ static inline void fsnotify_xattr(struct dentry *dentry) ...@@ -266,7 +267,7 @@ static inline void fsnotify_xattr(struct dentry *dentry)
inotify_inode_queue_event(inode, mask, 0, NULL, NULL); inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
fsnotify_parent(dentry, mask); fsnotify_parent(NULL, dentry, mask);
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
} }
...@@ -302,7 +303,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid) ...@@ -302,7 +303,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
mask |= FS_IN_ISDIR; mask |= FS_IN_ISDIR;
inotify_inode_queue_event(inode, mask, 0, NULL, NULL); inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
fsnotify_parent(dentry, mask); fsnotify_parent(NULL, dentry, mask);
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
} }
} }
......
...@@ -259,7 +259,7 @@ struct fsnotify_mark_entry { ...@@ -259,7 +259,7 @@ struct fsnotify_mark_entry {
/* main fsnotify call to send events */ /* main fsnotify call to send events */
extern void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is, extern void fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
const char *name, u32 cookie); const char *name, u32 cookie);
extern void __fsnotify_parent(struct dentry *dentry, __u32 mask); extern void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask);
extern void __fsnotify_inode_delete(struct inode *inode); extern void __fsnotify_inode_delete(struct inode *inode);
extern u32 fsnotify_get_cookie(void); extern u32 fsnotify_get_cookie(void);
...@@ -367,7 +367,7 @@ static inline void fsnotify(struct inode *to_tell, __u32 mask, void *data, int d ...@@ -367,7 +367,7 @@ static inline void fsnotify(struct inode *to_tell, __u32 mask, void *data, int d
const char *name, u32 cookie) const char *name, u32 cookie)
{} {}
static inline void __fsnotify_parent(struct dentry *dentry, __u32 mask) static inline void __fsnotify_parent(struct file *file, struct dentry *dentry, __u32 mask)
{} {}
static inline void __fsnotify_inode_delete(struct inode *inode) static inline void __fsnotify_inode_delete(struct inode *inode)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment