aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/ctree.h26
-rw-r--r--fs/btrfs/delayed-inode.c6
-rw-r--r--fs/btrfs/extent-tree.c97
-rw-r--r--fs/btrfs/inode-map.c5
-rw-r--r--fs/btrfs/inode.c5
-rw-r--r--fs/btrfs/relocation.c12
-rw-r--r--fs/btrfs/transaction.c30
-rw-r--r--fs/btrfs/transaction.h2
8 files changed, 97 insertions, 86 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index c72ead869507..8fd9fe4282f5 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2900,6 +2900,18 @@ void btrfs_create_pending_block_groups(struct btrfs_trans_handle *trans,
2900u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags); 2900u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags);
2901u64 btrfs_get_alloc_profile(struct btrfs_root *root, int data); 2901u64 btrfs_get_alloc_profile(struct btrfs_root *root, int data);
2902void btrfs_clear_space_info_full(struct btrfs_fs_info *info); 2902void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
2903
2904enum btrfs_reserve_flush_enum {
2905 /* If we are in the transaction, we can't flush anything.*/
2906 BTRFS_RESERVE_NO_FLUSH,
2907 /*
2908 * Flushing delalloc may cause deadlock somewhere, in this
2909 * case, use FLUSH LIMIT
2910 */
2911 BTRFS_RESERVE_FLUSH_LIMIT,
2912 BTRFS_RESERVE_FLUSH_ALL,
2913};
2914
2903int btrfs_check_data_free_space(struct inode *inode, u64 bytes); 2915int btrfs_check_data_free_space(struct inode *inode, u64 bytes);
2904void btrfs_free_reserved_data_space(struct inode *inode, u64 bytes); 2916void btrfs_free_reserved_data_space(struct inode *inode, u64 bytes);
2905void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans, 2917void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans,
@@ -2919,19 +2931,13 @@ struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_root *root,
2919void btrfs_free_block_rsv(struct btrfs_root *root, 2931void btrfs_free_block_rsv(struct btrfs_root *root,
2920 struct btrfs_block_rsv *rsv); 2932 struct btrfs_block_rsv *rsv);
2921int btrfs_block_rsv_add(struct btrfs_root *root, 2933int btrfs_block_rsv_add(struct btrfs_root *root,
2922 struct btrfs_block_rsv *block_rsv, 2934 struct btrfs_block_rsv *block_rsv, u64 num_bytes,
2923 u64 num_bytes); 2935 enum btrfs_reserve_flush_enum flush);
2924int btrfs_block_rsv_add_noflush(struct btrfs_root *root,
2925 struct btrfs_block_rsv *block_rsv,
2926 u64 num_bytes);
2927int btrfs_block_rsv_check(struct btrfs_root *root, 2936int btrfs_block_rsv_check(struct btrfs_root *root,
2928 struct btrfs_block_rsv *block_rsv, int min_factor); 2937 struct btrfs_block_rsv *block_rsv, int min_factor);
2929int btrfs_block_rsv_refill(struct btrfs_root *root, 2938int btrfs_block_rsv_refill(struct btrfs_root *root,
2930 struct btrfs_block_rsv *block_rsv, 2939 struct btrfs_block_rsv *block_rsv, u64 min_reserved,
2931 u64 min_reserved); 2940 enum btrfs_reserve_flush_enum flush);
2932int btrfs_block_rsv_refill_noflush(struct btrfs_root *root,
2933 struct btrfs_block_rsv *block_rsv,
2934 u64 min_reserved);
2935int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv, 2941int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv,
2936 struct btrfs_block_rsv *dst_rsv, 2942 struct btrfs_block_rsv *dst_rsv,
2937 u64 num_bytes); 2943 u64 num_bytes);
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 478f66bdc57b..0c6dca550ea1 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -651,7 +651,8 @@ static int btrfs_delayed_inode_reserve_metadata(
651 */ 651 */
652 if (!src_rsv || (!trans->bytes_reserved && 652 if (!src_rsv || (!trans->bytes_reserved &&
653 src_rsv->type != BTRFS_BLOCK_RSV_DELALLOC)) { 653 src_rsv->type != BTRFS_BLOCK_RSV_DELALLOC)) {
654 ret = btrfs_block_rsv_add_noflush(root, dst_rsv, num_bytes); 654 ret = btrfs_block_rsv_add(root, dst_rsv, num_bytes,
655 BTRFS_RESERVE_NO_FLUSH);
655 /* 656 /*
656 * Since we're under a transaction reserve_metadata_bytes could 657 * Since we're under a transaction reserve_metadata_bytes could
657 * try to commit the transaction which will make it return 658 * try to commit the transaction which will make it return
@@ -686,7 +687,8 @@ static int btrfs_delayed_inode_reserve_metadata(
686 * reserve something strictly for us. If not be a pain and try 687 * reserve something strictly for us. If not be a pain and try
687 * to steal from the delalloc block rsv. 688 * to steal from the delalloc block rsv.
688 */ 689 */
689 ret = btrfs_block_rsv_add_noflush(root, dst_rsv, num_bytes); 690 ret = btrfs_block_rsv_add(root, dst_rsv, num_bytes,
691 BTRFS_RESERVE_NO_FLUSH);
690 if (!ret) 692 if (!ret)
691 goto out; 693 goto out;
692 694
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 2cfcce290aba..2136adda2a0f 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3644,7 +3644,7 @@ out:
3644 3644
3645static int can_overcommit(struct btrfs_root *root, 3645static int can_overcommit(struct btrfs_root *root,
3646 struct btrfs_space_info *space_info, u64 bytes, 3646 struct btrfs_space_info *space_info, u64 bytes,
3647 int flush) 3647 enum btrfs_reserve_flush_enum flush)
3648{ 3648{
3649 u64 profile = btrfs_get_alloc_profile(root, 0); 3649 u64 profile = btrfs_get_alloc_profile(root, 0);
3650 u64 avail; 3650 u64 avail;
@@ -3672,7 +3672,7 @@ static int can_overcommit(struct btrfs_root *root,
3672 * 1/2th of the space. If we can flush, don't let us overcommit 3672 * 1/2th of the space. If we can flush, don't let us overcommit
3673 * too much, let it overcommit up to 1/8 of the space. 3673 * too much, let it overcommit up to 1/8 of the space.
3674 */ 3674 */
3675 if (flush) 3675 if (flush == BTRFS_RESERVE_FLUSH_ALL)
3676 avail >>= 3; 3676 avail >>= 3;
3677 else 3677 else
3678 avail >>= 1; 3678 avail >>= 1;
@@ -3696,6 +3696,7 @@ static void shrink_delalloc(struct btrfs_root *root, u64 to_reclaim, u64 orig,
3696 long time_left; 3696 long time_left;
3697 unsigned long nr_pages = (2 * 1024 * 1024) >> PAGE_CACHE_SHIFT; 3697 unsigned long nr_pages = (2 * 1024 * 1024) >> PAGE_CACHE_SHIFT;
3698 int loops = 0; 3698 int loops = 0;
3699 enum btrfs_reserve_flush_enum flush;
3699 3700
3700 trans = (struct btrfs_trans_handle *)current->journal_info; 3701 trans = (struct btrfs_trans_handle *)current->journal_info;
3701 block_rsv = &root->fs_info->delalloc_block_rsv; 3702 block_rsv = &root->fs_info->delalloc_block_rsv;
@@ -3723,8 +3724,12 @@ static void shrink_delalloc(struct btrfs_root *root, u64 to_reclaim, u64 orig,
3723 wait_event(root->fs_info->async_submit_wait, 3724 wait_event(root->fs_info->async_submit_wait,
3724 !atomic_read(&root->fs_info->async_delalloc_pages)); 3725 !atomic_read(&root->fs_info->async_delalloc_pages));
3725 3726
3727 if (!trans)
3728 flush = BTRFS_RESERVE_FLUSH_ALL;
3729 else
3730 flush = BTRFS_RESERVE_NO_FLUSH;
3726 spin_lock(&space_info->lock); 3731 spin_lock(&space_info->lock);
3727 if (can_overcommit(root, space_info, orig, !trans)) { 3732 if (can_overcommit(root, space_info, orig, flush)) {
3728 spin_unlock(&space_info->lock); 3733 spin_unlock(&space_info->lock);
3729 break; 3734 break;
3730 } 3735 }
@@ -3882,7 +3887,8 @@ static int flush_space(struct btrfs_root *root,
3882 */ 3887 */
3883static int reserve_metadata_bytes(struct btrfs_root *root, 3888static int reserve_metadata_bytes(struct btrfs_root *root,
3884 struct btrfs_block_rsv *block_rsv, 3889 struct btrfs_block_rsv *block_rsv,
3885 u64 orig_bytes, int flush) 3890 u64 orig_bytes,
3891 enum btrfs_reserve_flush_enum flush)
3886{ 3892{
3887 struct btrfs_space_info *space_info = block_rsv->space_info; 3893 struct btrfs_space_info *space_info = block_rsv->space_info;
3888 u64 used; 3894 u64 used;
@@ -3895,10 +3901,11 @@ again:
3895 ret = 0; 3901 ret = 0;
3896 spin_lock(&space_info->lock); 3902 spin_lock(&space_info->lock);
3897 /* 3903 /*
3898 * We only want to wait if somebody other than us is flushing and we are 3904 * We only want to wait if somebody other than us is flushing and we
3899 * actually alloed to flush. 3905 * are actually allowed to flush all things.
3900 */ 3906 */
3901 while (flush && !flushing && space_info->flush) { 3907 while (flush == BTRFS_RESERVE_FLUSH_ALL && !flushing &&
3908 space_info->flush) {
3902 spin_unlock(&space_info->lock); 3909 spin_unlock(&space_info->lock);
3903 /* 3910 /*
3904 * If we have a trans handle we can't wait because the flusher 3911 * If we have a trans handle we can't wait because the flusher
@@ -3964,23 +3971,40 @@ again:
3964 * Couldn't make our reservation, save our place so while we're trying 3971 * Couldn't make our reservation, save our place so while we're trying
3965 * to reclaim space we can actually use it instead of somebody else 3972 * to reclaim space we can actually use it instead of somebody else
3966 * stealing it from us. 3973 * stealing it from us.
3974 *
3975 * We make the other tasks wait for the flush only when we can flush
3976 * all things.
3967 */ 3977 */
3968 if (ret && flush) { 3978 if (ret && flush == BTRFS_RESERVE_FLUSH_ALL) {
3969 flushing = true; 3979 flushing = true;
3970 space_info->flush = 1; 3980 space_info->flush = 1;
3971 } 3981 }
3972 3982
3973 spin_unlock(&space_info->lock); 3983 spin_unlock(&space_info->lock);
3974 3984
3975 if (!ret || !flush) 3985 if (!ret || flush == BTRFS_RESERVE_NO_FLUSH)
3976 goto out; 3986 goto out;
3977 3987
3978 ret = flush_space(root, space_info, num_bytes, orig_bytes, 3988 ret = flush_space(root, space_info, num_bytes, orig_bytes,
3979 flush_state); 3989 flush_state);
3980 flush_state++; 3990 flush_state++;
3991
3992 /*
3993 * If we are FLUSH_LIMIT, we can not flush delalloc, or the deadlock
3994 * would happen. So skip delalloc flush.
3995 */
3996 if (flush == BTRFS_RESERVE_FLUSH_LIMIT &&
3997 (flush_state == FLUSH_DELALLOC ||
3998 flush_state == FLUSH_DELALLOC_WAIT))
3999 flush_state = ALLOC_CHUNK;
4000
3981 if (!ret) 4001 if (!ret)
3982 goto again; 4002 goto again;
3983 else if (flush_state <= COMMIT_TRANS) 4003 else if (flush == BTRFS_RESERVE_FLUSH_LIMIT &&
4004 flush_state < COMMIT_TRANS)
4005 goto again;
4006 else if (flush == BTRFS_RESERVE_FLUSH_ALL &&
4007 flush_state <= COMMIT_TRANS)
3984 goto again; 4008 goto again;
3985 4009
3986out: 4010out:
@@ -4131,9 +4155,9 @@ void btrfs_free_block_rsv(struct btrfs_root *root,
4131 kfree(rsv); 4155 kfree(rsv);
4132} 4156}
4133 4157
4134static inline int __block_rsv_add(struct btrfs_root *root, 4158int btrfs_block_rsv_add(struct btrfs_root *root,
4135 struct btrfs_block_rsv *block_rsv, 4159 struct btrfs_block_rsv *block_rsv, u64 num_bytes,
4136 u64 num_bytes, int flush) 4160 enum btrfs_reserve_flush_enum flush)
4137{ 4161{
4138 int ret; 4162 int ret;
4139 4163
@@ -4149,20 +4173,6 @@ static inline int __block_rsv_add(struct btrfs_root *root,
4149 return ret; 4173 return ret;
4150} 4174}
4151 4175
4152int btrfs_block_rsv_add(struct btrfs_root *root,
4153 struct btrfs_block_rsv *block_rsv,
4154 u64 num_bytes)
4155{
4156 return __block_rsv_add(root, block_rsv, num_bytes, 1);
4157}
4158
4159int btrfs_block_rsv_add_noflush(struct btrfs_root *root,
4160 struct btrfs_block_rsv *block_rsv,
4161 u64 num_bytes)
4162{
4163 return __block_rsv_add(root, block_rsv, num_bytes, 0);
4164}
4165
4166int btrfs_block_rsv_check(struct btrfs_root *root, 4176int btrfs_block_rsv_check(struct btrfs_root *root,
4167 struct btrfs_block_rsv *block_rsv, int min_factor) 4177 struct btrfs_block_rsv *block_rsv, int min_factor)
4168{ 4178{
@@ -4181,9 +4191,9 @@ int btrfs_block_rsv_check(struct btrfs_root *root,
4181 return ret; 4191 return ret;
4182} 4192}
4183 4193
4184static inline int __btrfs_block_rsv_refill(struct btrfs_root *root, 4194int btrfs_block_rsv_refill(struct btrfs_root *root,
4185 struct btrfs_block_rsv *block_rsv, 4195 struct btrfs_block_rsv *block_rsv, u64 min_reserved,
4186 u64 min_reserved, int flush) 4196 enum btrfs_reserve_flush_enum flush)
4187{ 4197{
4188 u64 num_bytes = 0; 4198 u64 num_bytes = 0;
4189 int ret = -ENOSPC; 4199 int ret = -ENOSPC;
@@ -4211,20 +4221,6 @@ static inline int __btrfs_block_rsv_refill(struct btrfs_root *root,
4211 return ret; 4221 return ret;
4212} 4222}
4213 4223
4214int btrfs_block_rsv_refill(struct btrfs_root *root,
4215 struct btrfs_block_rsv *block_rsv,
4216 u64 min_reserved)
4217{
4218 return __btrfs_block_rsv_refill(root, block_rsv, min_reserved, 1);
4219}
4220
4221int btrfs_block_rsv_refill_noflush(struct btrfs_root *root,
4222 struct btrfs_block_rsv *block_rsv,
4223 u64 min_reserved)
4224{
4225 return __btrfs_block_rsv_refill(root, block_rsv, min_reserved, 0);
4226}
4227
4228int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv, 4224int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv,
4229 struct btrfs_block_rsv *dst_rsv, 4225 struct btrfs_block_rsv *dst_rsv,
4230 u64 num_bytes) 4226 u64 num_bytes)
@@ -4515,14 +4511,15 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes)
4515 u64 csum_bytes; 4511 u64 csum_bytes;
4516 unsigned nr_extents = 0; 4512 unsigned nr_extents = 0;
4517 int extra_reserve = 0; 4513 int extra_reserve = 0;
4518 int flush = 1; 4514 enum btrfs_reserve_flush_enum flush = BTRFS_RESERVE_FLUSH_ALL;
4519 int ret; 4515 int ret;
4520 4516
4521 /* Need to be holding the i_mutex here if we aren't free space cache */ 4517 /* Need to be holding the i_mutex here if we aren't free space cache */
4522 if (btrfs_is_free_space_inode(inode)) 4518 if (btrfs_is_free_space_inode(inode))
4523 flush = 0; 4519 flush = BTRFS_RESERVE_NO_FLUSH;
4524 4520
4525 if (flush && btrfs_transaction_in_commit(root->fs_info)) 4521 if (flush != BTRFS_RESERVE_NO_FLUSH &&
4522 btrfs_transaction_in_commit(root->fs_info))
4526 schedule_timeout(1); 4523 schedule_timeout(1);
4527 4524
4528 mutex_lock(&BTRFS_I(inode)->delalloc_mutex); 4525 mutex_lock(&BTRFS_I(inode)->delalloc_mutex);
@@ -6252,7 +6249,8 @@ use_block_rsv(struct btrfs_trans_handle *trans,
6252 block_rsv = get_block_rsv(trans, root); 6249 block_rsv = get_block_rsv(trans, root);
6253 6250
6254 if (block_rsv->size == 0) { 6251 if (block_rsv->size == 0) {
6255 ret = reserve_metadata_bytes(root, block_rsv, blocksize, 0); 6252 ret = reserve_metadata_bytes(root, block_rsv, blocksize,
6253 BTRFS_RESERVE_NO_FLUSH);
6256 /* 6254 /*
6257 * If we couldn't reserve metadata bytes try and use some from 6255 * If we couldn't reserve metadata bytes try and use some from
6258 * the global reserve. 6256 * the global reserve.
@@ -6279,7 +6277,8 @@ use_block_rsv(struct btrfs_trans_handle *trans,
6279 printk(KERN_DEBUG "btrfs: block rsv returned %d\n", ret); 6277 printk(KERN_DEBUG "btrfs: block rsv returned %d\n", ret);
6280 WARN_ON(1); 6278 WARN_ON(1);
6281 } 6279 }
6282 ret = reserve_metadata_bytes(root, block_rsv, blocksize, 0); 6280 ret = reserve_metadata_bytes(root, block_rsv, blocksize,
6281 BTRFS_RESERVE_NO_FLUSH);
6283 if (!ret) { 6282 if (!ret) {
6284 return block_rsv; 6283 return block_rsv;
6285 } else if (ret && block_rsv != global_rsv) { 6284 } else if (ret && block_rsv != global_rsv) {
diff --git a/fs/btrfs/inode-map.c b/fs/btrfs/inode-map.c
index b1a1c929ba80..d26f67a59e36 100644
--- a/fs/btrfs/inode-map.c
+++ b/fs/btrfs/inode-map.c
@@ -434,8 +434,9 @@ int btrfs_save_ino_cache(struct btrfs_root *root,
434 * 3 items for pre-allocation 434 * 3 items for pre-allocation
435 */ 435 */
436 trans->bytes_reserved = btrfs_calc_trans_metadata_size(root, 8); 436 trans->bytes_reserved = btrfs_calc_trans_metadata_size(root, 8);
437 ret = btrfs_block_rsv_add_noflush(root, trans->block_rsv, 437 ret = btrfs_block_rsv_add(root, trans->block_rsv,
438 trans->bytes_reserved); 438 trans->bytes_reserved,
439 BTRFS_RESERVE_NO_FLUSH);
439 if (ret) 440 if (ret)
440 goto out; 441 goto out;
441 trace_btrfs_space_reservation(root->fs_info, "ino_cache", 442 trace_btrfs_space_reservation(root->fs_info, "ino_cache",
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 95542a1b3dfc..db3dd4ed057f 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3829,7 +3829,8 @@ void btrfs_evict_inode(struct inode *inode)
3829 * inode item when doing the truncate. 3829 * inode item when doing the truncate.
3830 */ 3830 */
3831 while (1) { 3831 while (1) {
3832 ret = btrfs_block_rsv_refill_noflush(root, rsv, min_size); 3832 ret = btrfs_block_rsv_refill(root, rsv, min_size,
3833 BTRFS_RESERVE_FLUSH_LIMIT);
3833 3834
3834 /* 3835 /*
3835 * Try and steal from the global reserve since we will 3836 * Try and steal from the global reserve since we will
@@ -3847,7 +3848,7 @@ void btrfs_evict_inode(struct inode *inode)
3847 goto no_delete; 3848 goto no_delete;
3848 } 3849 }
3849 3850
3850 trans = btrfs_start_transaction_noflush(root, 1); 3851 trans = btrfs_start_transaction_lflush(root, 1);
3851 if (IS_ERR(trans)) { 3852 if (IS_ERR(trans)) {
3852 btrfs_orphan_del(NULL, inode); 3853 btrfs_orphan_del(NULL, inode);
3853 btrfs_free_block_rsv(root, rsv); 3854 btrfs_free_block_rsv(root, rsv);
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 776f0aa128fc..242d6de4d8eb 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2074,7 +2074,8 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
2074 BUG_ON(IS_ERR(trans)); 2074 BUG_ON(IS_ERR(trans));
2075 trans->block_rsv = rc->block_rsv; 2075 trans->block_rsv = rc->block_rsv;
2076 2076
2077 ret = btrfs_block_rsv_refill(root, rc->block_rsv, min_reserved); 2077 ret = btrfs_block_rsv_refill(root, rc->block_rsv, min_reserved,
2078 BTRFS_RESERVE_FLUSH_ALL);
2078 if (ret) { 2079 if (ret) {
2079 BUG_ON(ret != -EAGAIN); 2080 BUG_ON(ret != -EAGAIN);
2080 ret = btrfs_commit_transaction(trans, root); 2081 ret = btrfs_commit_transaction(trans, root);
@@ -2184,7 +2185,8 @@ int prepare_to_merge(struct reloc_control *rc, int err)
2184again: 2185again:
2185 if (!err) { 2186 if (!err) {
2186 num_bytes = rc->merging_rsv_size; 2187 num_bytes = rc->merging_rsv_size;
2187 ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes); 2188 ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes,
2189 BTRFS_RESERVE_FLUSH_ALL);
2188 if (ret) 2190 if (ret)
2189 err = ret; 2191 err = ret;
2190 } 2192 }
@@ -2459,7 +2461,8 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans,
2459 num_bytes = calcu_metadata_size(rc, node, 1) * 2; 2461 num_bytes = calcu_metadata_size(rc, node, 1) * 2;
2460 2462
2461 trans->block_rsv = rc->block_rsv; 2463 trans->block_rsv = rc->block_rsv;
2462 ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes); 2464 ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes,
2465 BTRFS_RESERVE_FLUSH_ALL);
2463 if (ret) { 2466 if (ret) {
2464 if (ret == -EAGAIN) 2467 if (ret == -EAGAIN)
2465 rc->commit_transaction = 1; 2468 rc->commit_transaction = 1;
@@ -3685,7 +3688,8 @@ int prepare_to_relocate(struct reloc_control *rc)
3685 * is no reservation in transaction handle. 3688 * is no reservation in transaction handle.
3686 */ 3689 */
3687 ret = btrfs_block_rsv_add(rc->extent_root, rc->block_rsv, 3690 ret = btrfs_block_rsv_add(rc->extent_root, rc->block_rsv,
3688 rc->extent_root->nodesize * 256); 3691 rc->extent_root->nodesize * 256,
3692 BTRFS_RESERVE_FLUSH_ALL);
3689 if (ret) 3693 if (ret)
3690 return ret; 3694 return ret;
3691 3695
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 04bbfb1052eb..4e1def4c06b1 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -295,9 +295,9 @@ static int may_wait_transaction(struct btrfs_root *root, int type)
295 return 0; 295 return 0;
296} 296}
297 297
298static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, 298static struct btrfs_trans_handle *
299 u64 num_items, int type, 299start_transaction(struct btrfs_root *root, u64 num_items, int type,
300 int noflush) 300 enum btrfs_reserve_flush_enum flush)
301{ 301{
302 struct btrfs_trans_handle *h; 302 struct btrfs_trans_handle *h;
303 struct btrfs_transaction *cur_trans; 303 struct btrfs_transaction *cur_trans;
@@ -331,14 +331,9 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
331 } 331 }
332 332
333 num_bytes = btrfs_calc_trans_metadata_size(root, num_items); 333 num_bytes = btrfs_calc_trans_metadata_size(root, num_items);
334 if (noflush) 334 ret = btrfs_block_rsv_add(root,
335 ret = btrfs_block_rsv_add_noflush(root, 335 &root->fs_info->trans_block_rsv,
336 &root->fs_info->trans_block_rsv, 336 num_bytes, flush);
337 num_bytes);
338 else
339 ret = btrfs_block_rsv_add(root,
340 &root->fs_info->trans_block_rsv,
341 num_bytes);
342 if (ret) 337 if (ret)
343 return ERR_PTR(ret); 338 return ERR_PTR(ret);
344 } 339 }
@@ -422,13 +417,15 @@ got_it:
422struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, 417struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
423 int num_items) 418 int num_items)
424{ 419{
425 return start_transaction(root, num_items, TRANS_START, 0); 420 return start_transaction(root, num_items, TRANS_START,
421 BTRFS_RESERVE_FLUSH_ALL);
426} 422}
427 423
428struct btrfs_trans_handle *btrfs_start_transaction_noflush( 424struct btrfs_trans_handle *btrfs_start_transaction_lflush(
429 struct btrfs_root *root, int num_items) 425 struct btrfs_root *root, int num_items)
430{ 426{
431 return start_transaction(root, num_items, TRANS_START, 1); 427 return start_transaction(root, num_items, TRANS_START,
428 BTRFS_RESERVE_FLUSH_LIMIT);
432} 429}
433 430
434struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root) 431struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root)
@@ -1032,8 +1029,9 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
1032 btrfs_reloc_pre_snapshot(trans, pending, &to_reserve); 1029 btrfs_reloc_pre_snapshot(trans, pending, &to_reserve);
1033 1030
1034 if (to_reserve > 0) { 1031 if (to_reserve > 0) {
1035 ret = btrfs_block_rsv_add_noflush(root, &pending->block_rsv, 1032 ret = btrfs_block_rsv_add(root, &pending->block_rsv,
1036 to_reserve); 1033 to_reserve,
1034 BTRFS_RESERVE_NO_FLUSH);
1037 if (ret) { 1035 if (ret) {
1038 pending->error = ret; 1036 pending->error = ret;
1039 goto no_free_objectid; 1037 goto no_free_objectid;
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
index 80961947a6b2..0e8aa1e6c287 100644
--- a/fs/btrfs/transaction.h
+++ b/fs/btrfs/transaction.h
@@ -105,7 +105,7 @@ int btrfs_end_transaction(struct btrfs_trans_handle *trans,
105 struct btrfs_root *root); 105 struct btrfs_root *root);
106struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, 106struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
107 int num_items); 107 int num_items);
108struct btrfs_trans_handle *btrfs_start_transaction_noflush( 108struct btrfs_trans_handle *btrfs_start_transaction_lflush(
109 struct btrfs_root *root, int num_items); 109 struct btrfs_root *root, int num_items);
110struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root); 110struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root);
111struct btrfs_trans_handle *btrfs_join_transaction_nolock(struct btrfs_root *root); 111struct btrfs_trans_handle *btrfs_join_transaction_nolock(struct btrfs_root *root);