diff options
-rw-r--r-- | fs/btrfs/extent-tree.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index faff98f720de..e035731b3608 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -3672,13 +3672,30 @@ static int can_overcommit(struct btrfs_root *root, | |||
3672 | struct btrfs_space_info *space_info, u64 bytes, | 3672 | struct btrfs_space_info *space_info, u64 bytes, |
3673 | enum btrfs_reserve_flush_enum flush) | 3673 | enum btrfs_reserve_flush_enum flush) |
3674 | { | 3674 | { |
3675 | struct btrfs_block_rsv *global_rsv = &root->fs_info->global_block_rsv; | ||
3675 | u64 profile = btrfs_get_alloc_profile(root, 0); | 3676 | u64 profile = btrfs_get_alloc_profile(root, 0); |
3677 | u64 rsv_size = 0; | ||
3676 | u64 avail; | 3678 | u64 avail; |
3677 | u64 used; | 3679 | u64 used; |
3678 | 3680 | ||
3679 | used = space_info->bytes_used + space_info->bytes_reserved + | 3681 | used = space_info->bytes_used + space_info->bytes_reserved + |
3680 | space_info->bytes_pinned + space_info->bytes_readonly + | 3682 | space_info->bytes_pinned + space_info->bytes_readonly; |
3681 | space_info->bytes_may_use; | 3683 | |
3684 | spin_lock(&global_rsv->lock); | ||
3685 | rsv_size = global_rsv->size; | ||
3686 | spin_unlock(&global_rsv->lock); | ||
3687 | |||
3688 | /* | ||
3689 | * We only want to allow over committing if we have lots of actual space | ||
3690 | * free, but if we don't have enough space to handle the global reserve | ||
3691 | * space then we could end up having a real enospc problem when trying | ||
3692 | * to allocate a chunk or some other such important allocation. | ||
3693 | */ | ||
3694 | rsv_size <<= 1; | ||
3695 | if (used + rsv_size >= space_info->total_bytes) | ||
3696 | return 0; | ||
3697 | |||
3698 | used += space_info->bytes_may_use; | ||
3682 | 3699 | ||
3683 | spin_lock(&root->fs_info->free_chunk_lock); | 3700 | spin_lock(&root->fs_info->free_chunk_lock); |
3684 | avail = root->fs_info->free_chunk_space; | 3701 | avail = root->fs_info->free_chunk_space; |