vfs: add inode iteration methods
Subsystems (6)
v2 cover vfs: add inode iteration methods
This series adds two superblock inode iteration helpers:
super_iter_inodes()/super_iter_inodes_unsafe(), and converts the open-coded sb->s_inodes walks in the VFS to it. The design is based on Dave Chinner's patch set:
"vfs: improving inode cache iteration scalability"
https://lore.kernel.org/all/[email protected]/
About the two helpers:
int super_iter_inodes(struct super_block *sb,
struct inode_iter_context *ctx);
int super_iter_inodes_unsafe(struct super_block *sb,
struct inode_iter_context *ctx);
- super_iter_inodes() runs @ctx->iter_fn() with a referenced inode and with sb->s_inode_list_lock dropped, so the callback is free to block and to do whatever it wants with the inode except drop the reference the iterator holds.
It is exported because GFS2 can be built as a module.
- super_iter_inodes_unsafe() keeps sb->s_inode_list_lock and rcu_read_lock() held for the whole walk and takes no inode references at all. Its callback therefore only has an existence
guarantee: it must not block and must do its own inode state checks and its own reference handling.
It is internal to the VFS, being declared in fs/internal.h.
- %INO_ITER_F_REFERENCED additionally restricts the safe iterator to inodes that still have a reference. This preserves the "only handle referenced inodes" rule of landlock's sb-delete walk.
- @ctx->prev is the resume point of the unsafe iterator: a caller which has to drop the list lock in the middle of a walk stores the inode to continue from, and the next call starts after that inode instead of at the head.
Patch 1 adds the two iterators.
Patch 2 converts the callers that cannot use referenced inodes
(dquot removal, inode eviction, nr_blockdev_pages() and the generic_shutdown_super() poisoning loop) to super_iter_inodes_unsafe().
Patch 3 converts the remaining callers (sync_bdevs,
drop_pagecache_sb, gfs2_kill_sb, add_dquot_ref and landlock's hook_sb_delete).
BTW:
This patch set depends a small patch:
"fs/drop_caches: skip filesystems without fs writeback"
https://lkml.org/lkml/2026/9/23/675
v1-->v2:
-split the super_iter_inodes_unsafe from super_iter_inodes. -add ->eligible() before calling the __iget(). -others
v1: https://lore.kernel.org/all/[email protected]/
Huang Shijie (3):
vfs: add inode iteration methods
vfs: convert inode iterators to super_iter_inodes_unsafe()
vfs: convert sb->s_inodes iteration to super_iter_inodes()
block/bdev.c | 111 ++++++++++++------------ fs/drop_caches.c | 49 +++++------ fs/gfs2/ops_fstype.c | 33 +++---- fs/inode.c | 83 ++++++++++-------- fs/internal.h | 34 ++++++++ fs/quota/dquot.c | 149 +++++++++++++++++--------------- fs/super.c | 88 +++++++++++++++++-- include/linux/fs/super_types.h | 25 ++++++ security/landlock/fs.c | 153 +++++++++++++-------------------- 9 files changed, 413 insertions(+), 312 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/3 vfs: add inode iteration methods
Add two inode iteration methods:
super_iter_inodes_unsafe()/super_iter_inodes()
We use them to replace the explicit sb->s_inodes iteration, with the caller supplying an inode_iter_context which has the metadata needed in the interation.
The two iteration methods:
-- super_iter_inodes() runs @ctx->iter_fn() with a referenced
inode and with sb->s_inode_list_lock dropped, so the callback is free to block and to do whatever it wants with the inode except drop the reference the iterator holds. The iterator releases that one reference per inode itself, so the callback cannot leave a dangling inode behind. It is exported because filesystems built as modules need it.
-- super_iter_inodes_unsafe() keeps sb->s_inode_list_lock and
rcu_read_lock() held for the whole walk and takes no inode references at all. Its callback therefore only has an existence guarantee: it must not block and must do its own inode state checks and its own reference handling. It is internal to the VFS, being declared in fs/internal.h.
Both take a struct inode_iter_context carrying the per-caller state:
iter_fn the callback. Returns INO_ITER_RET_NEXT to go on
with the next inode, or INO_ITER_RET_ABORT to stop.
eligible optional filter, called only by the safe iterator,
from inside the inode's i_lock and before __iget(), so that an inode can be rejected without paying for a reference.
prev resume point. A caller of the unsafe iterator which
has to drop the list lock in the middle of a walk stores the inode to continue from here, and the next call starts after that inode instead of at the head.
flags INO_ITER_F_REFERENCED makes the safe iterator skip
inodes which have no reference, which is what hook_sb_delete() filters for today.
priv caller private data.
This patch only adds the methods; converting the callers over is left to the patches which follow.
--- fs/internal.h | 34 ++++++++++++++++++ fs/super.c | 65 ++++++++++++++++++++++++++++++++++ include/linux/fs/super_types.h | 25 +++++++++++++ 3 files changed, 124 insertions(+)
fs/internal.h +34 -0
@@ -139,6 +139,40 @@ struct super_block *user_get_super(dev_t, bool excl);void put_super (struct super_block *sb);extern bool mount_capable (struct fs_context *); +/* +* Unsafe iteration for internal VFS use only: +* @ctx->iter_fn runs in atomic context with only +* an inode existence guarantee, so it must not block +* and must perform its own inode state checks. +* +* Return INO_ITER_RET_ABORT if the iteration stops early. +* Return INO_ITER_RET_DONE if the iteration runs to the end. +*/ +static inline int super_iter_inodes_unsafe (struct super_block *sb, +struct inode_iter_context *ctx) +{ +struct inode *inode; +int ret =INO_ITER_RET_NEXT ; + +rcu_read_lock (); +spin_lock (&sb->s_inode_list_lock); + inode =list_prepare_entry (ctx->prev, &sb->s_inodes, i_sb_list); + +list_for_each_entry_continue (inode, &sb->s_inodes, i_sb_list) { + ret = ctx->iter_fn (inode, ctx); +if (ret ==INO_ITER_RET_ABORT ) +break ; + } +spin_unlock (&sb->s_inode_list_lock); +rcu_read_unlock (); + +/* Mark the end here */ +if (ret ==INO_ITER_RET_NEXT ) + ret =INO_ITER_RET_DONE ; + +return ret; +} +/* * Prepare superblock for changing its read-only state (i.e., either remount * read-write superblock read-only or vice versa). After this function returns
fs/super.c +65 -0
71 lines not on this page · raw message
include/linux/fs/super_types.h +25 -0
@@ -80,6 +80,31 @@ enum freeze_holder { FREEZE_EXCL = (1U << 3), }; +/* Inode iteration callback return values */ +#define INO_ITER_RET_DONE 0 +#define INO_ITER_RET_ABORT 1 +#define INO_ITER_RET_NEXT 2 + +/* Inode iteration control flags */ +/* Only iterate inodes that still have a reference. */ +#define INO_ITER_F_REFERENCED (1U << 0) + +struct inode_iter_context { +/* the hook for the iteration */ +int (*iter_fn)(struct inode *inode,struct inode_iter_context *ctx); + +/* the hook for the eligibility check, called before __iget() */ +bool (*eligible)(struct inode *inode,struct inode_iter_context *ctx); + +/* Save the temporary inode in a loop break */ +struct inode *prev; + +int flags; +void *priv; +}; + +int super_iter_inodes (struct super_block *sb,struct inode_iter_context *ctx); +struct super_operations {struct inode *(*alloc_inode)(struct super_block *sb);void (*destroy_inode)(struct inode *inode);
Signature · 1 line
2.53.0
Quoted 10 lines · Huang Shijie
fs/internal.h +10
-0+/* +* Unsafe iteration for internal VFS use only: +* @ctx->iter_fn runs in atomic context with only +* an inode existence guarantee, so it must not block +* and must perform its own inode state checks. +* +* Return INO_ITER_RET_ABORT if the iteration stops early. +* Return INO_ITER_RET_DONE if the iteration runs to the end. +*/ +static inline int super_iter_inodes_unsafe(struct super_block *sb,
fs/internal.h struct super_block *user_get_super(dev_t, bool excl); · line 161
Quoted 10 lines
fs/internal.h +10
-0+ struct inode_iter_context *ctx) +{ +struct inode *inode; +int ret =INO_ITER_RET_NEXT ; + +rcu_read_lock (); +spin_lock (&sb->s_inode_list_lock); + inode =list_prepare_entry (ctx->prev, &sb->s_inodes, i_sb_list); + +list_for_each_entry_continue (inode, &sb->s_inodes, i_sb_list) {
This is a really odd way to write a list iteration. I also don't see how the RCU lock is needed when you already hold the spinlock.
I honestly don't get this "iterator. It is trivial, the _unsafe is wrong naming. What is the point?
Quoted 5 lines
fs/super.c +5
-0+/** +* super_iter_inodes - iterate all the cached inodes on a superblock +* @sb: superblock to iterate +* @ctx: the context which has the metadata +*
fs/super.c static void super_wake(struct super_block *sb, unsigned int flag) · line 209
Quoted 10 lines
fs/super.c +10
-0+* This function iterates all cached inodes on a superblock that are not in +* the process of being initialised or torn down. It will run @ctx->iter_fn() +* with a valid, referenced inode, so it is safe for the caller to do +* anything it wants with the inode except drop the reference the iterator +* holds. +* +* Return INO_ITER_RET_DONE if the iteration runs to the end. +* Return other value if the iteration breaks. +*/ +int super_iter_inodes (struct super_block *sb,struct inode_iter_context *ctx)
This one makes a lot more sense, but the callback pattern is a bit annoying as it requires to stuff all information into the context. Im much of the core kernel we're slowly switching to an iterator model that allows the caller to keep the state. In this case something like
struct inode_iter_contex ctx = INODE_ITER_CTX_INIT;
while ((inode = sb_inode_iter()))) {
/* do stuff */
}which should be easily possibly with this model.
You probably also want to split the core iterator and switching each user into separate patches.
Quoted 15 lines · 在 Fri, Nov 13, 2026 at 04:23:40AM -0800,Christoph Hellwig 写道:
Quoted 14 lines · Huang Shijie
fs/internal.h +14
-0+/* +* Unsafe iteration for internal VFS use only: +* @ctx->iter_fn runs in atomic context with only +* an inode existence guarantee, so it must not block +* and must perform its own inode state checks. +* +* Return INO_ITER_RET_ABORT if the iteration stops early. +* Return INO_ITER_RET_DONE if the iteration runs to the end. +*/ +static inline int super_iter_inodes_unsafe (struct super_block *sb, +struct inode_iter_context *ctx) +{ +struct inode *inode; +int ret =INO_ITER_RET_NEXT ;
Quoted 8 lines
fs/internal.h struct super_block *user_get_super(dev_t, bool excl); · line 161
Quoted 6 lines
fs/internal.h +6
-0+ +rcu_read_lock (); +spin_lock (&sb->s_inode_list_lock); + inode =list_prepare_entry (ctx->prev, &sb->s_inodes, i_sb_list); + +list_for_each_entry_continue (inode, &sb->s_inodes, i_sb_list) {This is a really odd way to write a list iteration. I also don't see
This is for the evict_inodes() which will break and then resume the iteration.
Quoted 1 line
how the RCU lock is needed when you already hold the spinlock.
okay. I will remove the rcu_read_lock in future.
Quoted 3 lines
I honestly don't get this "iterator. It is trivial, the
_unsafeis wrong naming. What is the point?
What about super_iter_inodes_locked()? ore super_iter_inodes_noref()?
We use this function to hide the fs systems to use the sb->s_inode_list_lock directly. Then we can add more code to optimize the iteration.
Quoted 23 lines
Quoted 6 lines
fs/super.c +5
-0+/** +* super_iter_inodes - iterate all the cached inodes on a superblock +* @sb: superblock to iterate +* @ctx: the context which has the metadata +* fs/super.c static void super_wake(struct super_block *sb, unsigned int flag) · line 209
Quoted 10 lines
fs/super.c +10
-0+* This function iterates all cached inodes on a superblock that are not in +* the process of being initialised or torn down. It will run @ctx->iter_fn() +* with a valid, referenced inode, so it is safe for the caller to do +* anything it wants with the inode except drop the reference the iterator +* holds. +* +* Return INO_ITER_RET_DONE if the iteration runs to the end. +* Return other value if the iteration breaks. +*/ +int super_iter_inodes (struct super_block *sb,struct inode_iter_context *ctx)This one makes a lot more sense, but the callback pattern is a bit annoying as it requires to stuff all information into the context. Im much of the core kernel we're slowly switching to an iterator model that allows the caller to keep the state. In this case something like
Quoted 6 lines
struct inode_iter_contex ctx = INODE_ITER_CTX_INIT;
while ((inode = sb_inode_iter()))) {
/* do stuff */
}How to manage the sb->s_inode_list_lock in this code?
I have no idea how to hide the sb->s_inode_list_lock in this code.
Quoted 4 lines
which should be easily possibly with this model.
You probably also want to split the core iterator and switching each user into separate patches.
no problem. I can split them later.
Thanks
Huang Shijie
Christian Brauner
maintainerQuoted 9 lines · Huang Shijie
Quoted 6 lines
struct inode_iter_contex ctx = INODE_ITER_CTX_INIT; while ((inode = sb_inode_iter()))) { /* do stuff */ }How to manage the
sb->s_inode_list_lockin this code?I have no idea how to hide the
sb->s_inode_list_lockin this code.
I think Christoph is right. The lock shouldn't be held across iterations. Let the iterator take it, grab a reference to the next inode, drop the lock again and hand the inode out. The reference keeps the inode on s_inodes so the next call can continue from there.
This is how drop_pagecache_sb() does it today. Sm like (UNTESTED and not nice-ified):
struct sb_inode_iter {
struct super_block *sb;
struct inode *inode;
bool done;
};struct inode *sb_inode_iter_next(struct sb_inode_iter *it)
{
struct super_block *sb = it->sb;
struct inode *prev = it->inode, *inode;
if (it->done)
return NULL;
spin_lock(&sb->s_inode_list_lock);
inode = list_prepare_entry(prev, &sb->s_inodes, i_sb_list);
list_for_each_entry_continue(inode, &sb->s_inodes, i_sb_list) {
spin_lock(&inode->i_lock);
if (inode_state_read(inode) & (I_FREEING | I_WILL_FREE | I_NEW)) {
spin_unlock(&inode->i_lock);
continue;
}
__iget(inode);
spin_unlock(&inode->i_lock);
spin_unlock(&sb->s_inode_list_lock);
it->inode = inode;
iput(prev);
return inode;
}
spin_unlock(&sb->s_inode_list_lock);
it->inode = NULL;
it->done = true;
iput(prev);
return NULL;
}void sb_inode_iter_end(struct sb_inode_iter *it)
{
iput(it->inode);
it->inode = NULL;
it->done = true;
}and then drop_pagecache_sb() becomes:
struct sb_inode_iter it = { .sb = sb };
struct inode *inode;
while ((inode = sb_inode_iter_next(&it))) {
invalidate_mapping_pages(inode->i_mapping, 0, -1);
cond_resched();
}Make it a cleanup class and a caller that breaks out early doesn't have to remember sb_inode_iter_end() either.
This will end because new inodes are added at the head and the cursor stays on the list. So these assumptions should get VFS_WARN_ON_ONCE()-es.
Walkers that can't take a reference might need different solution. I'm not sure if there are any?
Quoted 7 lines · 在 Fri, Nov 20, 2026 at 12:14:24PM +0100,Christian Brauner 写道:
Quoted 6 lines · Huang Shijie
Quoted 6 lines
struct inode_iter_contex ctx = INODE_ITER_CTX_INIT; while ((inode = sb_inode_iter()))) { /* do stuff */ }
Quoted 7 lines
Quoted 3 lines
How to manage the
sb->s_inode_list_lockin this code?I have no idea how to hide the
sb->s_inode_list_lockin this code.I think Christoph is right. The lock shouldn't be held across iterations. Let the iterator take it, grab a reference to the next inode, drop the lock again and hand the inode out. The reference keeps the
okay.
If we can accept this method, I can change the code following it in future.
Quoted 61 lines
inode on
s_inodesso the next call can continue from there.This is how
drop_pagecache_sb()does it today. Sm like (UNTESTED and not nice-ified):struct sb_inode_iter { struct super_block *sb; struct inode *inode; bool done; };struct inode *sb_inode_iter_next(struct
sb_inode_iter*it){ struct super_block *sb = it->sb; struct inode *prev = it->inode, *inode; if (it->done) return NULL; spin_lock(&sb->s_inode_list_lock); inode = list_prepare_entry(prev, &sb->s_inodes, i_sb_list); list_for_each_entry_continue(inode, &sb->s_inodes, i_sb_list) { spin_lock(&inode->i_lock); if (inode_state_read(inode) & (I_FREEING | I_WILL_FREE | I_NEW)) { spin_unlock(&inode->i_lock); continue; } __iget(inode); spin_unlock(&inode->i_lock); spin_unlock(&sb->s_inode_list_lock); it->inode = inode; iput(prev); return inode; } spin_unlock(&sb->s_inode_list_lock); it->inode = NULL; it->done = true; iput(prev); return NULL; }void
sb_inode_iter_end(struct sb_inode_iter *it){ iput(it->inode); it->inode = NULL; it->done = true; }and then
drop_pagecache_sb()becomes:struct sb_inode_iter it = { .sb = sb }; struct inode *inode; while ((inode = sb_inode_iter_next(&it))) { invalidate_mapping_pages(inode->i_mapping, 0, -1); cond_resched(); }Make it a cleanup class and a caller that breaks out early doesn't have to remember
sb_inode_iter_end()either.
Quoted 6 lines
This will end because new inodes are added at the head and the cursor stays on the list. So these assumptions should get VFS_WARN_ON_ONCE()-es.
Walkers that can't take a reference might need different solution. I'm not sure if there are any?
I will think about it.
Thanks
Huang Shijie
PATCH v2 2/3 vfs: convert inode iterators to super_iter_inodes_unsafe()
In reply to Huang ShijieConvert VFS internal superblock inode iterators that cannot use referenced inodes to super_iter_inodes_unsafe():
- Dquot removal
- inode eviction
- The nr_blockdev_pages()
- generic_shutdown_super()
--- block/bdev.c | 19 +++++++---- fs/inode.c | 83 ++++++++++++++++++++++++++++-------------------- fs/quota/dquot.c | 73 ++++++++++++++++++++++++++---------------- fs/super.c | 23 ++++++++------ 4 files changed, 121 insertions(+), 77 deletions(-)
block/bdev.c +13 -6
@@ -558,16 +558,23 @@ void bdev_drop(struct block_device *bdev)iput (BD_INODE (bdev)); } +static int bdev_pages_count (struct inode *inode,struct inode_iter_context *ctx) +{ +long *pages = ctx->priv; + + *pages += inode->i_mapping->nrpages; +return INO_ITER_RET_NEXT ; +} +long nr_blockdev_pages (void ) { -struct inode *inode;long ret =0 ; +struct inode_iter_context ctx = { + .iter_fn = bdev_pages_count, + .priv = &ret, + }; -spin_lock (&blockdev_superblock->s_inode_list_lock); -list_for_each_entry (inode, &blockdev_superblock->s_inodes, i_sb_list) - ret += inode->i_mapping->nrpages; -spin_unlock (&blockdev_superblock->s_inode_list_lock); - +super_iter_inodes_unsafe (blockdev_superblock, &ctx);return ret; }
fs/inode.c +49 -34
99 lines not on this page · raw message
fs/quota/dquot.c +45 -28
98 lines not on this page · raw message
fs/super.c +14 -9
@@ -743,6 +743,15 @@ void retire_super(struct super_block *sb) }EXPORT_SYMBOL (retire_super); +static int inode_poison_fn (struct inode *inode,struct inode_iter_context *ctx) +{ + inode->i_op =VFS_PTR_POISON ; + inode->i_sb =VFS_PTR_POISON ; + inode->i_mapping =VFS_PTR_POISON ; + +return INO_ITER_RET_NEXT ; +} +/** * generic_shutdown_super - common helper for ->kill_sb() * @sb: superblock to kill
@@ -796,20 +805,16 @@ void generic_shutdown_super(struct super_block *sb)if (CHECK_DATA_CORRUPTION (!list_empty (&sb->s_inodes),NULL ,"VFS: Busy inodes after unmount of %s (%s)" , sb->s_id, sb->s_type->name)) { +struct inode_iter_context ctx = { + .iter_fn = inode_poison_fn, + }; +/* * Adding a proper bailout path here would be hard, but * we can at least make it more likely that a later * iput_final() or such crashes cleanly. */ -struct inode *inode; - -spin_lock (&sb->s_inode_list_lock); -list_for_each_entry (inode, &sb->s_inodes, i_sb_list) { - inode->i_op =VFS_PTR_POISON ; - inode->i_sb =VFS_PTR_POISON ; - inode->i_mapping =VFS_PTR_POISON ; - } -spin_unlock (&sb->s_inode_list_lock); +super_iter_inodes_unsafe (sb, &ctx); } }/*
Signature · 1 line
2.53.0
PATCH v2 3/3 vfs: convert sb->s_inodes iteration to super_iter_inodes()
In reply to Huang ShijieConvert all the remaining superblock inode iterators to use super_iter_inodes(). These are mostly straight forward conversions for the iterations that use referenced inodes:
- sync_bdevs
- drop_pagecache_sb
- gfs2_kill_sb
- add_dquot_ref
- hook_sb_delete
--- block/bdev.c | 92 +++++++++++-------------- fs/drop_caches.c | 49 ++++++------- fs/gfs2/ops_fstype.c | 33 +++------ fs/quota/dquot.c | 76 +++++++++----------- security/landlock/fs.c | 153 +++++++++++++++++------------------------ 5 files changed, 168 insertions(+), 235 deletions(-)
block/bdev.c +40 -52
@@ -1343,66 +1343,54 @@ void bdev_mark_dead(struct block_device *bdev, bool surprise)*/ EXPORT_SYMBOL_GPL (bdev_mark_dead); -void sync_bdevs (bool wait) +static bool sync_bdev_eligible (struct inode *inode, +struct inode_iter_context *ctx) { -struct inode *inode, *old_inode =NULL ; +return inode->i_mapping->nrpages !=0 ; +} -spin_lock (&blockdev_superblock->s_inode_list_lock); -list_for_each_entry (inode, &blockdev_superblock->s_inodes, i_sb_list) { -struct address_space *mapping = inode->i_mapping; -struct block_device *bdev; +static int sync_bdev_fn (struct inode *inode,struct inode_iter_context *ctx) +{ +bool wait = *(bool *)ctx->priv; +struct block_device *bdev; -spin_lock (&inode->i_lock); -if (inode_state_read (inode) & (I_FREEING |I_WILL_FREE |I_NEW ) || - mapping->nrpages ==0 ) { -spin_unlock (&inode->i_lock); -continue ; - } -__iget (inode); -spin_unlock (&inode->i_lock); -spin_unlock (&blockdev_superblock->s_inode_list_lock); -/* -* We hold a reference to 'inode' so it couldn't have been -* removed from s_inodes list while we dropped the -* s_inode_list_lock We cannot iput the inode now as we can -* be holding the last reference and we cannot iput it under -* s_inode_list_lock. So we keep the reference and iput it -* later. -*/ -iput (old_inode); - old_inode = inode; - bdev =I_BDEV (inode); + bdev =I_BDEV (inode); +/* +* The inode does not keep the gendisk of a partition alive, the +* device does. +*/ +if (!kobject_get_unless_zero (&bdev->bd_device.kobj)) +return INO_ITER_RET_NEXT ; +mutex_lock (&bdev->bd_disk->open_mutex); +if (!atomic_read (&bdev->bd_openers)) { + ;/* skip */ + }else if (wait) {/* -* The inode does not keep the gendisk of a partition alive, the -* device does. +* We keep the error status of individual mapping so +* that applications can catch the writeback error using +* fsync(2). See filemap_fdatawait_keep_errors() for +* details. */ -if (!kobject_get_unless_zero (&bdev->bd_device.kobj)) { -spin_lock (&blockdev_superblock->s_inode_list_lock); -continue ; - } +filemap_fdatawait_keep_errors (inode->i_mapping); + }else { +filemap_fdatawrite (inode->i_mapping); + } +mutex_unlock (&bdev->bd_disk->open_mutex); +put_device (&bdev->bd_device); -mutex_lock (&bdev->bd_disk->open_mutex); -if (!atomic_read (&bdev->bd_openers)) { - ;/* skip */ - }else if (wait) { -/* -* We keep the error status of individual mapping so -* that applications can catch the writeback error using -* fsync(2). See filemap_fdatawait_keep_errors() for -* details. -*/ -filemap_fdatawait_keep_errors (inode->i_mapping); - }else { -filemap_fdatawrite (inode->i_mapping); - } -mutex_unlock (&bdev->bd_disk->open_mutex); -put_device (&bdev->bd_device); +return INO_ITER_RET_NEXT ; +} -spin_lock (&blockdev_superblock->s_inode_list_lock); - } -spin_unlock (&blockdev_superblock->s_inode_list_lock); -iput (old_inode); +void sync_bdevs (bool wait) +{ +struct inode_iter_context ctx = { + .iter_fn = sync_bdev_fn, + .eligible = sync_bdev_eligible, + .priv = &wait, + }; + +super_iter_inodes (blockdev_superblock, &ctx); }/*
fs/drop_caches.c +22 -27
61 lines not on this page · raw message
fs/gfs2/ops_fstype.c +11 -22
@@ -1717,6 +1717,13 @@ static int gfs2_meta_init_fs_context(struct fs_context *fc)return 0 ; } +/* Nothing to do because we just want to bounce the inode through iput() */ +static int gfs2_evict_inode_fn (struct inode *inode, +struct inode_iter_context *ctx) +{ +return INO_ITER_RET_NEXT ; +} +/** * gfs2_evict_inodes - evict inodes cooperatively * @sb: the superblock
@@ -1739,31 +1746,13 @@ static int gfs2_meta_init_fs_context(struct fs_context *fc)*/ static void gfs2_evict_inodes (struct super_block *sb) { -struct inode *inode, *toput_inode =NULL ;struct gfs2_sbd *sdp = sb->s_fs_info; +struct inode_iter_context ctx = { + .iter_fn = gfs2_evict_inode_fn, + };set_bit (SDF_EVICTING , &sdp->sd_flags); - -spin_lock (&sb->s_inode_list_lock); -list_for_each_entry (inode, &sb->s_inodes, i_sb_list) { -spin_lock (&inode->i_lock); -if ((inode_state_read (inode) & (I_FREEING |I_WILL_FREE |I_NEW )) && - !need_resched ()) { -spin_unlock (&inode->i_lock); -continue ; - } -__iget (inode); -spin_unlock (&inode->i_lock); -spin_unlock (&sb->s_inode_list_lock); - -iput (toput_inode); - toput_inode = inode; - -cond_resched (); -spin_lock (&sb->s_inode_list_lock); - } -spin_unlock (&sb->s_inode_list_lock); -iput (toput_inode); +super_iter_inodes (sb, &ctx); }static void gfs2_kill_sb (struct super_block *sb)
fs/quota/dquot.c +33 -43
89 lines not on this page · raw message
security/landlock/fs.c +62 -91
172 lines not on this page · raw message
Signature · 1 line
2.53.0