Skip to content

Commit 6c5bd55

Browse files
Xin Yingregkh
authored andcommitted
ext4: modify the logic of ext4_mb_new_blocks_simple
commit 31a074a upstream. 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 <yinxin.x@bytedance.com> Reviewed-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com> Link: https://lore.kernel.org/r/20220110035141.1980-3-yinxin.x@bytedance.com Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8d71fc2 commit 6c5bd55

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

fs/ext4/mballoc.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5173,7 +5173,8 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle,
51735173
struct super_block *sb = ar->inode->i_sb;
51745174
ext4_group_t group;
51755175
ext4_grpblk_t blkoff;
5176-
int i = sb->s_blocksize;
5176+
ext4_grpblk_t max = EXT4_CLUSTERS_PER_GROUP(sb);
5177+
ext4_grpblk_t i = 0;
51775178
ext4_fsblk_t goal, block;
51785179
struct ext4_super_block *es = EXT4_SB(sb)->s_es;
51795180

@@ -5195,19 +5196,26 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle,
51955196
ext4_get_group_no_and_offset(sb,
51965197
max(ext4_group_first_block_no(sb, group), goal),
51975198
NULL, &blkoff);
5198-
i = mb_find_next_zero_bit(bitmap_bh->b_data, sb->s_blocksize,
5199+
while (1) {
5200+
i = mb_find_next_zero_bit(bitmap_bh->b_data, max,
51995201
blkoff);
5202+
if (i >= max)
5203+
break;
5204+
if (ext4_fc_replay_check_excluded(sb,
5205+
ext4_group_first_block_no(sb, group) + i)) {
5206+
blkoff = i + 1;
5207+
} else
5208+
break;
5209+
}
52005210
brelse(bitmap_bh);
5201-
if (i >= sb->s_blocksize)
5202-
continue;
5203-
if (ext4_fc_replay_check_excluded(sb,
5204-
ext4_group_first_block_no(sb, group) + i))
5205-
continue;
5206-
break;
5211+
if (i < max)
5212+
break;
52075213
}
52085214

5209-
if (group >= ext4_get_groups_count(sb) && i >= sb->s_blocksize)
5215+
if (group >= ext4_get_groups_count(sb) || i >= max) {
5216+
*errp = -ENOSPC;
52105217
return 0;
5218+
}
52115219

52125220
block = ext4_group_first_block_no(sb, group) + i;
52135221
ext4_mb_mark_bb(sb, block, 1, 1);

0 commit comments

Comments
 (0)