mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] inotify: do not coalesce events with different rename cookies
@ 2026-10-25 23:22 Hungyu Lin
  0 siblings, 0 replies; only message in thread
From: Hungyu Lin @ 2026-10-25 23:22 UTC (permalink / raw)
  To: Jan Kara
  Cc: Amir Goldstein, linux-fsdevel, linux-kernel, stable, dennylin0707

inotify compares the mask, watch descriptor and name when coalescing
adjacent unread events, but ignores their rename cookies. Distinct
renames can therefore lose an event even with IN_ALL_EVENTS.

For example, prepare two files in an unwatched staging directory and
rename each onto the same pathname in a watched destination directory
before reading the events. Only the first IN_MOVED_TO event is retained,
although the two renames have different cookies. Similarly, coalescing
distinct IN_MOVED_FROM events can discard the cookie needed to match a
subsequent IN_MOVED_TO event.

The original inotify implementation compared cookies before coalescing.
The fsnotify conversion lost this comparison. Compare sync_cookie as well
to preserve distinct rename events, while retaining coalescing for
ordinary events with zero cookies.

Fixes: 63c882a05416 ("inotify: reimplement inotify using fsnotify")
Cc: stable@vger.kernel.org
Signed-off-by: Hungyu Lin <dennylin0707@gmail.com>
---
 fs/notify/inotify/inotify_fsnotify.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
index 7c326ec2e8a8..6456d9c0e408 100644
--- a/fs/notify/inotify/inotify_fsnotify.c
+++ b/fs/notify/inotify/inotify_fsnotify.c
@@ -40,6 +40,7 @@ static bool event_compare(struct fsnotify_event *old_fsn,
 		return false;
 	if ((old->mask == new->mask) &&
 	    (old->wd == new->wd) &&
+	    (old->sync_cookie == new->sync_cookie) &&
 	    (old->name_len == new->name_len) &&
 	    (!old->name_len || !strcmp(old->name, new->name)))
 		return true;
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-25 23:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-25 23:22 [PATCH] inotify: do not coalesce events with different rename cookies Hungyu Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®