Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ext4: factor out ext4_block_group_meta_init()

Factor out ext4_block_group_meta_init(). No functional change.

Signed-off-by: Jason Yan <yanaijie@huawei.com>
Link: https://lore.kernel.org/r/20230323140517.1070239-8-yanaijie@huawei.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

authored by

Jason Yan and committed by
Theodore Ts'o
107d2be9 269e9226

+51 -39
+51 -39
fs/ext4/super.c
··· 5113 5113 } 5114 5114 } 5115 5115 5116 + static int ext4_block_group_meta_init(struct super_block *sb, int silent) 5117 + { 5118 + struct ext4_sb_info *sbi = EXT4_SB(sb); 5119 + struct ext4_super_block *es = sbi->s_es; 5120 + int has_huge_files; 5121 + 5122 + has_huge_files = ext4_has_feature_huge_file(sb); 5123 + sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits, 5124 + has_huge_files); 5125 + sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files); 5126 + 5127 + sbi->s_desc_size = le16_to_cpu(es->s_desc_size); 5128 + if (ext4_has_feature_64bit(sb)) { 5129 + if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT || 5130 + sbi->s_desc_size > EXT4_MAX_DESC_SIZE || 5131 + !is_power_of_2(sbi->s_desc_size)) { 5132 + ext4_msg(sb, KERN_ERR, 5133 + "unsupported descriptor size %lu", 5134 + sbi->s_desc_size); 5135 + return -EINVAL; 5136 + } 5137 + } else 5138 + sbi->s_desc_size = EXT4_MIN_DESC_SIZE; 5139 + 5140 + sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); 5141 + sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); 5142 + 5143 + sbi->s_inodes_per_block = sb->s_blocksize / EXT4_INODE_SIZE(sb); 5144 + if (sbi->s_inodes_per_block == 0 || sbi->s_blocks_per_group == 0) { 5145 + if (!silent) 5146 + ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem"); 5147 + return -EINVAL; 5148 + } 5149 + if (sbi->s_inodes_per_group < sbi->s_inodes_per_block || 5150 + sbi->s_inodes_per_group > sb->s_blocksize * 8) { 5151 + ext4_msg(sb, KERN_ERR, "invalid inodes per group: %lu\n", 5152 + sbi->s_inodes_per_group); 5153 + return -EINVAL; 5154 + } 5155 + sbi->s_itb_per_group = sbi->s_inodes_per_group / 5156 + sbi->s_inodes_per_block; 5157 + sbi->s_desc_per_block = sb->s_blocksize / EXT4_DESC_SIZE(sb); 5158 + sbi->s_mount_state = le16_to_cpu(es->s_state) & ~EXT4_FC_REPLAY; 5159 + sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb)); 5160 + sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb)); 5161 + 5162 + return 0; 5163 + } 5164 + 5116 5165 static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) 5117 5166 { 5118 5167 struct ext4_super_block *es = NULL; ··· 5170 5121 struct inode *root; 5171 5122 int ret = -ENOMEM; 5172 5123 unsigned int i; 5173 - int needs_recovery, has_huge_files; 5124 + int needs_recovery; 5174 5125 int err = 0; 5175 5126 ext4_group_t first_not_zeroed; 5176 5127 struct ext4_fs_context *ctx = fc->fs_private; ··· 5268 5219 goto failed_mount; 5269 5220 } 5270 5221 5271 - has_huge_files = ext4_has_feature_huge_file(sb); 5272 - sbi->s_bitmap_maxbytes = ext4_max_bitmap_size(sb->s_blocksize_bits, 5273 - has_huge_files); 5274 - sb->s_maxbytes = ext4_max_size(sb->s_blocksize_bits, has_huge_files); 5275 - 5276 - sbi->s_desc_size = le16_to_cpu(es->s_desc_size); 5277 - if (ext4_has_feature_64bit(sb)) { 5278 - if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT || 5279 - sbi->s_desc_size > EXT4_MAX_DESC_SIZE || 5280 - !is_power_of_2(sbi->s_desc_size)) { 5281 - ext4_msg(sb, KERN_ERR, 5282 - "unsupported descriptor size %lu", 5283 - sbi->s_desc_size); 5284 - goto failed_mount; 5285 - } 5286 - } else 5287 - sbi->s_desc_size = EXT4_MIN_DESC_SIZE; 5288 - 5289 - sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); 5290 - sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); 5291 - 5292 - sbi->s_inodes_per_block = sb->s_blocksize / EXT4_INODE_SIZE(sb); 5293 - if (sbi->s_inodes_per_block == 0 || sbi->s_blocks_per_group == 0) { 5294 - if (!silent) 5295 - ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem"); 5222 + if (ext4_block_group_meta_init(sb, silent)) 5296 5223 goto failed_mount; 5297 - } 5298 - if (sbi->s_inodes_per_group < sbi->s_inodes_per_block || 5299 - sbi->s_inodes_per_group > sb->s_blocksize * 8) { 5300 - ext4_msg(sb, KERN_ERR, "invalid inodes per group: %lu\n", 5301 - sbi->s_inodes_per_group); 5302 - goto failed_mount; 5303 - } 5304 - sbi->s_itb_per_group = sbi->s_inodes_per_group / 5305 - sbi->s_inodes_per_block; 5306 - sbi->s_desc_per_block = sb->s_blocksize / EXT4_DESC_SIZE(sb); 5307 - sbi->s_mount_state = le16_to_cpu(es->s_state) & ~EXT4_FC_REPLAY; 5308 - sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb)); 5309 - sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb)); 5310 5224 5311 5225 ext4_hash_info_init(sb); 5312 5226