OSDN Git Service

ext4: remove cantfind_ext4 error handler
authorJason Yan <yanaijie@huawei.com>
Fri, 16 Sep 2022 14:15:13 +0000 (22:15 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 1 Oct 2022 03:46:52 +0000 (23:46 -0400)
The 'cantfind_ext4' error handler is just a error msg print and then
goto failed_mount. This two level goto makes the code complex and not
easy to read. The only benefit is that is saves a little bit code.
However some branches can merge and some branches dot not even need it.
So do some refactor and remove it.

Signed-off-by: Jason Yan <yanaijie@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Link: https://lore.kernel.org/r/20220916141527.1012715-3-yanaijie@huawei.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/super.c

index 016b341..34a261f 100644 (file)
@@ -4344,8 +4344,12 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
        es = (struct ext4_super_block *) (bh->b_data + offset);
        sbi->s_es = es;
        sb->s_magic = le16_to_cpu(es->s_magic);
-       if (sb->s_magic != EXT4_SUPER_MAGIC)
-               goto cantfind_ext4;
+       if (sb->s_magic != EXT4_SUPER_MAGIC) {
+               if (!silent)
+                       ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem");
+               goto failed_mount;
+       }
+
        sbi->s_kbytes_written = le64_to_cpu(es->s_kbytes_written);
 
        /* Warn if metadata_csum and gdt_csum are both set. */
@@ -4358,8 +4362,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
        if (!ext4_verify_csum_type(sb, es)) {
                ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
                         "unknown checksum algorithm.");
-               silent = 1;
-               goto cantfind_ext4;
+               goto failed_mount;
        }
        ext4_setup_csum_trigger(sb, EXT4_JTR_ORPHAN_FILE,
                                ext4_orphan_file_block_trigger);
@@ -4377,9 +4380,8 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
        if (!ext4_superblock_csum_verify(sb, es)) {
                ext4_msg(sb, KERN_ERR, "VFS: Found ext4 filesystem with "
                         "invalid superblock checksum.  Run e2fsck?");
-               silent = 1;
                ret = -EFSBADCRC;
-               goto cantfind_ext4;
+               goto failed_mount;
        }
 
        /* Precompute checksum seed for all metadata */
@@ -4772,8 +4774,11 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
        sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
 
        sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
-       if (sbi->s_inodes_per_block == 0)
-               goto cantfind_ext4;
+       if (sbi->s_inodes_per_block == 0 || sbi->s_blocks_per_group == 0) {
+               if (!silent)
+                       ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem");
+               goto failed_mount;
+       }
        if (sbi->s_inodes_per_group < sbi->s_inodes_per_block ||
            sbi->s_inodes_per_group > blocksize * 8) {
                ext4_msg(sb, KERN_ERR, "invalid inodes per group: %lu\n",
@@ -4870,9 +4875,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
                goto failed_mount;
        }
 
-       if (EXT4_BLOCKS_PER_GROUP(sb) == 0)
-               goto cantfind_ext4;
-
        /* check blocks count against device size */
        blocks_count = sb_bdev_nr_blocks(sb);
        if (blocks_count && ext4_blocks_count(es) > blocks_count) {
@@ -5382,11 +5384,6 @@ no_journal:
 
        return 0;
 
-cantfind_ext4:
-       if (!silent)
-               ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem");
-       goto failed_mount;
-
 failed_mount9:
        ext4_release_orphan_info(sb);
 failed_mount8: