inotify: do not coalesce rename events
PATCH v2 1/1 inotify: do not coalesce rename events
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.
--- fs/notify/inotify/inotify_fsnotify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/notify/inotify/inotify_fsnotify.c +1 -1
@@ -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) &&
Signature · 1 line
2.43.0
Quoted 18 lines · Hungyu Lin
inotify compares the mask, watch descriptor and name when coalescing adjacent unread events, but ignores their rename cookies. Distinct
IN_MOVED_FROMevents can therefore be coalesced, losing the cookie needed to match a laterIN_MOVED_TOevent.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 secondIN_MOVED_FROMis merged with the first, while theIN_MOVED_TOretains 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_FROMorIN_MOVED_TOevents, which carry the identity of their respective renames. Leave coalescing of other event types unchanged.
Quoted 4 lines
Fixes 63c882a05416 ("inotify: reimplement inotify using fsnotify")Suggested-by Amir Goldstein <[email protected]>Signed-off-by Hungyu Lin <[email protected]>
Quoted 20 lines
--- fs/notify/inotify/inotify_fsnotify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/notify/inotify/inotify_fsnotify.c +1
-2@@ -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
maintainerQuoted 19 lines · Amir Goldstein
Quoted 18 lines · Hungyu Lin
inotify compares the mask, watch descriptor and name when coalescing adjacent unread events, but ignores their rename cookies. Distinct
IN_MOVED_FROMevents can therefore be coalesced, losing the cookie needed to match a laterIN_MOVED_TOevent.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 secondIN_MOVED_FROMis merged with the first, while theIN_MOVED_TOretains 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_FROMorIN_MOVED_TOevents, which carry the identity of their respective renames. Leave coalescing of other event types unchanged.
Quoted 5 lines
Quoted 4 lines
Fixes 63c882a05416 ("inotify: reimplement inotify using fsnotify")Suggested-by Amir Goldstein <[email protected]>Signed-off-by Hungyu Lin <[email protected]>Reviewed-by Amir Goldstein <[email protected]>
Thanks Amir and ignore my comment on v1. I've added this to my tree.
Honza
Quoted 21 lines
Quoted 21 lines
--- fs/notify/inotify/inotify_fsnotify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/notify/inotify/inotify_fsnotify.c +1
-2@@ -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
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR