diff options
Diffstat (limited to 'fs/ext4/mballoc.c')
-rw-r--r-- | fs/ext4/mballoc.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 8d254ca83d9e..8d141a25bbee 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c | |||
@@ -2964,7 +2964,15 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, | |||
2964 | le16_add_cpu(&gdp->bg_free_blocks_count, -ac->ac_b_ex.fe_len); | 2964 | le16_add_cpu(&gdp->bg_free_blocks_count, -ac->ac_b_ex.fe_len); |
2965 | gdp->bg_checksum = ext4_group_desc_csum(sbi, ac->ac_b_ex.fe_group, gdp); | 2965 | gdp->bg_checksum = ext4_group_desc_csum(sbi, ac->ac_b_ex.fe_group, gdp); |
2966 | spin_unlock(sb_bgl_lock(sbi, ac->ac_b_ex.fe_group)); | 2966 | spin_unlock(sb_bgl_lock(sbi, ac->ac_b_ex.fe_group)); |
2967 | percpu_counter_sub(&sbi->s_freeblocks_counter, ac->ac_b_ex.fe_len); | 2967 | |
2968 | /* | ||
2969 | * free blocks account has already be reduced/reserved | ||
2970 | * at write_begin() time for delayed allocation | ||
2971 | * do not double accounting | ||
2972 | */ | ||
2973 | if (!(ac->ac_flags & EXT4_MB_DELALLOC_RESERVED)) | ||
2974 | percpu_counter_sub(&sbi->s_freeblocks_counter, | ||
2975 | ac->ac_b_ex.fe_len); | ||
2968 | 2976 | ||
2969 | if (sbi->s_log_groups_per_flex) { | 2977 | if (sbi->s_log_groups_per_flex) { |
2970 | ext4_group_t flex_group = ext4_flex_group(sbi, | 2978 | ext4_group_t flex_group = ext4_flex_group(sbi, |
@@ -4169,7 +4177,12 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, | |||
4169 | &(ar->len), errp); | 4177 | &(ar->len), errp); |
4170 | return block; | 4178 | return block; |
4171 | } | 4179 | } |
4172 | ar->len = ext4_has_free_blocks(sbi, ar->len); | 4180 | if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag) { |
4181 | /* | ||
4182 | * With delalloc we already reserved the blocks | ||
4183 | */ | ||
4184 | ar->len = ext4_has_free_blocks(sbi, ar->len); | ||
4185 | } | ||
4173 | 4186 | ||
4174 | if (ar->len == 0) { | 4187 | if (ar->len == 0) { |
4175 | *errp = -ENOSPC; | 4188 | *errp = -ENOSPC; |
@@ -4186,6 +4199,9 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, | |||
4186 | } | 4199 | } |
4187 | inquota = ar->len; | 4200 | inquota = ar->len; |
4188 | 4201 | ||
4202 | if (EXT4_I(ar->inode)->i_delalloc_reserved_flag) | ||
4203 | ar->flags |= EXT4_MB_DELALLOC_RESERVED; | ||
4204 | |||
4189 | ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); | 4205 | ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); |
4190 | if (!ac) { | 4206 | if (!ac) { |
4191 | ar->len = 0; | 4207 | ar->len = 0; |