[PATCH v4 11/11] gfs2: convert gfs2_evict_inodes() to sb_inode_iter
From: Huang Shijie
Date: Wed Nov 25 2026 - 04:13:42 EST
Convert gfs2_evict_inodes to sb_inode_iter.
The original code also handed out an inode which was already being
torn down when need_resched() was set. That is not preserved: taking a
reference on an I_FREEING inode whose count has already reached zero
lets a second iput() run on it once the reference is dropped again.
Signed-off-by: Huang Shijie <huangsj@xxxxxxxx>
---
fs/gfs2/ops_fstype.c | 26 ++++++--------------------
1 file changed, 6 insertions(+), 20 deletions(-)
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 6ec47376aecf..130b116627a3 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -1739,31 +1739,17 @@ 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;
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;
-
+ /*
+ * Nothing to do with each inode: we only want to bounce it through
+ * iput() so that it is evicted while the list lock is dropped.
+ */
+ CLASS(sb_inode_iter, iter)(sb, NULL, NULL, 0);
+ while (sb_inode_iter_next(&iter))
cond_resched();
- spin_lock(&sb->s_inode_list_lock);
- }
- spin_unlock(&sb->s_inode_list_lock);
- iput(toput_inode);
}
static void gfs2_kill_sb(struct super_block *sb)
--
2.53.0