Commit 03c1c29053f678234dbd51bf3d65f3b7529021de
Committed by
Theodore Ts'o
1 parent
8a2f8460e8
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
ext4: ignore last group w/o enough space when resizing instead of BUG'ing
If the last group does not have enough space for group tables, ignore it instead of calling BUG_ON(). Reported-by: Daniel Drake <dsd@laptop.org> Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Cc: stable@vger.kernel.org
Showing 1 changed file with 9 additions and 3 deletions Side-by-side Diff
fs/ext4/resize.c
... | ... | @@ -200,8 +200,11 @@ |
200 | 200 | * be a partial of a flex group. |
201 | 201 | * |
202 | 202 | * @sb: super block of fs to which the groups belongs |
203 | + * | |
204 | + * Returns 0 on a successful allocation of the metadata blocks in the | |
205 | + * block group. | |
203 | 206 | */ |
204 | -static void ext4_alloc_group_tables(struct super_block *sb, | |
207 | +static int ext4_alloc_group_tables(struct super_block *sb, | |
205 | 208 | struct ext4_new_flex_group_data *flex_gd, |
206 | 209 | int flexbg_size) |
207 | 210 | { |
... | ... | @@ -226,6 +229,8 @@ |
226 | 229 | (last_group & ~(flexbg_size - 1)))); |
227 | 230 | next_group: |
228 | 231 | group = group_data[0].group; |
232 | + if (src_group >= group_data[0].group + flex_gd->count) | |
233 | + return -ENOSPC; | |
229 | 234 | start_blk = ext4_group_first_block_no(sb, src_group); |
230 | 235 | last_blk = start_blk + group_data[src_group - group].blocks_count; |
231 | 236 | |
... | ... | @@ -235,7 +240,6 @@ |
235 | 240 | |
236 | 241 | start_blk += overhead; |
237 | 242 | |
238 | - BUG_ON(src_group >= group_data[0].group + flex_gd->count); | |
239 | 243 | /* We collect contiguous blocks as much as possible. */ |
240 | 244 | src_group++; |
241 | 245 | for (; src_group <= last_group; src_group++) |
... | ... | @@ -300,6 +304,7 @@ |
300 | 304 | group_data[i].free_blocks_count); |
301 | 305 | } |
302 | 306 | } |
307 | + return 0; | |
303 | 308 | } |
304 | 309 | |
305 | 310 | static struct buffer_head *bclean(handle_t *handle, struct super_block *sb, |
... | ... | @@ -1729,7 +1734,8 @@ |
1729 | 1734 | */ |
1730 | 1735 | while (ext4_setup_next_flex_gd(sb, flex_gd, n_blocks_count, |
1731 | 1736 | flexbg_size)) { |
1732 | - ext4_alloc_group_tables(sb, flex_gd, flexbg_size); | |
1737 | + if (ext4_alloc_group_tables(sb, flex_gd, flexbg_size) != 0) | |
1738 | + break; | |
1733 | 1739 | err = ext4_flex_group_add(sb, resize_inode, flex_gd); |
1734 | 1740 | if (unlikely(err)) |
1735 | 1741 | break; |