Re: [PATCH v2] inotify: do not coalesce rename events
From: Jan Kara
Date: Tue Nov 03 2026 - 08:09:34 EST
On Wed 28-10-26 05:07:21, Amir Goldstein wrote:
> On Tue, Oct 27, 2026 at 9:20 PM Hungyu Lin <dennylin0707@xxxxxxxxx> wrote:
> >
> > inotify compares the mask, watch descriptor and name when coalescing
> > adjacent unread events, but ignores their rename cookies. Distinct
> > IN_MOVED_FROM events can therefore be coalesced, losing the cookie needed
> > to match a later IN_MOVED_TO event.
> >
> > For example, watch two directories with IN_MOVE. Move an entry from the
> > first directory into an unwatched directory, recreate it under the same
> > name, then move it from the first directory into the second watched
> > directory before reading the events. The second IN_MOVED_FROM is merged
> > with the first, while the IN_MOVED_TO retains the second rename's cookie.
> > Userspace can no longer pair the second rename's events.
> >
> > The original inotify implementation compared cookies before coalescing.
> > The fsnotify conversion lost this comparison. Do not coalesce
> > IN_MOVED_FROM or IN_MOVED_TO events, which carry the identity of their
> > respective renames. Leave coalescing of other event types unchanged.
> >
> > Fixes: 63c882a05416 ("inotify: reimplement inotify using fsnotify")
> > Cc: stable@xxxxxxxxxxxxxxx
> > Suggested-by: Amir Goldstein <amir73il@xxxxxxxxx>
> > Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
> Reviewed-by: Amir Goldstein <amir73il@xxxxxxxxx>
Thanks Amir and ignore my comment on v1. I've added this to my tree.
Honza
>
> > ---
> > fs/notify/inotify/inotify_fsnotify.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
> > index 7c326ec2e8a8..6e3af6452dcc 100644
> > --- a/fs/notify/inotify/inotify_fsnotify.c
> > +++ b/fs/notify/inotify/inotify_fsnotify.c
> > @@ -36,7 +36,7 @@ static bool event_compare(struct fsnotify_event *old_fsn,
> >
> > old = INOTIFY_E(old_fsn);
> > new = INOTIFY_E(new_fsn);
> > - if (old->mask & FS_IN_IGNORED)
> > + if (old->mask & (FS_IN_IGNORED | FS_MOVE))
> > return false;
> > if ((old->mask == new->mask) &&
> > (old->wd == new->wd) &&
> > --
> > 2.43.0
> >
--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR