diff options
| -rw-r--r-- | fs/ext4/resize.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c index c5adbb318a90..69a62610a6ca 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c | |||
| @@ -243,6 +243,7 @@ static int ext4_alloc_group_tables(struct super_block *sb, | |||
| 243 | ext4_group_t group; | 243 | ext4_group_t group; |
| 244 | ext4_group_t last_group; | 244 | ext4_group_t last_group; |
| 245 | unsigned overhead; | 245 | unsigned overhead; |
| 246 | __u16 uninit_mask = (flexbg_size > 1) ? ~EXT4_BG_BLOCK_UNINIT : ~0; | ||
| 246 | 247 | ||
| 247 | BUG_ON(flex_gd->count == 0 || group_data == NULL); | 248 | BUG_ON(flex_gd->count == 0 || group_data == NULL); |
| 248 | 249 | ||
| @@ -266,7 +267,7 @@ next_group: | |||
| 266 | src_group++; | 267 | src_group++; |
| 267 | for (; src_group <= last_group; src_group++) { | 268 | for (; src_group <= last_group; src_group++) { |
| 268 | overhead = ext4_group_overhead_blocks(sb, src_group); | 269 | overhead = ext4_group_overhead_blocks(sb, src_group); |
| 269 | if (overhead != 0) | 270 | if (overhead == 0) |
| 270 | last_blk += group_data[src_group - group].blocks_count; | 271 | last_blk += group_data[src_group - group].blocks_count; |
| 271 | else | 272 | else |
| 272 | break; | 273 | break; |
| @@ -280,8 +281,7 @@ next_group: | |||
| 280 | group = ext4_get_group_number(sb, start_blk - 1); | 281 | group = ext4_get_group_number(sb, start_blk - 1); |
| 281 | group -= group_data[0].group; | 282 | group -= group_data[0].group; |
| 282 | group_data[group].free_blocks_count--; | 283 | group_data[group].free_blocks_count--; |
| 283 | if (flexbg_size > 1) | 284 | flex_gd->bg_flags[group] &= uninit_mask; |
| 284 | flex_gd->bg_flags[group] &= ~EXT4_BG_BLOCK_UNINIT; | ||
| 285 | } | 285 | } |
| 286 | 286 | ||
| 287 | /* Allocate inode bitmaps */ | 287 | /* Allocate inode bitmaps */ |
| @@ -292,22 +292,30 @@ next_group: | |||
| 292 | group = ext4_get_group_number(sb, start_blk - 1); | 292 | group = ext4_get_group_number(sb, start_blk - 1); |
| 293 | group -= group_data[0].group; | 293 | group -= group_data[0].group; |
| 294 | group_data[group].free_blocks_count--; | 294 | group_data[group].free_blocks_count--; |
| 295 | if (flexbg_size > 1) | 295 | flex_gd->bg_flags[group] &= uninit_mask; |
| 296 | flex_gd->bg_flags[group] &= ~EXT4_BG_BLOCK_UNINIT; | ||
| 297 | } | 296 | } |
| 298 | 297 | ||
| 299 | /* Allocate inode tables */ | 298 | /* Allocate inode tables */ |
| 300 | for (; it_index < flex_gd->count; it_index++) { | 299 | for (; it_index < flex_gd->count; it_index++) { |
| 301 | if (start_blk + EXT4_SB(sb)->s_itb_per_group > last_blk) | 300 | unsigned int itb = EXT4_SB(sb)->s_itb_per_group; |
| 301 | ext4_fsblk_t next_group_start; | ||
| 302 | |||
| 303 | if (start_blk + itb > last_blk) | ||
| 302 | goto next_group; | 304 | goto next_group; |
| 303 | group_data[it_index].inode_table = start_blk; | 305 | group_data[it_index].inode_table = start_blk; |
| 304 | group = ext4_get_group_number(sb, start_blk - 1); | 306 | group = ext4_get_group_number(sb, start_blk); |
| 307 | next_group_start = ext4_group_first_block_no(sb, group + 1); | ||
| 305 | group -= group_data[0].group; | 308 | group -= group_data[0].group; |
| 306 | group_data[group].free_blocks_count -= | ||
| 307 | EXT4_SB(sb)->s_itb_per_group; | ||
| 308 | if (flexbg_size > 1) | ||
| 309 | flex_gd->bg_flags[group] &= ~EXT4_BG_BLOCK_UNINIT; | ||
| 310 | 309 | ||
| 310 | if (start_blk + itb > next_group_start) { | ||
| 311 | flex_gd->bg_flags[group + 1] &= uninit_mask; | ||
| 312 | overhead = start_blk + itb - next_group_start; | ||
| 313 | group_data[group + 1].free_blocks_count -= overhead; | ||
| 314 | itb -= overhead; | ||
| 315 | } | ||
| 316 | |||
| 317 | group_data[group].free_blocks_count -= itb; | ||
| 318 | flex_gd->bg_flags[group] &= uninit_mask; | ||
| 311 | start_blk += EXT4_SB(sb)->s_itb_per_group; | 319 | start_blk += EXT4_SB(sb)->s_itb_per_group; |
| 312 | } | 320 | } |
| 313 | 321 | ||
| @@ -620,7 +628,7 @@ handle_ib: | |||
| 620 | if (err) | 628 | if (err) |
| 621 | goto out; | 629 | goto out; |
| 622 | count = group_table_count[j]; | 630 | count = group_table_count[j]; |
| 623 | start = group_data[i].block_bitmap; | 631 | start = (&group_data[i].block_bitmap)[j]; |
| 624 | block = start; | 632 | block = start; |
| 625 | } | 633 | } |
| 626 | 634 | ||
