feat(fs): implement inotify filesystem event notification - #2164
Open
sparkzky wants to merge 1 commit into
Open
Conversation
Member
|
needs to rebase |
sparkzky
force-pushed
the
feat/inotify
branch
2 times, most recently
from
August 1, 2026 06:38
1efd172 to
8fad46f
Compare
Implements inotify (issue DragonOS-Community#2151): the fsnotify core notification layer, the inotify pseudo-device, 4 syscalls (init/init1/add_watch/rm_watch), and VFS write-path hooks for all standard events (create/delete/move/ modify/access/close/attrib/self events). Architecture: - fsnotify/ unified dispatch layer: global inode_id -> Weak<mark> index, TOTAL_WATCHES atomic fast-path (zero cost when no watches), lock-family separation (global index lock / events lock / wd lock never nested). - inotify.rs device: InotifyInode implements IndexNode + PollableInode, epoll-integrated via LockedEPItemLinkedList, exact inotify_event layout (name field aligned to sizeof(inotify_event)=16, matching Linux ABI). - VFS hooks placed in syscall-core layer (vcore/open/rename_utils/...), NOT per-filesystem: single anchor covers ext4/tmpfs/overlayfs/fuse. Hooks fire only after success and never alter syscall return values. Review fixes incorporated: - Directory watches receive child content events (issue B): IN_MODIFY/ ACCESS/OPEN/CLOSE delivered to parent dir watch with child name. - Guard DELETE_SELF on hardlink unlink/rename-over: only emit when i_nlink reaches 0, matching Linux fsnotify_link_count() semantics. - Fix MountFSInode downcast: MountFSInode::as_any_ref() returns the inner inode's Any, so downcast_ref::<MountFSInode>() always fails. Use downcast_arc instead so parent resolution works for child content event delivery. - TOTAL_WATCHES counter: avoid double-decrement / double-increment. Test: user/apps/tests/dunitest/suites/normal/inotify_dir_watch.cc covers directory-watch child content events and self-watch MODIFY. Design doc: docs/kernel/filesystem/inotify.md Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements inotify (issue #2151): filesystem event notification with
inotify_init1/inotify_add_watch/inotify_rm_watch/read, the full standard event set, epoll integration, and exactinotify_eventABI.Design doc:
docs/kernel/filesystem/inotify.md. Behavior targets Linux 6.6.Architecture (3 layers)
fs/notify/-style): globalinode_id -> Weak<mark>index,TOTAL_WATCHESatomic fast-path (zero cost when no watches), lock-family separation (global index lock / events lock / wd lock never nested). Hooks fire only after success and never alter syscall return values.inotify.rs):InotifyInodeimplementsIndexNode + PollableInode, epoll-integrated viaLockedEPItemLinkedList, exactinotify_eventlayout (name field aligned tosizeof(inotify_event)=16, matching the Linux 6.6 ABI).vcore/open/rename_utils/...), not per-filesystem: a single anchor covers ext4/tmpfs/overlayfs/fuse.What this PR adds beyond the initial implementation
The initial implementation was put through a 3-way adversarial review (independent reviewers) + independent verification. This PR includes both the feature and the resulting fixes:
Directory watches now receive child content events (the primary inotify use case, e.g.
inotifywait -m /dir). Previously only namespace events (create/delete/move) reached directory watches;IN_MODIFY/ACCESS/OPEN/CLOSEon children were silently dropped. Resolved by snapshotting the parent dir + child name once atFileconstruction (gated byhas_any_watchfor zero cost when unused) and routing content events to both the parent (with name) and self watch. This also makesIN_EXCL_UNLINKeffective.Other review fixes (all verified):
TOTAL_WATCHESdouble-count onadd_watch(broke the no-watch fast path).add_watchTOCTOU: concurrent same-inode adds created duplicate marks.IN_EXCL_UNLINKpolarity was inverted.fallocate: restored theoffset+lenoverflow guard removed during theIN_MODIFYrefactor.renameoverwriting an existing target now emitsIN_DELETE/IN_DELETE_SELF(was a ghost-watch leak).RENAME_EXCHANGEnow emits the full 4 namespace events + 2MOVE_SELFwith two cookies.Testing
normal/inotify_dir_watch(directory-watch child content events + self-watch sanity), added to the whitelist so CI runs it.make kernel).docs/impl-notes/): rename-after-open yields a stale parent snapshot (EXCL_UNLINK covers unlink);IN_ATTRIB-to-parent via fd-based setattr is not yet wired; unmount does not emitIN_UNMOUNT(watch reclaims on fd close).Checklist
make kernelcompiles