diff options
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/extent-tree.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 875ba519a131..7b227a65078c 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -3857,7 +3857,9 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes) | |||
3857 | struct btrfs_root *root = BTRFS_I(inode)->root; | 3857 | struct btrfs_root *root = BTRFS_I(inode)->root; |
3858 | struct btrfs_fs_info *fs_info = root->fs_info; | 3858 | struct btrfs_fs_info *fs_info = root->fs_info; |
3859 | u64 used; | 3859 | u64 used; |
3860 | int ret = 0, committed = 0; | 3860 | int ret = 0; |
3861 | int committed = 0; | ||
3862 | int have_pinned_space = 1; | ||
3861 | 3863 | ||
3862 | /* make sure bytes are sectorsize aligned */ | 3864 | /* make sure bytes are sectorsize aligned */ |
3863 | bytes = ALIGN(bytes, root->sectorsize); | 3865 | bytes = ALIGN(bytes, root->sectorsize); |
@@ -3925,11 +3927,12 @@ alloc: | |||
3925 | 3927 | ||
3926 | /* | 3928 | /* |
3927 | * If we don't have enough pinned space to deal with this | 3929 | * If we don't have enough pinned space to deal with this |
3928 | * allocation don't bother committing the transaction. | 3930 | * allocation, and no removed chunk in current transaction, |
3931 | * don't bother committing the transaction. | ||
3929 | */ | 3932 | */ |
3930 | if (percpu_counter_compare(&data_sinfo->total_bytes_pinned, | 3933 | if (percpu_counter_compare(&data_sinfo->total_bytes_pinned, |
3931 | bytes) < 0) | 3934 | bytes) < 0) |
3932 | committed = 1; | 3935 | have_pinned_space = 0; |
3933 | spin_unlock(&data_sinfo->lock); | 3936 | spin_unlock(&data_sinfo->lock); |
3934 | 3937 | ||
3935 | /* commit the current transaction and try again */ | 3938 | /* commit the current transaction and try again */ |
@@ -3941,10 +3944,15 @@ commit_trans: | |||
3941 | trans = btrfs_join_transaction(root); | 3944 | trans = btrfs_join_transaction(root); |
3942 | if (IS_ERR(trans)) | 3945 | if (IS_ERR(trans)) |
3943 | return PTR_ERR(trans); | 3946 | return PTR_ERR(trans); |
3944 | ret = btrfs_commit_transaction(trans, root); | 3947 | if (have_pinned_space || |
3945 | if (ret) | 3948 | trans->transaction->have_free_bgs) { |
3946 | return ret; | 3949 | ret = btrfs_commit_transaction(trans, root); |
3947 | goto again; | 3950 | if (ret) |
3951 | return ret; | ||
3952 | goto again; | ||
3953 | } else { | ||
3954 | btrfs_end_transaction(trans, root); | ||
3955 | } | ||
3948 | } | 3956 | } |
3949 | 3957 | ||
3950 | trace_btrfs_space_reservation(root->fs_info, | 3958 | trace_btrfs_space_reservation(root->fs_info, |