ext2: fix missing percpu_counter_inc
authorMikulas Patocka <mpatocka@redhat.com>
Mon, 20 Apr 2020 20:02:21 +0000 (16:02 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Aug 2020 09:05:32 +0000 (11:05 +0200)
commit bc2fbaa4d3808aef82dd1064a8e61c16549fe956 upstream.

sbi->s_freeinodes_counter is only decreased by the ext2 code, it is never
increased. This patch fixes it.

Note that sbi->s_freeinodes_counter is only used in the algorithm that
tries to find the group for new allocations, so this bug is not easily
visible (the only visibility is that the group finding algorithm selects
inoptinal result).

Link: https://lore.kernel.org/r/alpine.LRH.2.02.2004201538300.19436@file01.intranet.prod.int.rdu2.redhat.com
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ext2/ialloc.c

index 5c3d7b7e49755ccbe22f65b607e8197d854df091..d8a03b1afbc332dd84c3f9f59d2c8621be8b54f5 100644 (file)
@@ -80,6 +80,7 @@ static void ext2_release_inode(struct super_block *sb, int group, int dir)
        if (dir)
                le16_add_cpu(&desc->bg_used_dirs_count, -1);
        spin_unlock(sb_bgl_lock(EXT2_SB(sb), group));
+       percpu_counter_inc(&EXT2_SB(sb)->s_freeinodes_counter);
        if (dir)
                percpu_counter_dec(&EXT2_SB(sb)->s_dirs_counter);
        mark_buffer_dirty(bh);
@@ -531,7 +532,7 @@ struct inode *ext2_new_inode(struct inode *dir, umode_t mode,
                goto fail;
        }
 
-       percpu_counter_add(&sbi->s_freeinodes_counter, -1);
+       percpu_counter_dec(&sbi->s_freeinodes_counter);
        if (S_ISDIR(mode))
                percpu_counter_inc(&sbi->s_dirs_counter);