Skip to content

Commit 68228da

Browse files
Wang Jianjiantytso
authored andcommitted
ext4: add correct group descriptors and reserved GDT blocks to system zone
When setup_system_zone, flex_bg is not initialized so it is always 1. Use a new helper function, ext4_num_base_meta_blocks() which does not depend on sbi->s_log_groups_per_flex being initialized. [ Squashed two patches in the Link URL's below together into a single commit, which is simpler to review/understand. Also fix checkpatch warnings. --TYT ] Cc: stable@kernel.org Signed-off-by: Wang Jianjian <wangjianjian0@foxmail.com> Link: https://lore.kernel.org/r/tencent_21AF0D446A9916ED5C51492CC6C9A0A77B05@qq.com Link: https://lore.kernel.org/r/tencent_D744D1450CC169AEA77FCF0A64719909ED05@qq.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent b6c7d6d commit 68228da

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

fs/ext4/balloc.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -913,11 +913,11 @@ unsigned long ext4_bg_num_gdb(struct super_block *sb, ext4_group_t group)
913913
}
914914

915915
/*
916-
* This function returns the number of file system metadata clusters at
916+
* This function returns the number of file system metadata blocks at
917917
* the beginning of a block group, including the reserved gdt blocks.
918918
*/
919-
static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
920-
ext4_group_t block_group)
919+
unsigned int ext4_num_base_meta_blocks(struct super_block *sb,
920+
ext4_group_t block_group)
921921
{
922922
struct ext4_sb_info *sbi = EXT4_SB(sb);
923923
unsigned num;
@@ -935,8 +935,15 @@ static unsigned ext4_num_base_meta_clusters(struct super_block *sb,
935935
} else { /* For META_BG_BLOCK_GROUPS */
936936
num += ext4_bg_num_gdb_meta(sb, block_group);
937937
}
938-
return EXT4_NUM_B2C(sbi, num);
938+
return num;
939939
}
940+
941+
static unsigned int ext4_num_base_meta_clusters(struct super_block *sb,
942+
ext4_group_t block_group)
943+
{
944+
return EXT4_NUM_B2C(EXT4_SB(sb), ext4_num_base_meta_blocks(sb, block_group));
945+
}
946+
940947
/**
941948
* ext4_inode_to_goal_block - return a hint for block allocation
942949
* @inode: inode for block allocation

fs/ext4/block_validity.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,20 @@ int ext4_setup_system_zone(struct super_block *sb)
215215
struct ext4_system_blocks *system_blks;
216216
struct ext4_group_desc *gdp;
217217
ext4_group_t i;
218-
int flex_size = ext4_flex_bg_size(sbi);
219218
int ret;
220219

221220
system_blks = kzalloc(sizeof(*system_blks), GFP_KERNEL);
222221
if (!system_blks)
223222
return -ENOMEM;
224223

225224
for (i=0; i < ngroups; i++) {
225+
unsigned int meta_blks = ext4_num_base_meta_blocks(sb, i);
226+
226227
cond_resched();
227-
if (ext4_bg_has_super(sb, i) &&
228-
((i < 5) || ((i % flex_size) == 0))) {
228+
if (meta_blks != 0) {
229229
ret = add_system_zone(system_blks,
230230
ext4_group_first_block_no(sb, i),
231-
ext4_bg_num_gdb(sb, i) + 1, 0);
231+
meta_blks, 0);
232232
if (ret)
233233
goto err;
234234
}

fs/ext4/ext4.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,6 +3079,8 @@ extern const char *ext4_decode_error(struct super_block *sb, int errno,
30793079
extern void ext4_mark_group_bitmap_corrupted(struct super_block *sb,
30803080
ext4_group_t block_group,
30813081
unsigned int flags);
3082+
extern unsigned int ext4_num_base_meta_blocks(struct super_block *sb,
3083+
ext4_group_t block_group);
30823084

30833085
extern __printf(7, 8)
30843086
void __ext4_error(struct super_block *, const char *, unsigned int, bool,

0 commit comments

Comments
 (0)