diff options
author | Amir Goldstein <amir73il@gmail.com> | 2020-07-16 10:42:19 +0200 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2020-07-27 21:24:51 +0200 |
commit | 62cb0af4cea871e80015dd45b200033002f23a95 (patch) | |
tree | a4a9ee6902925738f606e40a887bb3dd1a412c85 /fs/notify | |
parent | fanotify: no external fh buffer in fanotify_name_event (diff) | |
download | linux-62cb0af4cea871e80015dd45b200033002f23a95.tar.xz linux-62cb0af4cea871e80015dd45b200033002f23a95.zip |
dnotify: report both events on parent and child with single callback
For some events (e.g. DN_ATTRIB on sub-directory) fsnotify may call
dnotify_handle_event() once for watching parent and once again for
the watching sub-directory.
Do the same thing with a single callback instead of two callbacks when
marks iterator contains both inode and child entries.
Link: https://lore.kernel.org/r/20200716084230.30611-12-amir73il@gmail.com
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/notify')
-rw-r--r-- | fs/notify/dnotify/dnotify.c | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c index 2d2eadfb5186..ca78d3f78da8 100644 --- a/fs/notify/dnotify/dnotify.c +++ b/fs/notify/dnotify/dnotify.c @@ -70,26 +70,15 @@ static void dnotify_recalc_inode_mask(struct fsnotify_mark *fsn_mark) * destroy the dnotify struct if it was not registered to receive multiple * events. */ -static int dnotify_handle_event(struct fsnotify_group *group, u32 mask, - const void *data, int data_type, - struct inode *dir, - const struct qstr *file_name, u32 cookie, - struct fsnotify_iter_info *iter_info) +static void dnotify_one_event(struct fsnotify_group *group, u32 mask, + struct fsnotify_mark *inode_mark) { - struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info); struct dnotify_mark *dn_mark; struct dnotify_struct *dn; struct dnotify_struct **prev; struct fown_struct *fown; __u32 test_mask = mask & ~FS_EVENT_ON_CHILD; - /* not a dir, dnotify doesn't care */ - if (!dir && !(mask & FS_ISDIR)) - return 0; - - if (WARN_ON(fsnotify_iter_vfsmount_mark(iter_info))) - return 0; - dn_mark = container_of(inode_mark, struct dnotify_mark, fsn_mark); spin_lock(&inode_mark->lock); @@ -111,6 +100,33 @@ static int dnotify_handle_event(struct fsnotify_group *group, u32 mask, } spin_unlock(&inode_mark->lock); +} + +static int dnotify_handle_event(struct fsnotify_group *group, u32 mask, + const void *data, int data_type, + struct inode *dir, + const struct qstr *file_name, u32 cookie, + struct fsnotify_iter_info *iter_info) +{ + struct fsnotify_mark *inode_mark = fsnotify_iter_inode_mark(iter_info); + struct fsnotify_mark *child_mark = fsnotify_iter_child_mark(iter_info); + + /* not a dir, dnotify doesn't care */ + if (!dir && !(mask & FS_ISDIR)) + return 0; + + if (WARN_ON(fsnotify_iter_vfsmount_mark(iter_info))) + return 0; + + /* + * Some events can be sent on both parent dir and subdir marks + * (e.g. DN_ATTRIB). If both parent dir and subdir are watching, + * report the event once to parent dir and once to subdir. + */ + if (inode_mark) + dnotify_one_event(group, mask, inode_mark); + if (child_mark) + dnotify_one_event(group, mask, child_mark); return 0; } |