diff options
Diffstat (limited to 'fs/ext4/mballoc.c')
-rw-r--r-- | fs/ext4/mballoc.c | 73 |
1 files changed, 29 insertions, 44 deletions
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index d34afad3e137..abb11e328b65 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c | |||
@@ -441,10 +441,9 @@ static void mb_free_blocks_double(struct inode *inode, struct ext4_buddy *e4b, | |||
441 | for (i = 0; i < count; i++) { | 441 | for (i = 0; i < count; i++) { |
442 | if (!mb_test_bit(first + i, e4b->bd_info->bb_bitmap)) { | 442 | if (!mb_test_bit(first + i, e4b->bd_info->bb_bitmap)) { |
443 | ext4_fsblk_t blocknr; | 443 | ext4_fsblk_t blocknr; |
444 | blocknr = e4b->bd_group * EXT4_BLOCKS_PER_GROUP(sb); | 444 | |
445 | blocknr = ext4_group_first_block_no(sb, e4b->bd_group); | ||
445 | blocknr += first + i; | 446 | blocknr += first + i; |
446 | blocknr += | ||
447 | le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); | ||
448 | ext4_grp_locked_error(sb, e4b->bd_group, | 447 | ext4_grp_locked_error(sb, e4b->bd_group, |
449 | __func__, "double-free of inode" | 448 | __func__, "double-free of inode" |
450 | " %lu's block %llu(bit %u in group %u)", | 449 | " %lu's block %llu(bit %u in group %u)", |
@@ -1255,10 +1254,9 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b, | |||
1255 | 1254 | ||
1256 | if (!mb_test_bit(block, EXT4_MB_BITMAP(e4b))) { | 1255 | if (!mb_test_bit(block, EXT4_MB_BITMAP(e4b))) { |
1257 | ext4_fsblk_t blocknr; | 1256 | ext4_fsblk_t blocknr; |
1258 | blocknr = e4b->bd_group * EXT4_BLOCKS_PER_GROUP(sb); | 1257 | |
1258 | blocknr = ext4_group_first_block_no(sb, e4b->bd_group); | ||
1259 | blocknr += block; | 1259 | blocknr += block; |
1260 | blocknr += | ||
1261 | le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block); | ||
1262 | ext4_grp_locked_error(sb, e4b->bd_group, | 1260 | ext4_grp_locked_error(sb, e4b->bd_group, |
1263 | __func__, "double-free of inode" | 1261 | __func__, "double-free of inode" |
1264 | " %lu's block %llu(bit %u in group %u)", | 1262 | " %lu's block %llu(bit %u in group %u)", |
@@ -1631,7 +1629,6 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac, | |||
1631 | int max; | 1629 | int max; |
1632 | int err; | 1630 | int err; |
1633 | struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); | 1631 | struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); |
1634 | struct ext4_super_block *es = sbi->s_es; | ||
1635 | struct ext4_free_extent ex; | 1632 | struct ext4_free_extent ex; |
1636 | 1633 | ||
1637 | if (!(ac->ac_flags & EXT4_MB_HINT_TRY_GOAL)) | 1634 | if (!(ac->ac_flags & EXT4_MB_HINT_TRY_GOAL)) |
@@ -1648,8 +1645,8 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac, | |||
1648 | if (max >= ac->ac_g_ex.fe_len && ac->ac_g_ex.fe_len == sbi->s_stripe) { | 1645 | if (max >= ac->ac_g_ex.fe_len && ac->ac_g_ex.fe_len == sbi->s_stripe) { |
1649 | ext4_fsblk_t start; | 1646 | ext4_fsblk_t start; |
1650 | 1647 | ||
1651 | start = (e4b->bd_group * EXT4_BLOCKS_PER_GROUP(ac->ac_sb)) + | 1648 | start = ext4_group_first_block_no(ac->ac_sb, e4b->bd_group) + |
1652 | ex.fe_start + le32_to_cpu(es->s_first_data_block); | 1649 | ex.fe_start; |
1653 | /* use do_div to get remainder (would be 64-bit modulo) */ | 1650 | /* use do_div to get remainder (would be 64-bit modulo) */ |
1654 | if (do_div(start, sbi->s_stripe) == 0) { | 1651 | if (do_div(start, sbi->s_stripe) == 0) { |
1655 | ac->ac_found++; | 1652 | ac->ac_found++; |
@@ -1803,8 +1800,8 @@ void ext4_mb_scan_aligned(struct ext4_allocation_context *ac, | |||
1803 | BUG_ON(sbi->s_stripe == 0); | 1800 | BUG_ON(sbi->s_stripe == 0); |
1804 | 1801 | ||
1805 | /* find first stripe-aligned block in group */ | 1802 | /* find first stripe-aligned block in group */ |
1806 | first_group_block = e4b->bd_group * EXT4_BLOCKS_PER_GROUP(sb) | 1803 | first_group_block = ext4_group_first_block_no(sb, e4b->bd_group); |
1807 | + le32_to_cpu(sbi->s_es->s_first_data_block); | 1804 | |
1808 | a = first_group_block + sbi->s_stripe - 1; | 1805 | a = first_group_block + sbi->s_stripe - 1; |
1809 | do_div(a, sbi->s_stripe); | 1806 | do_div(a, sbi->s_stripe); |
1810 | i = (a * sbi->s_stripe) - first_group_block; | 1807 | i = (a * sbi->s_stripe) - first_group_block; |
@@ -2256,7 +2253,7 @@ int ext4_mb_add_groupinfo(struct super_block *sb, ext4_group_t group, | |||
2256 | 2253 | ||
2257 | INIT_LIST_HEAD(&meta_group_info[i]->bb_prealloc_list); | 2254 | INIT_LIST_HEAD(&meta_group_info[i]->bb_prealloc_list); |
2258 | init_rwsem(&meta_group_info[i]->alloc_sem); | 2255 | init_rwsem(&meta_group_info[i]->alloc_sem); |
2259 | meta_group_info[i]->bb_free_root.rb_node = NULL; | 2256 | meta_group_info[i]->bb_free_root = RB_ROOT; |
2260 | 2257 | ||
2261 | #ifdef DOUBLE_CHECK | 2258 | #ifdef DOUBLE_CHECK |
2262 | { | 2259 | { |
@@ -2560,12 +2557,9 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn) | |||
2560 | ext4_unlock_group(sb, entry->group); | 2557 | ext4_unlock_group(sb, entry->group); |
2561 | if (test_opt(sb, DISCARD)) { | 2558 | if (test_opt(sb, DISCARD)) { |
2562 | ext4_fsblk_t discard_block; | 2559 | ext4_fsblk_t discard_block; |
2563 | struct ext4_super_block *es = EXT4_SB(sb)->s_es; | ||
2564 | 2560 | ||
2565 | discard_block = (ext4_fsblk_t)entry->group * | 2561 | discard_block = entry->start_blk + |
2566 | EXT4_BLOCKS_PER_GROUP(sb) | 2562 | ext4_group_first_block_no(sb, entry->group); |
2567 | + entry->start_blk | ||
2568 | + le32_to_cpu(es->s_first_data_block); | ||
2569 | trace_ext4_discard_blocks(sb, | 2563 | trace_ext4_discard_blocks(sb, |
2570 | (unsigned long long)discard_block, | 2564 | (unsigned long long)discard_block, |
2571 | entry->count); | 2565 | entry->count); |
@@ -2703,14 +2697,11 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, | |||
2703 | if (err) | 2697 | if (err) |
2704 | goto out_err; | 2698 | goto out_err; |
2705 | 2699 | ||
2706 | block = ac->ac_b_ex.fe_group * EXT4_BLOCKS_PER_GROUP(sb) | 2700 | block = ext4_grp_offs_to_block(sb, &ac->ac_b_ex); |
2707 | + ac->ac_b_ex.fe_start | ||
2708 | + le32_to_cpu(es->s_first_data_block); | ||
2709 | 2701 | ||
2710 | len = ac->ac_b_ex.fe_len; | 2702 | len = ac->ac_b_ex.fe_len; |
2711 | if (!ext4_data_block_valid(sbi, block, len)) { | 2703 | if (!ext4_data_block_valid(sbi, block, len)) { |
2712 | ext4_error(sb, __func__, | 2704 | ext4_error(sb, "Allocating blocks %llu-%llu which overlap " |
2713 | "Allocating blocks %llu-%llu which overlap " | ||
2714 | "fs metadata\n", block, block+len); | 2705 | "fs metadata\n", block, block+len); |
2715 | /* File system mounted not to panic on error | 2706 | /* File system mounted not to panic on error |
2716 | * Fix the bitmap and repeat the block allocation | 2707 | * Fix the bitmap and repeat the block allocation |
@@ -3161,9 +3152,7 @@ ext4_mb_use_preallocated(struct ext4_allocation_context *ac) | |||
3161 | /* The max size of hash table is PREALLOC_TB_SIZE */ | 3152 | /* The max size of hash table is PREALLOC_TB_SIZE */ |
3162 | order = PREALLOC_TB_SIZE - 1; | 3153 | order = PREALLOC_TB_SIZE - 1; |
3163 | 3154 | ||
3164 | goal_block = ac->ac_g_ex.fe_group * EXT4_BLOCKS_PER_GROUP(ac->ac_sb) + | 3155 | goal_block = ext4_grp_offs_to_block(ac->ac_sb, &ac->ac_g_ex); |
3165 | ac->ac_g_ex.fe_start + | ||
3166 | le32_to_cpu(EXT4_SB(ac->ac_sb)->s_es->s_first_data_block); | ||
3167 | /* | 3156 | /* |
3168 | * search for the prealloc space that is having | 3157 | * search for the prealloc space that is having |
3169 | * minimal distance from the goal block. | 3158 | * minimal distance from the goal block. |
@@ -3526,8 +3515,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh, | |||
3526 | if (bit >= end) | 3515 | if (bit >= end) |
3527 | break; | 3516 | break; |
3528 | next = mb_find_next_bit(bitmap_bh->b_data, end, bit); | 3517 | next = mb_find_next_bit(bitmap_bh->b_data, end, bit); |
3529 | start = group * EXT4_BLOCKS_PER_GROUP(sb) + bit + | 3518 | start = ext4_group_first_block_no(sb, group) + bit; |
3530 | le32_to_cpu(sbi->s_es->s_first_data_block); | ||
3531 | mb_debug(1, " free preallocated %u/%u in group %u\n", | 3519 | mb_debug(1, " free preallocated %u/%u in group %u\n", |
3532 | (unsigned) start, (unsigned) next - bit, | 3520 | (unsigned) start, (unsigned) next - bit, |
3533 | (unsigned) group); | 3521 | (unsigned) group); |
@@ -3623,15 +3611,13 @@ ext4_mb_discard_group_preallocations(struct super_block *sb, | |||
3623 | 3611 | ||
3624 | bitmap_bh = ext4_read_block_bitmap(sb, group); | 3612 | bitmap_bh = ext4_read_block_bitmap(sb, group); |
3625 | if (bitmap_bh == NULL) { | 3613 | if (bitmap_bh == NULL) { |
3626 | ext4_error(sb, __func__, "Error in reading block " | 3614 | ext4_error(sb, "Error reading block bitmap for %u", group); |
3627 | "bitmap for %u", group); | ||
3628 | return 0; | 3615 | return 0; |
3629 | } | 3616 | } |
3630 | 3617 | ||
3631 | err = ext4_mb_load_buddy(sb, group, &e4b); | 3618 | err = ext4_mb_load_buddy(sb, group, &e4b); |
3632 | if (err) { | 3619 | if (err) { |
3633 | ext4_error(sb, __func__, "Error in loading buddy " | 3620 | ext4_error(sb, "Error loading buddy information for %u", group); |
3634 | "information for %u", group); | ||
3635 | put_bh(bitmap_bh); | 3621 | put_bh(bitmap_bh); |
3636 | return 0; | 3622 | return 0; |
3637 | } | 3623 | } |
@@ -3804,15 +3790,15 @@ repeat: | |||
3804 | 3790 | ||
3805 | err = ext4_mb_load_buddy(sb, group, &e4b); | 3791 | err = ext4_mb_load_buddy(sb, group, &e4b); |
3806 | if (err) { | 3792 | if (err) { |
3807 | ext4_error(sb, __func__, "Error in loading buddy " | 3793 | ext4_error(sb, "Error loading buddy information for %u", |
3808 | "information for %u", group); | 3794 | group); |
3809 | continue; | 3795 | continue; |
3810 | } | 3796 | } |
3811 | 3797 | ||
3812 | bitmap_bh = ext4_read_block_bitmap(sb, group); | 3798 | bitmap_bh = ext4_read_block_bitmap(sb, group); |
3813 | if (bitmap_bh == NULL) { | 3799 | if (bitmap_bh == NULL) { |
3814 | ext4_error(sb, __func__, "Error in reading block " | 3800 | ext4_error(sb, "Error reading block bitmap for %u", |
3815 | "bitmap for %u", group); | 3801 | group); |
3816 | ext4_mb_release_desc(&e4b); | 3802 | ext4_mb_release_desc(&e4b); |
3817 | continue; | 3803 | continue; |
3818 | } | 3804 | } |
@@ -3938,7 +3924,7 @@ static void ext4_mb_group_or_file(struct ext4_allocation_context *ac) | |||
3938 | 3924 | ||
3939 | /* don't use group allocation for large files */ | 3925 | /* don't use group allocation for large files */ |
3940 | size = max(size, isize); | 3926 | size = max(size, isize); |
3941 | if (size >= sbi->s_mb_stream_request) { | 3927 | if (size > sbi->s_mb_stream_request) { |
3942 | ac->ac_flags |= EXT4_MB_STREAM_ALLOC; | 3928 | ac->ac_flags |= EXT4_MB_STREAM_ALLOC; |
3943 | return; | 3929 | return; |
3944 | } | 3930 | } |
@@ -4077,8 +4063,8 @@ ext4_mb_discard_lg_preallocations(struct super_block *sb, | |||
4077 | 4063 | ||
4078 | ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, NULL); | 4064 | ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, NULL); |
4079 | if (ext4_mb_load_buddy(sb, group, &e4b)) { | 4065 | if (ext4_mb_load_buddy(sb, group, &e4b)) { |
4080 | ext4_error(sb, __func__, "Error in loading buddy " | 4066 | ext4_error(sb, "Error loading buddy information for %u", |
4081 | "information for %u", group); | 4067 | group); |
4082 | continue; | 4068 | continue; |
4083 | } | 4069 | } |
4084 | ext4_lock_group(sb, group); | 4070 | ext4_lock_group(sb, group); |
@@ -4476,10 +4462,10 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode, | |||
4476 | 4462 | ||
4477 | sbi = EXT4_SB(sb); | 4463 | sbi = EXT4_SB(sb); |
4478 | es = EXT4_SB(sb)->s_es; | 4464 | es = EXT4_SB(sb)->s_es; |
4479 | if (!ext4_data_block_valid(sbi, block, count)) { | 4465 | if (!(flags & EXT4_FREE_BLOCKS_VALIDATED) && |
4480 | ext4_error(sb, __func__, | 4466 | !ext4_data_block_valid(sbi, block, count)) { |
4481 | "Freeing blocks not in datazone - " | 4467 | ext4_error(sb, "Freeing blocks not in datazone - " |
4482 | "block = %llu, count = %lu", block, count); | 4468 | "block = %llu, count = %lu", block, count); |
4483 | goto error_return; | 4469 | goto error_return; |
4484 | } | 4470 | } |
4485 | 4471 | ||
@@ -4547,8 +4533,7 @@ do_more: | |||
4547 | in_range(block + count - 1, ext4_inode_table(sb, gdp), | 4533 | in_range(block + count - 1, ext4_inode_table(sb, gdp), |
4548 | EXT4_SB(sb)->s_itb_per_group)) { | 4534 | EXT4_SB(sb)->s_itb_per_group)) { |
4549 | 4535 | ||
4550 | ext4_error(sb, __func__, | 4536 | ext4_error(sb, "Freeing blocks in system zone - " |
4551 | "Freeing blocks in system zone - " | ||
4552 | "Block = %llu, count = %lu", block, count); | 4537 | "Block = %llu, count = %lu", block, count); |
4553 | /* err = 0. ext4_std_error should be a no op */ | 4538 | /* err = 0. ext4_std_error should be a no op */ |
4554 | goto error_return; | 4539 | goto error_return; |