Linux Security Modules development
 help / color / mirror / Atom feed
* [PATCH v4 00/11] vfs: add inode iteration methods
@ 2026-11-25  9:11 Huang Shijie
  2026-11-25  9:11 ` [PATCH v4 01/11] vfs: add sb_inode_iter_next() Huang Shijie
                   ` (11 more replies)
  0 siblings, 12 replies; 15+ messages in thread
From: Huang Shijie @ 2026-11-25  9:11 UTC (permalink / raw)
  To: viro, brauner, jack, hch, agruenba, mic, axboe
  Cc: gnoack, paul, jmorris, serge, legion, aleksa, libaokun, ebiggers,
	djwong, sandeen, zhongyuan, fangbaoshun, yingzhiwei, wujianyong,
	shijie8, linux-fsdevel, linux-kernel, linux-block, gfs2,
	linux-security-module, Huang Shijie

This series adds a superblock inode iterator and converts the open-coded
sb->s_inodes walks in the VFS to it.  The design follows the cursor-based
construct proposed by Christian Brauner:

  https://lore.kernel.org/all/20261120-mitverantwortlich-drehbaren-kantholz-241300d20168@brauner/

and is the same direction as Dave Chinner's patch set:

  "vfs: improving inode cache iteration scalability"
  https://lore.kernel.org/all/20241002014017.3801899-1-david@fromorbit.com/

The caller owns the iterator state and drives the walk itself:

  CLASS(sb_inode_iter, iter)(sb, eligible, priv, flags);
  while ((inode = sb_inode_iter_next(&iter)))
          /* do stuff */;

The lock does not span iterations.  sb_inode_iter_next() takes
sb->s_inode_list_lock, takes a reference on the next inode, drops the lock
again and hands the inode out; the reference is what keeps the cursor on
sb->s_inodes so that the next call can resume from it.  As the iterator
is a cleanup class, a caller that breaks out early does not have to call
sb_inode_iter_end() explicitly.

Two optional channels let a caller keep its own state instead of filling in
a shared context:

  - iter->eligible is called with inode->i_lock held, so that a caller can
    reject an inode before a reference is paid for.

  - iter->status carries an error out of the walk.  Setting it to a
    negative value makes sb_inode_iter_next() return NULL.

Most callers just want a referenced inode and use no flags at all.  Three
flags cover the walks that need something else:

  - %INO_ITER_F_REFERENCED restricts the walk to inodes that still have a
    reference, preserving the "only handle referenced inodes" rule of
    landlock's sb-delete walk.

  - %INO_ITER_F_NOREF hands out only inodes whose reference count has
    already reached zero, and %INO_ITER_F_NOIGET suppresses the reference.
    Neither keeps the inode alive, so the caller has to make the inode
    unclaimable itself.

A second, internal iterator covers the walks that must not take a
reference at all:

  static inline int sb_inode_iter_locked(struct super_block *sb,
                                         int (*iter_fn)(struct inode *,
                                                        void *),
                                         void *priv);

  - It keeps sb->s_inode_list_lock held for the whole walk and takes no
    inode reference, so @iter_fn only has an existence guarantee: it must
    not block, and it must do its own inode state checks and its own
    reference handling.  A callback returns a negative value to stop the
    walk with that error, and 0 to continue.

  - It lives in fs/internal.h as a static inline rather than being
    exported: it is a VFS internal facility, and the small callbacks
    inline into their callers.

  It serves the three walks that cannot use sb_inode_iter_next():

  - nr_blockdev_pages() is reached from si_meminfo(), which kdb calls, and
    the iput() that the referenced iterator would do can sleep.

  - remove_dquot_ref() has to scan I_NEW inodes as well, which the
    referenced iterator filters out; it only touches the quota pointers,
    and those have their own locking in dq_data_lock.

  - the generic_shutdown_super() poisoning loop has to touch every inode
    still on the list, including the I_NEW, I_FREEING and I_WILL_FREE
    ones that sb_inode_iter_next() filters out, and it must not bounce
    them through __iget()/iput(): the loop overwrites i_sb with
    VFS_PTR_POISON, and evict() dereferences i_sb->s_op on the way out.

  Patch 1 adds sb_inode_iter_next().
  Patch 2 adds sb_inode_iter_locked().
  Patch 3-5 convert the callers which cannot use referenced inodes
          (nr_blockdev_pages(), dquot removal and the
          generic_shutdown_super() poisoning loop).
  Patch 6-11 convert the remaining callers (inode eviction, sync_bdevs,
          drop_pagecache_sb, add_dquot_ref, landlock's hook_sb_delete
          and gfs2_evict_inodes()).


BTW:
  This series is based on v7.4-rc2, and applies on top of the last commit
  of that base, which is the small patch this series depends on:

      v7.4-rc2-22-ga02161f70fcf
      commit a02161f70fcf ("fs/drop_caches: skip filesystems without page cache writeback")

  That patch was posted as:
      https://lore.kernel.org/all/20260923070116.3226846-1-huangsj@hygon.cn/

