Convert gfs2_evict_inodes to super_iter_inodes(). 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 | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index 6ec47376aecf..a6f8e95a4187 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -1717,6 +1717,12 @@ 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, void *priv) +{ + return INO_ITER_RET_NEXT; +} + /** * gfs2_evict_inodes - evict inodes cooperatively * @sb: the superblock @@ -1739,31 +1745,10 @@ 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; - - cond_resched(); - spin_lock(&sb->s_inode_list_lock); - } - spin_unlock(&sb->s_inode_list_lock); - iput(toput_inode); + super_iter_inodes(sb, gfs2_evict_inode_fn, NULL, NULL, 0); } static void gfs2_kill_sb(struct super_block *sb) -- 2.53.0