aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorZhao Lei <zhaolei@cn.fujitsu.com>2015-02-14 00:23:45 -0500
committerChris Mason <clm@fb.com>2015-04-13 10:26:40 -0400
commit94b947b2f3f84f3bba25d34c4e2a229fc2276830 (patch)
tree802839c6379786086b980f44a6ed852bcbcb8e86 /fs/btrfs
parentde249e66a73d696666281cd812087979c6fae552 (diff)
btrfs: fix condition of commit transaction
Old code bypass commit transaction when we don't have enough pinned space, but another case is there exist freed bgs in current transction, it have possibility to make alloc_chunk success. This patch modify the condition to: if (have_free_bg || have_pinned_space) commit_transaction() Confirmed above action by printk before and after patch. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/extent-tree.c22
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,