Skip to content

Commit 22654a3

Browse files
tytsogregkh
authored andcommitted
ext4: recalucate superblock checksum after updating free blocks/inodes
commit 4274f51 upstream. When mounting the superblock, ext4_fill_super() calculates the free blocks and free inodes and stores them in the superblock. It's not strictly necessary, since we don't use them any more, but it's nice to keep them roughly aligned to reality. Since it's not critical for file system correctness, the code doesn't call ext4_commit_super(). The problem is that it's in ext4_commit_super() that we recalculate the superblock checksum. So if we're not going to call ext4_commit_super(), we need to call ext4_superblock_csum_set() to make sure the superblock checksum is consistent. Most of the time, this doesn't matter, since we end up calling ext4_commit_super() very soon thereafter, and definitely by the time the file system is unmounted. However, it doesn't work in this sequence: mke2fs -Fq -t ext4 /dev/vdc 128M mount /dev/vdc /vdc cp xfstests/git-versions /vdc godown /vdc umount /vdc mount /dev/vdc tune2fs -l /dev/vdc With this commit, the "tune2fs -l" no longer fails. Reported-by: Chengguang Xu <cgxu519@gmx.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 779af00 commit 22654a3

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

fs/ext4/super.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4311,11 +4311,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
43114311
block = ext4_count_free_clusters(sb);
43124312
ext4_free_blocks_count_set(sbi->s_es,
43134313
EXT4_C2B(sbi, block));
4314+
ext4_superblock_csum_set(sb);
43144315
err = percpu_counter_init(&sbi->s_freeclusters_counter, block,
43154316
GFP_KERNEL);
43164317
if (!err) {
43174318
unsigned long freei = ext4_count_free_inodes(sb);
43184319
sbi->s_es->s_free_inodes_count = cpu_to_le32(freei);
4320+
ext4_superblock_csum_set(sb);
43194321
err = percpu_counter_init(&sbi->s_freeinodes_counter, freei,
43204322
GFP_KERNEL);
43214323
}

0 commit comments

Comments
 (0)