Skip to content

Commit 31a074a

Browse files
Xin Yintytso
authored andcommitted
ext4: modify the logic of ext4_mb_new_blocks_simple
For now in ext4_mb_new_blocks_simple, if we found a block which should be excluded then will switch to next group, this may probably cause 'group' run out of range. Change to check next block in the same group when get a block should be excluded. Also change the search range to EXT4_CLUSTERS_PER_GROUP and add error checking. Signed-off-by: Xin Yin <[email protected]> Reviewed-by: Harshad Shirwadkar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected]
1 parent 599ea31 commit 31a074a

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

fs/ext4/mballoc.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5753,7 +5753,8 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle,
57535753
struct super_block *sb = ar->inode->i_sb;
57545754
ext4_group_t group;
57555755
ext4_grpblk_t blkoff;
5756-
int i = sb->s_blocksize;
5756+
ext4_grpblk_t max = EXT4_CLUSTERS_PER_GROUP(sb);
5757+
ext4_grpblk_t i = 0;
57575758
ext4_fsblk_t goal, block;
57585759
struct ext4_super_block *es = EXT4_SB(sb)->s_es;
57595760

@@ -5775,19 +5776,26 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle,
57755776
ext4_get_group_no_and_offset(sb,
57765777
max(ext4_group_first_block_no(sb, group), goal),
57775778
NULL, &blkoff);
5778-
i = mb_find_next_zero_bit(bitmap_bh->b_data, sb->s_blocksize,
5779+
while (1) {
5780+
i = mb_find_next_zero_bit(bitmap_bh->b_data, max,
57795781
blkoff);
5782+
if (i >= max)
5783+
break;
5784+
if (ext4_fc_replay_check_excluded(sb,
5785+
ext4_group_first_block_no(sb, group) + i)) {
5786+
blkoff = i + 1;
5787+
} else
5788+
break;
5789+
}
57805790
brelse(bitmap_bh);
5781-
if (i >= sb->s_blocksize)
5782-
continue;
5783-
if (ext4_fc_replay_check_excluded(sb,
5784-
ext4_group_first_block_no(sb, group) + i))
5785-
continue;
5786-
break;
5791+
if (i < max)
5792+
break;
57875793
}
57885794

5789-
if (group >= ext4_get_groups_count(sb) && i >= sb->s_blocksize)
5795+
if (group >= ext4_get_groups_count(sb) || i >= max) {
5796+
*errp = -ENOSPC;
57905797
return 0;
5798+
}
57915799

57925800
block = ext4_group_first_block_no(sb, group) + i;
57935801
ext4_mb_mark_bb(sb, block, 1, 1);

0 commit comments

Comments
 (0)