Skip to content

Commit 9b6641d

Browse files
Ye Bintytso
Ye Bin
authored andcommitted
ext4: fix super block checksum incorrect after mount
We got issue as follows: [home]# mount /dev/sda test EXT4-fs (sda): warning: mounting fs with errors, running e2fsck is recommended [home]# dmesg EXT4-fs (sda): warning: mounting fs with errors, running e2fsck is recommended EXT4-fs (sda): Errors on filesystem, clearing orphan list. EXT4-fs (sda): recovery complete EXT4-fs (sda): mounted filesystem with ordered data mode. Quota mode: none. [home]# debugfs /dev/sda debugfs 1.46.5 (30-Dec-2021) Checksum errors in superblock! Retrying... Reason is ext4_orphan_cleanup will reset ‘s_last_orphan’ but not update super block checksum. To solve above issue, defer update super block checksum after ext4_orphan_cleanup. Signed-off-by: Ye Bin <[email protected]> Cc: [email protected] Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Ritesh Harjani <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 8d5459c commit 9b6641d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

fs/ext4/super.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -5302,14 +5302,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
53025302
err = percpu_counter_init(&sbi->s_freeinodes_counter, freei,
53035303
GFP_KERNEL);
53045304
}
5305-
/*
5306-
* Update the checksum after updating free space/inode
5307-
* counters. Otherwise the superblock can have an incorrect
5308-
* checksum in the buffer cache until it is written out and
5309-
* e2fsprogs programs trying to open a file system immediately
5310-
* after it is mounted can fail.
5311-
*/
5312-
ext4_superblock_csum_set(sb);
53135305
if (!err)
53145306
err = percpu_counter_init(&sbi->s_dirs_counter,
53155307
ext4_count_dirs(sb), GFP_KERNEL);
@@ -5367,6 +5359,14 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
53675359
EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
53685360
ext4_orphan_cleanup(sb, es);
53695361
EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
5362+
/*
5363+
* Update the checksum after updating free space/inode counters and
5364+
* ext4_orphan_cleanup. Otherwise the superblock can have an incorrect
5365+
* checksum in the buffer cache until it is written out and
5366+
* e2fsprogs programs trying to open a file system immediately
5367+
* after it is mounted can fail.
5368+
*/
5369+
ext4_superblock_csum_set(sb);
53705370
if (needs_recovery) {
53715371
ext4_msg(sb, KERN_INFO, "recovery complete");
53725372
err = ext4_mark_recovery_complete(sb, es);

0 commit comments

Comments
 (0)