Skip to content

Commit 9bd5a84

Browse files
amir73ilgregkh
authored andcommitted
fanotify: merge duplicate events on parent and child
[ Upstream commit f367a62 ] With inotify, when a watch is set on a directory and on its child, an event on the child is reported twice, once with wd of the parent watch and once with wd of the child watch without the filename. With fanotify, when a watch is set on a directory and on its child, an event on the child is reported twice, but it has the exact same information - either an open file descriptor of the child or an encoded fid of the child. The reason that the two identical events are not merged is because the object id used for merging events in the queue is the child inode in one event and parent inode in the other. For events with path or dentry data, use the victim inode instead of the watched inode as the object id for event merging, so that the event reported on parent will be merged with the event reported on the child. Link: https://lore.kernel.org/r/20200319151022.31456-9-amir73il@gmail.com Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 4638e0f commit 9bd5a84

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

fs/notify/fanotify/fanotify.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,12 @@ struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group,
314314
if (!event)
315315
goto out;
316316
init: __maybe_unused
317-
fsnotify_init_event(&event->fse, (unsigned long)inode);
317+
/*
318+
* Use the victim inode instead of the watching inode as the id for
319+
* event queue, so event reported on parent is merged with event
320+
* reported on child when both directory and child watches exist.
321+
*/
322+
fsnotify_init_event(&event->fse, (unsigned long)id);
318323
event->mask = mask;
319324
if (FAN_GROUP_FLAG(group, FAN_REPORT_TID))
320325
event->pid = get_pid(task_pid(current));

0 commit comments

Comments
 (0)