Skip to content

kernfs: Add inotify IN_DELETE_SELF, IN_IGNORED support

T.J. Mercier cgroups driver-core linux-fsdevel linux-kselftest lkml 5 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest3 patches 0 repliesNew
  2. v43 patches 15 repliesSuperseded
  3. v33 patches 11 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v23 patches12 repliesSuperseded
v13 patches2 repliesSuperseded

Changes in v5 from the cover letter

Add comment about inotify, and fanotify limitataions per Tejun Add Tejun's Ack to new patch 2
Fix circular locking reported by syzbot in patch 2
https://lore.kernel.org/all/CABdmKX3jMS5ha2s5FMpnAMW0c9+Wmpmyc+8=D-24KyhVjBJvYg@mail.gmail.com/
Add Tested-by: for syzbot as requested

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3kernfs: Don't set_nlink for directories being removedfs/kernfs/dir.c fs/kernfs/inode.c+3 -10 replies
2/3kernfs: Send IN_DELETE_SELF and IN_IGNOREDfs/kernfs/dir.c+50 -40 replies
3/3selftests: memcg: Add tests for IN_DELETE_SELF and IN_IGNOREDtools/testing/selftests/cgroup/test_memcontrol.c+112 -00 replies

Reviews trailers per patch

2 of 3 patches have a Reviewed-by or Acked-by.

Patch[email protected]Tejun HeoAmir Goldstein
1/3
2/3T-b A-b
3/3A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v5 thread

Cover letter [PATCH v5 0/3] kernfs: Add inotify IN_DELETE_SELF, IN_IGNORED support

This series adds support for IN_DELETE_SELF and IN_IGNORED inotify events to kernfs files and directories.

Currently, kernfs (used by cgroup and others) supports IN_MODIFY events but fails to notify watchers when the file is removed (e.g. during cgroup destruction). This forces userspace monitors to maintain resource intensive side-channels like pidfds, procfs polling, or redundant directory watches to detect when a cgroup dies and a watched file is removed.

By generating IN_DELETE_SELF events on destruction, we allow watchers to rely on a single watch descriptor for the entire lifecycle of the monitored file, reducing resource usage (file descriptors, CPU cycles) and complexity in userspace.

The series is structured as follows:
Patch 1 preemptively addresses a race to set/clear i_nlink that would
arise in patch 2.
Patch 2 implements the logic to generate DELETE_SELF and IGNORED events
on file / dir removal.
Patch 3 adds selftests to verify the new behavior.

---
Changes in v5:
Add comment about inotify, and fanotify limitataions per Tejun Add Tejun's Ack to new patch 2
Fix circular locking reported by syzbot in patch 2
https://lore.kernel.org/all/CABdmKX3jMS5ha2s5FMpnAMW0c9+Wmpmyc+8=D-24KyhVjBJvYg@mail.gmail.com/
Add Tested-by: for syzbot as requested

Changes in v4:
Clear inode i_nlink upon kernfs removal instead of calling fsnotify from kernfs per Jan. This adds support for directories. Abandon support for files removed from vfs_writes.
Add selftest for directory watch per Amir.
Add Amir's Ack to selftests.

Changes in v3:
Remove parent IN_DELETE notification per Amir.
Refactored kernfs_notify_workfn to avoid grabbing parent when unnecessary for DELETE events as a result.
Use notify_event for fsnotify_inode call per Amir Initialize memcg pointers to NULL in selftests
Add Amir's Ack
Add Tejun's Acks to the series

Changes in v2:
Remove unused variables from new selftests per kernel test robot Fix kernfs_type argument per Tejun
Inline checks for FS_MODIFY, FS_DELETE in kernfs_notify_workfn per Tejun

T.J. Mercier (3):
kernfs: Don't set_nlink for directories being removed
kernfs: Send IN_DELETE_SELF and IN_IGNORED
selftests: memcg: Add tests for IN_DELETE_SELF and IN_IGNORED

 fs/kernfs/dir.c                               |  56 ++++++++-
 fs/kernfs/inode.c                             |   2 +-
 .../selftests/cgroup/test_memcontrol.c        | 112 ++++++++++++++++++
 3 files changed, 165 insertions(+), 5 deletions(-)

base-commit: ba268514ea14b44570030e8ed2aef92a38679e85

Signature · 1 line
2.53.0.414.gf7e9f6c205-goog