Convert gfs2_evict_inodes() to for_each_inode(). 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 --- 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..22bb50509904 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -1736,37 +1736,23 @@ static int gfs2_meta_init_fs_context(struct fs_context *fc) * version of evict_inodes() avoids that. * * Modeled after drop_pagecache_sb(). */ 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 *inode __maybe_unused; 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. + */ + for_each_inode(inode, sb) 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) { struct gfs2_sbd *sdp = sb->s_fs_info; -- 2.34.1