v3-->v4:
   -the interface is redone as a caller-owned cursor, following Christian's
    sb_inode_iter construct: sb_inode_iter_next() returns a referenced
    inode with sb->s_inode_list_lock dropped, and the reference keeps the
    cursor on sb->s_inodes.  The callback-based interface of v3, with its
    ino_iter_fn and INO_ITER_RET_* return values, is gone.

   -the iterator is wrapped in a cleanup class, so a caller that breaks out
    of the walk does not have to call sb_inode_iter_end().

   -an inode can be rejected before a reference is paid for: @eligible is
    called with inode->i_lock held.

   -the error channel is now iter->status rather than a three-valued
    callback return.

   -super_iter_inodes() and super_iter_inodes_locked() are renamed to
    sb_inode_iter_next() and sb_inode_iter_locked(), and the latter stays
    in fs/internal.h for the three walks that must not take a reference.

   -evict_inodes() uses INO_ITER_F_NOREF | INO_ITER_F_NOIGET: it only
    takes inodes whose reference count has reached zero, pins each one by
    setting I_FREEING and dropping it from the LRU, and runs dispose_list()
    with the list lock dropped.

   v3: https://lore.kernel.org/all/20261120031305.3561045-1-huangsj@hygon.cn/
   v2: https://lore.kernel.org/all/20261113115702.586594-1-huangsj@hygon.cn/
   v1: https://lore.kernel.org/all/20261015093854.2082600-1-huangsj@hygon.cn/

Huang Shijie (11):
  vfs: add sb_inode_iter_next()
  vfs: add sb_inode_iter_locked()
  block: convert nr_blockdev_pages() to sb_inode_iter_locked()
  fs/quota: convert remove_dquot_ref() to sb_inode_iter_locked()
  fs: convert generic_shutdown_super() poison loop
  fs/inode: convert evict_inodes() to sb_inode_iter
  block: convert sync_bdevs() to sb_inode_iter
  fs/drop_caches: convert drop_pagecache_sb() to sb_inode_iter
  fs/quota: convert add_dquot_ref() to sb_inode_iter
  landlock: convert hook_sb_delete() to sb_inode_iter
  gfs2: convert gfs2_evict_inodes() to sb_inode_iter

 block/bdev.c                   |  58 ++++++----------
 fs/drop_caches.c               |  36 ++++------
 fs/gfs2/ops_fstype.c           |  26 ++-----
 fs/inode.c                     |  33 +++------
 fs/internal.h                  |  25 +++++++
 fs/quota/dquot.c               | 120 +++++++++++++++-----------------
 fs/super.c                     | 121 ++++++++++++++++++++++++++++++---
 include/linux/fs/super_types.h |  40 +++++++++++
 security/landlock/fs.c         |  67 +++++-------------
 9 files changed, 297 insertions(+), 229 deletions(-)

-- 
2.53.0



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2026-11-26 14:32 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  9:11 [PATCH v4 00/11] vfs: add inode iteration methods Huang Shijie
2026-11-25  9:11 ` [PATCH v4 01/11] vfs: add sb_inode_iter_next() Huang Shijie
2026-11-25  9:11 ` [PATCH v4 02/11] vfs: add sb_inode_iter_locked() Huang Shijie
2026-11-25  9:11 ` [PATCH v4 03/11] block: convert nr_blockdev_pages() to sb_inode_iter_locked() Huang Shijie
2026-11-25  9:11 ` [PATCH v4 04/11] fs/quota: convert remove_dquot_ref() " Huang Shijie
2026-11-25  9:11 ` [PATCH v4 05/11] fs: convert generic_shutdown_super() poison loop Huang Shijie
2026-11-25  9:11 ` [PATCH v4 06/11] fs/inode: convert evict_inodes() to sb_inode_iter Huang Shijie
2026-11-25  9:11 ` [PATCH v4 07/11] block: convert sync_bdevs() " Huang Shijie
2026-11-25  9:11 ` [PATCH v4 08/11] fs/drop_caches: convert drop_pagecache_sb() " Huang Shijie
2026-11-25  9:11 ` [PATCH v4 09/11] fs/quota: convert add_dquot_ref() " Huang Shijie
2026-11-25  9:11 ` [PATCH v4 10/11] landlock: convert hook_sb_delete() " Huang Shijie
2026-11-25  9:11 ` [PATCH v4 11/11] gfs2: convert gfs2_evict_inodes() " Huang Shijie
2026-11-25 22:25 ` [PATCH v4 00/11] vfs: add inode iteration methods Andreas Gruenbacher
2026-11-26 12:15   ` Huang Shijie
2026-11-26 14:32     ` Andreas Gruenbacher

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