summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/backref.c2
-rw-r--r--fs/btrfs/delayed-inode.c4
-rw-r--r--fs/btrfs/dev-replace.c10
-rw-r--r--fs/btrfs/disk-io.c8
-rw-r--r--fs/btrfs/extent-tree.c31
-rw-r--r--fs/btrfs/extent_io.c2
-rw-r--r--fs/btrfs/file.c20
-rw-r--r--fs/btrfs/free-space-tree.c8
-rw-r--r--fs/btrfs/inode.c74
-rw-r--r--fs/btrfs/ioctl.c65
-rw-r--r--fs/btrfs/qgroup.c8
-rw-r--r--fs/btrfs/relocation.c30
-rw-r--r--fs/btrfs/root-tree.c2
-rw-r--r--fs/btrfs/scrub.c9
-rw-r--r--fs/btrfs/send.c4
-rw-r--r--fs/btrfs/super.c4
-rw-r--r--fs/btrfs/transaction.c59
-rw-r--r--fs/btrfs/transaction.h18
-rw-r--r--fs/btrfs/tree-log.c4
-rw-r--r--fs/btrfs/uuid-tree.c2
-rw-r--r--fs/btrfs/volumes.c33
-rw-r--r--fs/btrfs/xattr.c2
22 files changed, 188 insertions, 211 deletions
diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 4577c028333a..8299601a3549 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -2056,7 +2056,7 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
2056out: 2056out:
2057 if (!search_commit_root) { 2057 if (!search_commit_root) {
2058 btrfs_put_tree_mod_seq(fs_info, &tree_mod_seq_elem); 2058 btrfs_put_tree_mod_seq(fs_info, &tree_mod_seq_elem);
2059 btrfs_end_transaction(trans, fs_info->extent_root); 2059 btrfs_end_transaction(trans);
2060 } else { 2060 } else {
2061 up_read(&fs_info->commit_root_sem); 2061 up_read(&fs_info->commit_root_sem);
2062 } 2062 }
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
index 33ed79b8d6cc..be007c1b5592 100644
--- a/fs/btrfs/delayed-inode.c
+++ b/fs/btrfs/delayed-inode.c
@@ -1280,7 +1280,7 @@ int btrfs_commit_inode_delayed_inode(struct inode *inode)
1280 btrfs_free_path(path); 1280 btrfs_free_path(path);
1281 trans->block_rsv = block_rsv; 1281 trans->block_rsv = block_rsv;
1282trans_out: 1282trans_out:
1283 btrfs_end_transaction(trans, delayed_node->root); 1283 btrfs_end_transaction(trans);
1284 btrfs_btree_balance_dirty(fs_info); 1284 btrfs_btree_balance_dirty(fs_info);
1285out: 1285out:
1286 btrfs_release_delayed_node(delayed_node); 1286 btrfs_release_delayed_node(delayed_node);
@@ -1345,7 +1345,7 @@ again:
1345 __btrfs_commit_inode_delayed_items(trans, path, delayed_node); 1345 __btrfs_commit_inode_delayed_items(trans, path, delayed_node);
1346 1346
1347 trans->block_rsv = block_rsv; 1347 trans->block_rsv = block_rsv;
1348 btrfs_end_transaction(trans, root); 1348 btrfs_end_transaction(trans);
1349 btrfs_btree_balance_dirty_nodelay(root->fs_info); 1349 btrfs_btree_balance_dirty_nodelay(root->fs_info);
1350 1350
1351release_path: 1351release_path:
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 1b545885f7b1..5de280b9ad73 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -335,7 +335,7 @@ int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, char *tgtdev_name,
335 */ 335 */
336 trans = btrfs_attach_transaction(root); 336 trans = btrfs_attach_transaction(root);
337 if (!IS_ERR(trans)) { 337 if (!IS_ERR(trans)) {
338 ret = btrfs_commit_transaction(trans, root); 338 ret = btrfs_commit_transaction(trans);
339 if (ret) 339 if (ret)
340 return ret; 340 return ret;
341 } else if (PTR_ERR(trans) != -ENOENT) { 341 } else if (PTR_ERR(trans) != -ENOENT) {
@@ -397,7 +397,7 @@ int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info, char *tgtdev_name,
397 goto leave; 397 goto leave;
398 } 398 }
399 399
400 ret = btrfs_commit_transaction(trans, root); 400 ret = btrfs_commit_transaction(trans);
401 WARN_ON(ret); 401 WARN_ON(ret);
402 402
403 /* the disk copy procedure reuses the scrub code */ 403 /* the disk copy procedure reuses the scrub code */
@@ -513,7 +513,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
513 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); 513 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
514 return PTR_ERR(trans); 514 return PTR_ERR(trans);
515 } 515 }
516 ret = btrfs_commit_transaction(trans, root); 516 ret = btrfs_commit_transaction(trans);
517 WARN_ON(ret); 517 WARN_ON(ret);
518 518
519 mutex_lock(&uuid_mutex); 519 mutex_lock(&uuid_mutex);
@@ -603,7 +603,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
603 /* write back the superblocks */ 603 /* write back the superblocks */
604 trans = btrfs_start_transaction(root, 0); 604 trans = btrfs_start_transaction(root, 0);
605 if (!IS_ERR(trans)) 605 if (!IS_ERR(trans))
606 btrfs_commit_transaction(trans, root); 606 btrfs_commit_transaction(trans);
607 607
608 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); 608 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
609 609
@@ -718,7 +718,7 @@ static u64 __btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info)
718 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount); 718 mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
719 return PTR_ERR(trans); 719 return PTR_ERR(trans);
720 } 720 }
721 ret = btrfs_commit_transaction(trans, root); 721 ret = btrfs_commit_transaction(trans);
722 WARN_ON(ret); 722 WARN_ON(ret);
723 if (tgt_device) 723 if (tgt_device)
724 btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device); 724 btrfs_destroy_dev_replace_tgtdev(fs_info, tgt_device);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 3ce36b526ebe..196f1aafcea9 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1913,7 +1913,7 @@ sleep:
1913 } else { 1913 } else {
1914 int ret; 1914 int ret;
1915 1915
1916 ret = btrfs_commit_transaction(trans, root); 1916 ret = btrfs_commit_transaction(trans);
1917 if (ret) 1917 if (ret)
1918 btrfs_err(fs_info, 1918 btrfs_err(fs_info,
1919 "cleaner open transaction commit returned %d", 1919 "cleaner open transaction commit returned %d",
@@ -1965,9 +1965,9 @@ static int transaction_kthread(void *arg)
1965 goto sleep; 1965 goto sleep;
1966 } 1966 }
1967 if (transid == trans->transid) { 1967 if (transid == trans->transid) {
1968 btrfs_commit_transaction(trans, root); 1968 btrfs_commit_transaction(trans);
1969 } else { 1969 } else {
1970 btrfs_end_transaction(trans, root); 1970 btrfs_end_transaction(trans);
1971 } 1971 }
1972sleep: 1972sleep:
1973 wake_up_process(fs_info->cleaner_kthread); 1973 wake_up_process(fs_info->cleaner_kthread);
@@ -3901,7 +3901,7 @@ int btrfs_commit_super(struct btrfs_fs_info *fs_info)
3901 trans = btrfs_join_transaction(root); 3901 trans = btrfs_join_transaction(root);
3902 if (IS_ERR(trans)) 3902 if (IS_ERR(trans))
3903 return PTR_ERR(trans); 3903 return PTR_ERR(trans);
3904 return btrfs_commit_transaction(trans, root); 3904 return btrfs_commit_transaction(trans);
3905} 3905}
3906 3906
3907void close_ctree(struct btrfs_fs_info *fs_info) 3907void close_ctree(struct btrfs_fs_info *fs_info)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 0360e973378d..2825019cd18f 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -2868,7 +2868,7 @@ static void delayed_ref_async_start(struct btrfs_work *work)
2868 if (ret) 2868 if (ret)
2869 async->error = ret; 2869 async->error = ret;
2870end: 2870end:
2871 ret = btrfs_end_transaction(trans, async->root); 2871 ret = btrfs_end_transaction(trans);
2872 if (ret && !async->error) 2872 if (ret && !async->error)
2873 async->error = ret; 2873 async->error = ret;
2874done: 2874done:
@@ -4175,7 +4175,7 @@ alloc:
4175 4175
4176 ret = do_chunk_alloc(trans, fs_info, alloc_target, 4176 ret = do_chunk_alloc(trans, fs_info, alloc_target,
4177 CHUNK_ALLOC_NO_FORCE); 4177 CHUNK_ALLOC_NO_FORCE);
4178 btrfs_end_transaction(trans, root); 4178 btrfs_end_transaction(trans);
4179 if (ret < 0) { 4179 if (ret < 0) {
4180 if (ret != -ENOSPC) 4180 if (ret != -ENOSPC)
4181 return ret; 4181 return ret;
@@ -4220,7 +4220,7 @@ commit_trans:
4220 test_bit(BTRFS_TRANS_HAVE_FREE_BGS, 4220 test_bit(BTRFS_TRANS_HAVE_FREE_BGS,
4221 &trans->transaction->flags) || 4221 &trans->transaction->flags) ||
4222 need_commit > 0) { 4222 need_commit > 0) {
4223 ret = btrfs_commit_transaction(trans, root); 4223 ret = btrfs_commit_transaction(trans);
4224 if (ret) 4224 if (ret)
4225 return ret; 4225 return ret;
4226 /* 4226 /*
@@ -4232,7 +4232,7 @@ commit_trans:
4232 mutex_unlock(&fs_info->cleaner_delayed_iput_mutex); 4232 mutex_unlock(&fs_info->cleaner_delayed_iput_mutex);
4233 goto again; 4233 goto again;
4234 } else { 4234 } else {
4235 btrfs_end_transaction(trans, root); 4235 btrfs_end_transaction(trans);
4236 } 4236 }
4237 } 4237 }
4238 4238
@@ -4824,7 +4824,7 @@ commit:
4824 if (IS_ERR(trans)) 4824 if (IS_ERR(trans))
4825 return -ENOSPC; 4825 return -ENOSPC;
4826 4826
4827 return btrfs_commit_transaction(trans, root); 4827 return btrfs_commit_transaction(trans);
4828} 4828}
4829 4829
4830struct reserve_ticket { 4830struct reserve_ticket {
@@ -4857,7 +4857,7 @@ static int flush_space(struct btrfs_root *root,
4857 break; 4857 break;
4858 } 4858 }
4859 ret = btrfs_run_delayed_items_nr(trans, fs_info, nr); 4859 ret = btrfs_run_delayed_items_nr(trans, fs_info, nr);
4860 btrfs_end_transaction(trans, root); 4860 btrfs_end_transaction(trans);
4861 break; 4861 break;
4862 case FLUSH_DELALLOC: 4862 case FLUSH_DELALLOC:
4863 case FLUSH_DELALLOC_WAIT: 4863 case FLUSH_DELALLOC_WAIT:
@@ -4873,7 +4873,7 @@ static int flush_space(struct btrfs_root *root,
4873 ret = do_chunk_alloc(trans, fs_info, 4873 ret = do_chunk_alloc(trans, fs_info,
4874 btrfs_get_alloc_profile(root, 0), 4874 btrfs_get_alloc_profile(root, 0),
4875 CHUNK_ALLOC_NO_FORCE); 4875 CHUNK_ALLOC_NO_FORCE);
4876 btrfs_end_transaction(trans, root); 4876 btrfs_end_transaction(trans);
4877 if (ret > 0 || ret == -ENOSPC) 4877 if (ret > 0 || ret == -ENOSPC)
4878 ret = 0; 4878 ret = 0;
4879 break; 4879 break;
@@ -7854,7 +7854,7 @@ loop:
7854 else 7854 else
7855 ret = 0; 7855 ret = 0;
7856 if (!exist) 7856 if (!exist)
7857 btrfs_end_transaction(trans, root); 7857 btrfs_end_transaction(trans);
7858 if (ret) 7858 if (ret)
7859 goto out; 7859 goto out;
7860 } 7860 }
@@ -9106,7 +9106,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
9106 } 9106 }
9107 9107
9108 BUG_ON(wc->level == 0); 9108 BUG_ON(wc->level == 0);
9109 if (btrfs_should_end_transaction(trans, tree_root) || 9109 if (btrfs_should_end_transaction(trans) ||
9110 (!for_reloc && btrfs_need_cleaner_sleep(fs_info))) { 9110 (!for_reloc && btrfs_need_cleaner_sleep(fs_info))) {
9111 ret = btrfs_update_root(trans, tree_root, 9111 ret = btrfs_update_root(trans, tree_root,
9112 &root->root_key, 9112 &root->root_key,
@@ -9117,7 +9117,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
9117 goto out_end_trans; 9117 goto out_end_trans;
9118 } 9118 }
9119 9119
9120 btrfs_end_transaction_throttle(trans, tree_root); 9120 btrfs_end_transaction_throttle(trans);
9121 if (!for_reloc && btrfs_need_cleaner_sleep(fs_info)) { 9121 if (!for_reloc && btrfs_need_cleaner_sleep(fs_info)) {
9122 btrfs_debug(fs_info, 9122 btrfs_debug(fs_info,
9123 "drop snapshot early exit"); 9123 "drop snapshot early exit");
@@ -9171,7 +9171,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root,
9171 } 9171 }
9172 root_dropped = true; 9172 root_dropped = true;
9173out_end_trans: 9173out_end_trans:
9174 btrfs_end_transaction_throttle(trans, tree_root); 9174 btrfs_end_transaction_throttle(trans);
9175out_free: 9175out_free:
9176 kfree(wc); 9176 kfree(wc);
9177 btrfs_free_path(path); 9177 btrfs_free_path(path);
@@ -9380,7 +9380,7 @@ again:
9380 u64 transid = trans->transid; 9380 u64 transid = trans->transid;
9381 9381
9382 mutex_unlock(&fs_info->ro_block_group_mutex); 9382 mutex_unlock(&fs_info->ro_block_group_mutex);
9383 btrfs_end_transaction(trans, root); 9383 btrfs_end_transaction(trans);
9384 9384
9385 ret = btrfs_wait_for_commit(fs_info, transid); 9385 ret = btrfs_wait_for_commit(fs_info, transid);
9386 if (ret) 9386 if (ret)
@@ -9425,7 +9425,7 @@ out:
9425 } 9425 }
9426 mutex_unlock(&fs_info->ro_block_group_mutex); 9426 mutex_unlock(&fs_info->ro_block_group_mutex);
9427 9427
9428 btrfs_end_transaction(trans, root); 9428 btrfs_end_transaction(trans);
9429 return ret; 9429 return ret;
9430} 9430}
9431 9431
@@ -9644,7 +9644,7 @@ int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr)
9644 "no space to allocate a new chunk for block group %llu", 9644 "no space to allocate a new chunk for block group %llu",
9645 block_group->key.objectid); 9645 block_group->key.objectid);
9646 mutex_unlock(&fs_info->chunk_mutex); 9646 mutex_unlock(&fs_info->chunk_mutex);
9647 btrfs_end_transaction(trans, root); 9647 btrfs_end_transaction(trans);
9648out: 9648out:
9649 btrfs_put_block_group(block_group); 9649 btrfs_put_block_group(block_group);
9650 return ret; 9650 return ret;
@@ -10596,7 +10596,6 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
10596{ 10596{
10597 struct btrfs_block_group_cache *block_group; 10597 struct btrfs_block_group_cache *block_group;
10598 struct btrfs_space_info *space_info; 10598 struct btrfs_space_info *space_info;
10599 struct btrfs_root *root = fs_info->extent_root;
10600 struct btrfs_trans_handle *trans; 10599 struct btrfs_trans_handle *trans;
10601 int ret = 0; 10600 int ret = 0;
10602 10601
@@ -10747,7 +10746,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
10747 btrfs_get_block_group(block_group); 10746 btrfs_get_block_group(block_group);
10748 } 10747 }
10749end_trans: 10748end_trans:
10750 btrfs_end_transaction(trans, root); 10749 btrfs_end_transaction(trans);
10751next: 10750next:
10752 mutex_unlock(&fs_info->delete_unused_bgs_mutex); 10751 mutex_unlock(&fs_info->delete_unused_bgs_mutex);
10753 btrfs_put_block_group(block_group); 10752 btrfs_put_block_group(block_group);
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 3b148e5fcc56..bf2defa8ebe0 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4540,7 +4540,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
4540 root->objectid, 4540 root->objectid,
4541 btrfs_ino(inode), bytenr); 4541 btrfs_ino(inode), bytenr);
4542 if (trans) 4542 if (trans)
4543 btrfs_end_transaction(trans, root); 4543 btrfs_end_transaction(trans);
4544 if (ret < 0) 4544 if (ret < 0)
4545 goto out_free; 4545 goto out_free;
4546 if (ret) 4546 if (ret)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 2d3b93dd9c2c..140271b1ea2e 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2146,7 +2146,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
2146 * which are indicated by ctx.io_err. 2146 * which are indicated by ctx.io_err.
2147 */ 2147 */
2148 if (ctx.io_err) { 2148 if (ctx.io_err) {
2149 btrfs_end_transaction(trans, root); 2149 btrfs_end_transaction(trans);
2150 ret = ctx.io_err; 2150 ret = ctx.io_err;
2151 goto out; 2151 goto out;
2152 } 2152 }
@@ -2155,20 +2155,20 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
2155 if (!ret) { 2155 if (!ret) {
2156 ret = btrfs_sync_log(trans, root, &ctx); 2156 ret = btrfs_sync_log(trans, root, &ctx);
2157 if (!ret) { 2157 if (!ret) {
2158 ret = btrfs_end_transaction(trans, root); 2158 ret = btrfs_end_transaction(trans);
2159 goto out; 2159 goto out;
2160 } 2160 }
2161 } 2161 }
2162 if (!full_sync) { 2162 if (!full_sync) {
2163 ret = btrfs_wait_ordered_range(inode, start, len); 2163 ret = btrfs_wait_ordered_range(inode, start, len);
2164 if (ret) { 2164 if (ret) {
2165 btrfs_end_transaction(trans, root); 2165 btrfs_end_transaction(trans);
2166 goto out; 2166 goto out;
2167 } 2167 }
2168 } 2168 }
2169 ret = btrfs_commit_transaction(trans, root); 2169 ret = btrfs_commit_transaction(trans);
2170 } else { 2170 } else {
2171 ret = btrfs_end_transaction(trans, root); 2171 ret = btrfs_end_transaction(trans);
2172 } 2172 }
2173out: 2173out:
2174 return ret > 0 ? -EIO : ret; 2174 return ret > 0 ? -EIO : ret;
@@ -2574,7 +2574,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
2574 break; 2574 break;
2575 } 2575 }
2576 2576
2577 btrfs_end_transaction(trans, root); 2577 btrfs_end_transaction(trans);
2578 btrfs_btree_balance_dirty(fs_info); 2578 btrfs_btree_balance_dirty(fs_info);
2579 2579
2580 trans = btrfs_start_transaction(root, rsv_count); 2580 trans = btrfs_start_transaction(root, rsv_count);
@@ -2642,7 +2642,7 @@ out_trans:
2642 trans->block_rsv = &fs_info->trans_block_rsv; 2642 trans->block_rsv = &fs_info->trans_block_rsv;
2643 ret = btrfs_update_inode(trans, root, inode); 2643 ret = btrfs_update_inode(trans, root, inode);
2644 updated_inode = true; 2644 updated_inode = true;
2645 btrfs_end_transaction(trans, root); 2645 btrfs_end_transaction(trans);
2646 btrfs_btree_balance_dirty(fs_info); 2646 btrfs_btree_balance_dirty(fs_info);
2647out_free: 2647out_free:
2648 btrfs_free_path(path); 2648 btrfs_free_path(path);
@@ -2664,7 +2664,7 @@ out_only_mutex:
2664 err = PTR_ERR(trans); 2664 err = PTR_ERR(trans);
2665 } else { 2665 } else {
2666 err = btrfs_update_inode(trans, root, inode); 2666 err = btrfs_update_inode(trans, root, inode);
2667 ret = btrfs_end_transaction(trans, root); 2667 ret = btrfs_end_transaction(trans);
2668 } 2668 }
2669 } 2669 }
2670 inode_unlock(inode); 2670 inode_unlock(inode);
@@ -2906,9 +2906,9 @@ static long btrfs_fallocate(struct file *file, int mode,
2906 btrfs_ordered_update_i_size(inode, actual_end, NULL); 2906 btrfs_ordered_update_i_size(inode, actual_end, NULL);
2907 ret = btrfs_update_inode(trans, root, inode); 2907 ret = btrfs_update_inode(trans, root, inode);
2908 if (ret) 2908 if (ret)
2909 btrfs_end_transaction(trans, root); 2909 btrfs_end_transaction(trans);
2910 else 2910 else
2911 ret = btrfs_end_transaction(trans, root); 2911 ret = btrfs_end_transaction(trans);
2912 } 2912 }
2913 } 2913 }
2914out_unlock: 2914out_unlock:
diff --git a/fs/btrfs/free-space-tree.c b/fs/btrfs/free-space-tree.c
index 2a08f518353b..ff0c55337c2e 100644
--- a/fs/btrfs/free-space-tree.c
+++ b/fs/btrfs/free-space-tree.c
@@ -1189,7 +1189,7 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
1189 btrfs_set_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID); 1189 btrfs_set_fs_compat_ro(fs_info, FREE_SPACE_TREE_VALID);
1190 clear_bit(BTRFS_FS_CREATING_FREE_SPACE_TREE, &fs_info->flags); 1190 clear_bit(BTRFS_FS_CREATING_FREE_SPACE_TREE, &fs_info->flags);
1191 1191
1192 ret = btrfs_commit_transaction(trans, tree_root); 1192 ret = btrfs_commit_transaction(trans);
1193 if (ret) 1193 if (ret)
1194 return ret; 1194 return ret;
1195 1195
@@ -1198,7 +1198,7 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
1198abort: 1198abort:
1199 clear_bit(BTRFS_FS_CREATING_FREE_SPACE_TREE, &fs_info->flags); 1199 clear_bit(BTRFS_FS_CREATING_FREE_SPACE_TREE, &fs_info->flags);
1200 btrfs_abort_transaction(trans, ret); 1200 btrfs_abort_transaction(trans, ret);
1201 btrfs_end_transaction(trans, tree_root); 1201 btrfs_end_transaction(trans);
1202 return ret; 1202 return ret;
1203} 1203}
1204 1204
@@ -1278,7 +1278,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
1278 free_extent_buffer(free_space_root->commit_root); 1278 free_extent_buffer(free_space_root->commit_root);
1279 kfree(free_space_root); 1279 kfree(free_space_root);
1280 1280
1281 ret = btrfs_commit_transaction(trans, tree_root); 1281 ret = btrfs_commit_transaction(trans);
1282 if (ret) 1282 if (ret)
1283 return ret; 1283 return ret;
1284 1284
@@ -1286,7 +1286,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
1286 1286
1287abort: 1287abort:
1288 btrfs_abort_transaction(trans, ret); 1288 btrfs_abort_transaction(trans, ret);
1289 btrfs_end_transaction(trans, tree_root); 1289 btrfs_end_transaction(trans);
1290 return ret; 1290 return ret;
1291} 1291}
1292 1292
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 5fa8aeb23e94..dbcec1ced85a 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -326,7 +326,7 @@ out:
326 */ 326 */
327 btrfs_qgroup_free_data(inode, 0, PAGE_SIZE); 327 btrfs_qgroup_free_data(inode, 0, PAGE_SIZE);
328 btrfs_free_path(path); 328 btrfs_free_path(path);
329 btrfs_end_transaction(trans, root); 329 btrfs_end_transaction(trans);
330 return ret; 330 return ret;
331} 331}
332 332
@@ -1534,7 +1534,7 @@ out_check:
1534 } 1534 }
1535 1535
1536error: 1536error:
1537 err = btrfs_end_transaction(trans, root); 1537 err = btrfs_end_transaction(trans);
1538 if (!ret) 1538 if (!ret)
1539 ret = err; 1539 ret = err;
1540 1540
@@ -2665,7 +2665,7 @@ again:
2665out_free_path: 2665out_free_path:
2666 btrfs_release_path(path); 2666 btrfs_release_path(path);
2667 path->leave_spinning = 0; 2667 path->leave_spinning = 0;
2668 btrfs_end_transaction(trans, root); 2668 btrfs_end_transaction(trans);
2669out_unlock: 2669out_unlock:
2670 unlock_extent_cached(&BTRFS_I(inode)->io_tree, lock_start, lock_end, 2670 unlock_extent_cached(&BTRFS_I(inode)->io_tree, lock_start, lock_end,
2671 &cached, GFP_NOFS); 2671 &cached, GFP_NOFS);
@@ -3011,7 +3011,7 @@ out:
3011 if (root != fs_info->tree_root) 3011 if (root != fs_info->tree_root)
3012 btrfs_delalloc_release_metadata(inode, ordered_extent->len); 3012 btrfs_delalloc_release_metadata(inode, ordered_extent->len);
3013 if (trans) 3013 if (trans)
3014 btrfs_end_transaction(trans, root); 3014 btrfs_end_transaction(trans);
3015 3015
3016 if (ret || truncated) { 3016 if (ret || truncated) {
3017 u64 start, end; 3017 u64 start, end;
@@ -3519,7 +3519,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
3519 found_key.objectid); 3519 found_key.objectid);
3520 ret = btrfs_del_orphan_item(trans, root, 3520 ret = btrfs_del_orphan_item(trans, root,
3521 found_key.objectid); 3521 found_key.objectid);
3522 btrfs_end_transaction(trans, root); 3522 btrfs_end_transaction(trans);
3523 if (ret) 3523 if (ret)
3524 goto out; 3524 goto out;
3525 continue; 3525 continue;
@@ -3549,7 +3549,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
3549 goto out; 3549 goto out;
3550 } 3550 }
3551 ret = btrfs_orphan_add(trans, inode); 3551 ret = btrfs_orphan_add(trans, inode);
3552 btrfs_end_transaction(trans, root); 3552 btrfs_end_transaction(trans);
3553 if (ret) { 3553 if (ret) {
3554 iput(inode); 3554 iput(inode);
3555 goto out; 3555 goto out;
@@ -3580,7 +3580,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root)
3580 test_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state)) { 3580 test_bit(BTRFS_ROOT_ORPHAN_ITEM_INSERTED, &root->state)) {
3581 trans = btrfs_join_transaction(root); 3581 trans = btrfs_join_transaction(root);
3582 if (!IS_ERR(trans)) 3582 if (!IS_ERR(trans))
3583 btrfs_end_transaction(trans, root); 3583 btrfs_end_transaction(trans);
3584 } 3584 }
3585 3585
3586 if (nr_unlink) 3586 if (nr_unlink)
@@ -4156,7 +4156,7 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry)
4156 } 4156 }
4157 4157
4158out: 4158out:
4159 btrfs_end_transaction(trans, root); 4159 btrfs_end_transaction(trans);
4160 btrfs_btree_balance_dirty(root->fs_info); 4160 btrfs_btree_balance_dirty(root->fs_info);
4161 return ret; 4161 return ret;
4162} 4162}
@@ -4293,7 +4293,7 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
4293 BTRFS_I(dir)->last_unlink_trans = last_unlink_trans; 4293 BTRFS_I(dir)->last_unlink_trans = last_unlink_trans;
4294 } 4294 }
4295out: 4295out:
4296 btrfs_end_transaction(trans, root); 4296 btrfs_end_transaction(trans);
4297 btrfs_btree_balance_dirty(root->fs_info); 4297 btrfs_btree_balance_dirty(root->fs_info);
4298 4298
4299 return err; 4299 return err;
@@ -4453,7 +4453,7 @@ search_again:
4453 * bytes_deleted is > 0, it will be huge by the time we get here 4453 * bytes_deleted is > 0, it will be huge by the time we get here
4454 */ 4454 */
4455 if (be_nice && bytes_deleted > SZ_32M) { 4455 if (be_nice && bytes_deleted > SZ_32M) {
4456 if (btrfs_should_end_transaction(trans, root)) { 4456 if (btrfs_should_end_transaction(trans)) {
4457 err = -EAGAIN; 4457 err = -EAGAIN;
4458 goto error; 4458 goto error;
4459 } 4459 }
@@ -4858,7 +4858,7 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode,
4858 ret = btrfs_drop_extents(trans, root, inode, offset, offset + len, 1); 4858 ret = btrfs_drop_extents(trans, root, inode, offset, offset + len, 1);
4859 if (ret) { 4859 if (ret) {
4860 btrfs_abort_transaction(trans, ret); 4860 btrfs_abort_transaction(trans, ret);
4861 btrfs_end_transaction(trans, root); 4861 btrfs_end_transaction(trans);
4862 return ret; 4862 return ret;
4863 } 4863 }
4864 4864
@@ -4868,7 +4868,7 @@ static int maybe_insert_hole(struct btrfs_root *root, struct inode *inode,
4868 btrfs_abort_transaction(trans, ret); 4868 btrfs_abort_transaction(trans, ret);
4869 else 4869 else
4870 btrfs_update_inode(trans, root, inode); 4870 btrfs_update_inode(trans, root, inode);
4871 btrfs_end_transaction(trans, root); 4871 btrfs_end_transaction(trans);
4872 return ret; 4872 return ret;
4873} 4873}
4874 4874
@@ -5032,7 +5032,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
5032 pagecache_isize_extended(inode, oldsize, newsize); 5032 pagecache_isize_extended(inode, oldsize, newsize);
5033 ret = btrfs_update_inode(trans, root, inode); 5033 ret = btrfs_update_inode(trans, root, inode);
5034 btrfs_end_write_no_snapshoting(root); 5034 btrfs_end_write_no_snapshoting(root);
5035 btrfs_end_transaction(trans, root); 5035 btrfs_end_transaction(trans);
5036 } else { 5036 } else {
5037 5037
5038 /* 5038 /*
@@ -5063,7 +5063,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
5063 * will be consistent. 5063 * will be consistent.
5064 */ 5064 */
5065 ret = btrfs_orphan_add(trans, inode); 5065 ret = btrfs_orphan_add(trans, inode);
5066 btrfs_end_transaction(trans, root); 5066 btrfs_end_transaction(trans);
5067 if (ret) 5067 if (ret)
5068 return ret; 5068 return ret;
5069 5069
@@ -5094,7 +5094,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
5094 err = btrfs_orphan_del(trans, inode); 5094 err = btrfs_orphan_del(trans, inode);
5095 if (err) 5095 if (err)
5096 btrfs_abort_transaction(trans, err); 5096 btrfs_abort_transaction(trans, err);
5097 btrfs_end_transaction(trans, root); 5097 btrfs_end_transaction(trans);
5098 } 5098 }
5099 } 5099 }
5100 5100
@@ -5355,7 +5355,7 @@ void btrfs_evict_inode(struct inode *inode)
5355 * again. 5355 * again.
5356 */ 5356 */
5357 if (ret) { 5357 if (ret) {
5358 ret = btrfs_commit_transaction(trans, root); 5358 ret = btrfs_commit_transaction(trans);
5359 if (ret) { 5359 if (ret) {
5360 btrfs_orphan_del(NULL, inode); 5360 btrfs_orphan_del(NULL, inode);
5361 btrfs_free_block_rsv(fs_info, rsv); 5361 btrfs_free_block_rsv(fs_info, rsv);
@@ -5373,7 +5373,7 @@ void btrfs_evict_inode(struct inode *inode)
5373 break; 5373 break;
5374 5374
5375 trans->block_rsv = &fs_info->trans_block_rsv; 5375 trans->block_rsv = &fs_info->trans_block_rsv;
5376 btrfs_end_transaction(trans, root); 5376 btrfs_end_transaction(trans);
5377 trans = NULL; 5377 trans = NULL;
5378 btrfs_btree_balance_dirty(fs_info); 5378 btrfs_btree_balance_dirty(fs_info);
5379 } 5379 }
@@ -5396,7 +5396,7 @@ void btrfs_evict_inode(struct inode *inode)
5396 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)) 5396 root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID))
5397 btrfs_return_ino(root, btrfs_ino(inode)); 5397 btrfs_return_ino(root, btrfs_ino(inode));
5398 5398
5399 btrfs_end_transaction(trans, root); 5399 btrfs_end_transaction(trans);
5400 btrfs_btree_balance_dirty(fs_info); 5400 btrfs_btree_balance_dirty(fs_info);
5401no_delete: 5401no_delete:
5402 btrfs_remove_delayed_node(inode); 5402 btrfs_remove_delayed_node(inode);
@@ -5975,7 +5975,7 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc)
5975 trans = btrfs_join_transaction(root); 5975 trans = btrfs_join_transaction(root);
5976 if (IS_ERR(trans)) 5976 if (IS_ERR(trans))
5977 return PTR_ERR(trans); 5977 return PTR_ERR(trans);
5978 ret = btrfs_commit_transaction(trans, root); 5978 ret = btrfs_commit_transaction(trans);
5979 } 5979 }
5980 return ret; 5980 return ret;
5981} 5981}
@@ -6003,14 +6003,14 @@ static int btrfs_dirty_inode(struct inode *inode)
6003 ret = btrfs_update_inode(trans, root, inode); 6003 ret = btrfs_update_inode(trans, root, inode);
6004 if (ret && ret == -ENOSPC) { 6004 if (ret && ret == -ENOSPC) {
6005 /* whoops, lets try again with the full transaction */ 6005 /* whoops, lets try again with the full transaction */
6006 btrfs_end_transaction(trans, root); 6006 btrfs_end_transaction(trans);
6007 trans = btrfs_start_transaction(root, 1); 6007 trans = btrfs_start_transaction(root, 1);
6008 if (IS_ERR(trans)) 6008 if (IS_ERR(trans))
6009 return PTR_ERR(trans); 6009 return PTR_ERR(trans);
6010 6010
6011 ret = btrfs_update_inode(trans, root, inode); 6011 ret = btrfs_update_inode(trans, root, inode);
6012 } 6012 }
6013 btrfs_end_transaction(trans, root); 6013 btrfs_end_transaction(trans);
6014 if (BTRFS_I(inode)->delayed_node) 6014 if (BTRFS_I(inode)->delayed_node)
6015 btrfs_balance_delayed_items(fs_info); 6015 btrfs_balance_delayed_items(fs_info);
6016 6016
@@ -6448,7 +6448,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
6448 } 6448 }
6449 6449
6450out_unlock: 6450out_unlock:
6451 btrfs_end_transaction(trans, root); 6451 btrfs_end_transaction(trans);
6452 btrfs_balance_delayed_items(fs_info); 6452 btrfs_balance_delayed_items(fs_info);
6453 btrfs_btree_balance_dirty(fs_info); 6453 btrfs_btree_balance_dirty(fs_info);
6454 if (drop_inode) { 6454 if (drop_inode) {
@@ -6524,7 +6524,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
6524 d_instantiate(dentry, inode); 6524 d_instantiate(dentry, inode);
6525 6525
6526out_unlock: 6526out_unlock:
6527 btrfs_end_transaction(trans, root); 6527 btrfs_end_transaction(trans);
6528 if (err && drop_inode_on_err) { 6528 if (err && drop_inode_on_err) {
6529 inode_dec_link_count(inode); 6529 inode_dec_link_count(inode);
6530 iput(inode); 6530 iput(inode);
@@ -6606,7 +6606,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,
6606 btrfs_balance_delayed_items(fs_info); 6606 btrfs_balance_delayed_items(fs_info);
6607fail: 6607fail:
6608 if (trans) 6608 if (trans)
6609 btrfs_end_transaction(trans, root); 6609 btrfs_end_transaction(trans);
6610 if (drop_inode) { 6610 if (drop_inode) {
6611 inode_dec_link_count(inode); 6611 inode_dec_link_count(inode);
6612 iput(inode); 6612 iput(inode);
@@ -6675,7 +6675,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
6675 drop_on_err = 0; 6675 drop_on_err = 0;
6676 6676
6677out_fail: 6677out_fail:
6678 btrfs_end_transaction(trans, root); 6678 btrfs_end_transaction(trans);
6679 if (drop_on_err) { 6679 if (drop_on_err) {
6680 inode_dec_link_count(inode); 6680 inode_dec_link_count(inode);
6681 iput(inode); 6681 iput(inode);
@@ -7063,7 +7063,7 @@ out:
7063 7063
7064 btrfs_free_path(path); 7064 btrfs_free_path(path);
7065 if (trans) { 7065 if (trans) {
7066 ret = btrfs_end_transaction(trans, root); 7066 ret = btrfs_end_transaction(trans);
7067 if (!err) 7067 if (!err)
7068 err = ret; 7068 err = ret;
7069 } 7069 }
@@ -7386,7 +7386,7 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
7386 7386
7387 ret = btrfs_cross_ref_exist(trans, root, btrfs_ino(inode), 7387 ret = btrfs_cross_ref_exist(trans, root, btrfs_ino(inode),
7388 key.offset - backref_offset, disk_bytenr); 7388 key.offset - backref_offset, disk_bytenr);
7389 btrfs_end_transaction(trans, root); 7389 btrfs_end_transaction(trans);
7390 if (ret) { 7390 if (ret) {
7391 ret = 0; 7391 ret = 0;
7392 goto out; 7392 goto out;
@@ -9200,7 +9200,7 @@ static int btrfs_truncate(struct inode *inode)
9200 break; 9200 break;
9201 } 9201 }
9202 9202
9203 btrfs_end_transaction(trans, root); 9203 btrfs_end_transaction(trans);
9204 btrfs_btree_balance_dirty(fs_info); 9204 btrfs_btree_balance_dirty(fs_info);
9205 9205
9206 trans = btrfs_start_transaction(root, 2); 9206 trans = btrfs_start_transaction(root, 2);
@@ -9229,7 +9229,7 @@ static int btrfs_truncate(struct inode *inode)
9229 if (ret && !err) 9229 if (ret && !err)
9230 err = ret; 9230 err = ret;
9231 9231
9232 ret = btrfs_end_transaction(trans, root); 9232 ret = btrfs_end_transaction(trans);
9233 btrfs_btree_balance_dirty(fs_info); 9233 btrfs_btree_balance_dirty(fs_info);
9234 } 9234 }
9235out: 9235out:
@@ -9697,7 +9697,7 @@ out_fail:
9697 dest_log_pinned = false; 9697 dest_log_pinned = false;
9698 } 9698 }
9699 } 9699 }
9700 ret = btrfs_end_transaction(trans, root); 9700 ret = btrfs_end_transaction(trans);
9701out_notrans: 9701out_notrans:
9702 if (new_ino == BTRFS_FIRST_FREE_OBJECTID) 9702 if (new_ino == BTRFS_FIRST_FREE_OBJECTID)
9703 up_read(&fs_info->subvol_sem); 9703 up_read(&fs_info->subvol_sem);
@@ -9967,7 +9967,7 @@ out_fail:
9967 btrfs_end_log_trans(root); 9967 btrfs_end_log_trans(root);
9968 log_pinned = false; 9968 log_pinned = false;
9969 } 9969 }
9970 btrfs_end_transaction(trans, root); 9970 btrfs_end_transaction(trans);
9971out_notrans: 9971out_notrans:
9972 if (old_ino == BTRFS_FIRST_FREE_OBJECTID) 9972 if (old_ino == BTRFS_FIRST_FREE_OBJECTID)
9973 up_read(&fs_info->subvol_sem); 9973 up_read(&fs_info->subvol_sem);
@@ -10300,7 +10300,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
10300 d_instantiate(dentry, inode); 10300 d_instantiate(dentry, inode);
10301 10301
10302out_unlock: 10302out_unlock:
10303 btrfs_end_transaction(trans, root); 10303 btrfs_end_transaction(trans);
10304 if (drop_inode) { 10304 if (drop_inode) {
10305 inode_dec_link_count(inode); 10305 inode_dec_link_count(inode);
10306 iput(inode); 10306 iput(inode);
@@ -10356,7 +10356,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
10356 min_size, 0, *alloc_hint, &ins, 1, 0); 10356 min_size, 0, *alloc_hint, &ins, 1, 0);
10357 if (ret) { 10357 if (ret) {
10358 if (own_trans) 10358 if (own_trans)
10359 btrfs_end_transaction(trans, root); 10359 btrfs_end_transaction(trans);
10360 break; 10360 break;
10361 } 10361 }
10362 btrfs_dec_block_group_reservations(fs_info, ins.objectid); 10362 btrfs_dec_block_group_reservations(fs_info, ins.objectid);
@@ -10372,7 +10372,7 @@ static int __btrfs_prealloc_file_range(struct inode *inode, int mode,
10372 ins.offset, 0); 10372 ins.offset, 0);
10373 btrfs_abort_transaction(trans, ret); 10373 btrfs_abort_transaction(trans, ret);
10374 if (own_trans) 10374 if (own_trans)
10375 btrfs_end_transaction(trans, root); 10375 btrfs_end_transaction(trans);
10376 break; 10376 break;
10377 } 10377 }
10378 10378
@@ -10432,12 +10432,12 @@ next:
10432 if (ret) { 10432 if (ret) {
10433 btrfs_abort_transaction(trans, ret); 10433 btrfs_abort_transaction(trans, ret);
10434 if (own_trans) 10434 if (own_trans)
10435 btrfs_end_transaction(trans, root); 10435 btrfs_end_transaction(trans);
10436 break; 10436 break;
10437 } 10437 }
10438 10438
10439 if (own_trans) 10439 if (own_trans)
10440 btrfs_end_transaction(trans, root); 10440 btrfs_end_transaction(trans);
10441 } 10441 }
10442 if (cur_offset < end) 10442 if (cur_offset < end)
10443 btrfs_free_reserved_data_space(inode, cur_offset, 10443 btrfs_free_reserved_data_space(inode, cur_offset,
@@ -10542,7 +10542,7 @@ static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
10542 mark_inode_dirty(inode); 10542 mark_inode_dirty(inode);
10543 10543
10544out: 10544out:
10545 btrfs_end_transaction(trans, root); 10545 btrfs_end_transaction(trans);
10546 if (ret) 10546 if (ret)
10547 iput(inode); 10547 iput(inode);
10548 btrfs_balance_delayed_items(fs_info); 10548 btrfs_balance_delayed_items(fs_info);
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 256af12d0ff0..0a6902555e65 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -352,7 +352,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)
352 inode->i_ctime = current_time(inode); 352 inode->i_ctime = current_time(inode);
353 ret = btrfs_update_inode(trans, root, inode); 353 ret = btrfs_update_inode(trans, root, inode);
354 354
355 btrfs_end_transaction(trans, root); 355 btrfs_end_transaction(trans);
356 out_drop: 356 out_drop:
357 if (ret) { 357 if (ret) {
358 ip->flags = ip_oldflags; 358 ip->flags = ip_oldflags;
@@ -617,11 +617,11 @@ fail:
617 617
618 if (async_transid) { 618 if (async_transid) {
619 *async_transid = trans->transid; 619 *async_transid = trans->transid;
620 err = btrfs_commit_transaction_async(trans, root, 1); 620 err = btrfs_commit_transaction_async(trans, 1);
621 if (err) 621 if (err)
622 err = btrfs_commit_transaction(trans, root); 622 err = btrfs_commit_transaction(trans);
623 } else { 623 } else {
624 err = btrfs_commit_transaction(trans, root); 624 err = btrfs_commit_transaction(trans);
625 } 625 }
626 if (err && !ret) 626 if (err && !ret)
627 ret = err; 627 ret = err;
@@ -727,13 +727,11 @@ static int create_snapshot(struct btrfs_root *root, struct inode *dir,
727 spin_unlock(&fs_info->trans_lock); 727 spin_unlock(&fs_info->trans_lock);
728 if (async_transid) { 728 if (async_transid) {
729 *async_transid = trans->transid; 729 *async_transid = trans->transid;
730 ret = btrfs_commit_transaction_async(trans, 730 ret = btrfs_commit_transaction_async(trans, 1);
731 fs_info->extent_root, 1);
732 if (ret) 731 if (ret)
733 ret = btrfs_commit_transaction(trans, root); 732 ret = btrfs_commit_transaction(trans);
734 } else { 733 } else {
735 ret = btrfs_commit_transaction(trans, 734 ret = btrfs_commit_transaction(trans);
736 fs_info->extent_root);
737 } 735 }
738 if (ret) 736 if (ret)
739 goto fail; 737 goto fail;
@@ -1615,7 +1613,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
1615 goto out_free; 1613 goto out_free;
1616 } 1614 }
1617 ret = btrfs_grow_device(trans, device, new_size); 1615 ret = btrfs_grow_device(trans, device, new_size);
1618 btrfs_commit_transaction(trans, root); 1616 btrfs_commit_transaction(trans);
1619 } else if (new_size < old_size) { 1617 } else if (new_size < old_size) {
1620 ret = btrfs_shrink_device(device, new_size); 1618 ret = btrfs_shrink_device(device, new_size);
1621 } /* equal, nothing need to do */ 1619 } /* equal, nothing need to do */
@@ -1873,7 +1871,7 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
1873 ret = btrfs_update_root(trans, fs_info->tree_root, 1871 ret = btrfs_update_root(trans, fs_info->tree_root,
1874 &root->root_key, &root->root_item); 1872 &root->root_key, &root->root_item);
1875 1873
1876 btrfs_commit_transaction(trans, root); 1874 btrfs_commit_transaction(trans);
1877out_reset: 1875out_reset:
1878 if (ret) 1876 if (ret)
1879 btrfs_set_root_flags(&root->root_item, root_flags); 1877 btrfs_set_root_flags(&root->root_item, root_flags);
@@ -2552,7 +2550,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
2552out_end_trans: 2550out_end_trans:
2553 trans->block_rsv = NULL; 2551 trans->block_rsv = NULL;
2554 trans->bytes_reserved = 0; 2552 trans->bytes_reserved = 0;
2555 ret = btrfs_end_transaction(trans, root); 2553 ret = btrfs_end_transaction(trans);
2556 if (ret && !err) 2554 if (ret && !err)
2557 err = ret; 2555 err = ret;
2558 inode->i_flags |= S_DEAD; 2556 inode->i_flags |= S_DEAD;
@@ -3311,10 +3309,10 @@ static int clone_finish_inode_update(struct btrfs_trans_handle *trans,
3311 ret = btrfs_update_inode(trans, root, inode); 3309 ret = btrfs_update_inode(trans, root, inode);
3312 if (ret) { 3310 if (ret) {
3313 btrfs_abort_transaction(trans, ret); 3311 btrfs_abort_transaction(trans, ret);
3314 btrfs_end_transaction(trans, root); 3312 btrfs_end_transaction(trans);
3315 goto out; 3313 goto out;
3316 } 3314 }
3317 ret = btrfs_end_transaction(trans, root); 3315 ret = btrfs_end_transaction(trans);
3318out: 3316out:
3319 return ret; 3317 return ret;
3320} 3318}
@@ -3715,7 +3713,7 @@ process_slot:
3715 if (ret != -EOPNOTSUPP) 3713 if (ret != -EOPNOTSUPP)
3716 btrfs_abort_transaction(trans, 3714 btrfs_abort_transaction(trans,
3717 ret); 3715 ret);
3718 btrfs_end_transaction(trans, root); 3716 btrfs_end_transaction(trans);
3719 goto out; 3717 goto out;
3720 } 3718 }
3721 3719
@@ -3723,7 +3721,7 @@ process_slot:
3723 &new_key, size); 3721 &new_key, size);
3724 if (ret) { 3722 if (ret) {
3725 btrfs_abort_transaction(trans, ret); 3723 btrfs_abort_transaction(trans, ret);
3726 btrfs_end_transaction(trans, root); 3724 btrfs_end_transaction(trans);
3727 goto out; 3725 goto out;
3728 } 3726 }
3729 3727
@@ -3756,8 +3754,7 @@ process_slot:
3756 if (ret) { 3754 if (ret) {
3757 btrfs_abort_transaction(trans, 3755 btrfs_abort_transaction(trans,
3758 ret); 3756 ret);
3759 btrfs_end_transaction(trans, 3757 btrfs_end_transaction(trans);
3760 root);
3761 goto out; 3758 goto out;
3762 3759
3763 } 3760 }
@@ -3776,7 +3773,7 @@ process_slot:
3776 3773
3777 if (comp && (skip || trim)) { 3774 if (comp && (skip || trim)) {
3778 ret = -EINVAL; 3775 ret = -EINVAL;
3779 btrfs_end_transaction(trans, root); 3776 btrfs_end_transaction(trans);
3780 goto out; 3777 goto out;
3781 } 3778 }
3782 size -= skip + trim; 3779 size -= skip + trim;
@@ -3792,7 +3789,7 @@ process_slot:
3792 if (ret != -EOPNOTSUPP) 3789 if (ret != -EOPNOTSUPP)
3793 btrfs_abort_transaction(trans, 3790 btrfs_abort_transaction(trans,
3794 ret); 3791 ret);
3795 btrfs_end_transaction(trans, root); 3792 btrfs_end_transaction(trans);
3796 goto out; 3793 goto out;
3797 } 3794 }
3798 leaf = path->nodes[0]; 3795 leaf = path->nodes[0];
@@ -3852,7 +3849,7 @@ process_slot:
3852 if (ret) { 3849 if (ret) {
3853 if (ret != -EOPNOTSUPP) 3850 if (ret != -EOPNOTSUPP)
3854 btrfs_abort_transaction(trans, ret); 3851 btrfs_abort_transaction(trans, ret);
3855 btrfs_end_transaction(trans, root); 3852 btrfs_end_transaction(trans);
3856 goto out; 3853 goto out;
3857 } 3854 }
3858 clone_update_extent_map(inode, trans, NULL, last_dest_end, 3855 clone_update_extent_map(inode, trans, NULL, last_dest_end,
@@ -4114,7 +4111,7 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)
4114 dir_id, "default", 7, 1); 4111 dir_id, "default", 7, 1);
4115 if (IS_ERR_OR_NULL(di)) { 4112 if (IS_ERR_OR_NULL(di)) {
4116 btrfs_free_path(path); 4113 btrfs_free_path(path);
4117 btrfs_end_transaction(trans, root); 4114 btrfs_end_transaction(trans);
4118 btrfs_err(fs_info, 4115 btrfs_err(fs_info,
4119 "Umm, you don't have the default diritem, this isn't going to work"); 4116 "Umm, you don't have the default diritem, this isn't going to work");
4120 ret = -ENOENT; 4117 ret = -ENOENT;
@@ -4127,7 +4124,7 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)
4127 btrfs_free_path(path); 4124 btrfs_free_path(path);
4128 4125
4129 btrfs_set_fs_incompat(fs_info, DEFAULT_SUBVOL); 4126 btrfs_set_fs_incompat(fs_info, DEFAULT_SUBVOL);
4130 btrfs_end_transaction(trans, root); 4127 btrfs_end_transaction(trans);
4131out: 4128out:
4132 mnt_drop_write_file(file); 4129 mnt_drop_write_file(file);
4133 return ret; 4130 return ret;
@@ -4307,7 +4304,7 @@ long btrfs_ioctl_trans_end(struct file *file)
4307 return -EINVAL; 4304 return -EINVAL;
4308 file->private_data = NULL; 4305 file->private_data = NULL;
4309 4306
4310 btrfs_end_transaction(trans, root); 4307 btrfs_end_transaction(trans);
4311 4308
4312 atomic_dec(&root->fs_info->open_ioctl_trans); 4309 atomic_dec(&root->fs_info->open_ioctl_trans);
4313 4310
@@ -4332,9 +4329,9 @@ static noinline long btrfs_ioctl_start_sync(struct btrfs_root *root,
4332 goto out; 4329 goto out;
4333 } 4330 }
4334 transid = trans->transid; 4331 transid = trans->transid;
4335 ret = btrfs_commit_transaction_async(trans, root, 0); 4332 ret = btrfs_commit_transaction_async(trans, 0);
4336 if (ret) { 4333 if (ret) {
4337 btrfs_end_transaction(trans, root); 4334 btrfs_end_transaction(trans);
4338 return ret; 4335 return ret;
4339 } 4336 }
4340out: 4337out:
@@ -4885,7 +4882,7 @@ static long btrfs_ioctl_quota_ctl(struct file *file, void __user *arg)
4885 break; 4882 break;
4886 } 4883 }
4887 4884
4888 err = btrfs_commit_transaction(trans, fs_info->tree_root); 4885 err = btrfs_commit_transaction(trans);
4889 if (err && !ret) 4886 if (err && !ret)
4890 ret = err; 4887 ret = err;
4891out: 4888out:
@@ -4939,7 +4936,7 @@ static long btrfs_ioctl_qgroup_assign(struct file *file, void __user *arg)
4939 if (err < 0) 4936 if (err < 0)
4940 btrfs_handle_fs_error(fs_info, err, 4937 btrfs_handle_fs_error(fs_info, err,
4941 "failed to update qgroup status and info"); 4938 "failed to update qgroup status and info");
4942 err = btrfs_end_transaction(trans, root); 4939 err = btrfs_end_transaction(trans);
4943 if (err && !ret) 4940 if (err && !ret)
4944 ret = err; 4941 ret = err;
4945 4942
@@ -4991,7 +4988,7 @@ static long btrfs_ioctl_qgroup_create(struct file *file, void __user *arg)
4991 ret = btrfs_remove_qgroup(trans, fs_info, sa->qgroupid); 4988 ret = btrfs_remove_qgroup(trans, fs_info, sa->qgroupid);
4992 } 4989 }
4993 4990
4994 err = btrfs_end_transaction(trans, root); 4991 err = btrfs_end_transaction(trans);
4995 if (err && !ret) 4992 if (err && !ret)
4996 ret = err; 4993 ret = err;
4997 4994
@@ -5041,7 +5038,7 @@ static long btrfs_ioctl_qgroup_limit(struct file *file, void __user *arg)
5041 /* FIXME: check if the IDs really exist */ 5038 /* FIXME: check if the IDs really exist */
5042 ret = btrfs_limit_qgroup(trans, fs_info, qgroupid, &sa->lim); 5039 ret = btrfs_limit_qgroup(trans, fs_info, qgroupid, &sa->lim);
5043 5040
5044 err = btrfs_end_transaction(trans, root); 5041 err = btrfs_end_transaction(trans);
5045 if (err && !ret) 5042 if (err && !ret)
5046 ret = err; 5043 ret = err;
5047 5044
@@ -5187,7 +5184,7 @@ static long _btrfs_ioctl_set_received_subvol(struct file *file,
5187 ret = btrfs_update_root(trans, fs_info->tree_root, 5184 ret = btrfs_update_root(trans, fs_info->tree_root,
5188 &root->root_key, &root->root_item); 5185 &root->root_key, &root->root_item);
5189 if (ret < 0) { 5186 if (ret < 0) {
5190 btrfs_end_transaction(trans, root); 5187 btrfs_end_transaction(trans);
5191 goto out; 5188 goto out;
5192 } 5189 }
5193 if (received_uuid_changed && !btrfs_is_empty_uuid(sa->uuid)) { 5190 if (received_uuid_changed && !btrfs_is_empty_uuid(sa->uuid)) {
@@ -5199,7 +5196,7 @@ static long _btrfs_ioctl_set_received_subvol(struct file *file,
5199 goto out; 5196 goto out;
5200 } 5197 }
5201 } 5198 }
5202 ret = btrfs_commit_transaction(trans, root); 5199 ret = btrfs_commit_transaction(trans);
5203 if (ret < 0) { 5200 if (ret < 0) {
5204 btrfs_abort_transaction(trans, ret); 5201 btrfs_abort_transaction(trans, ret);
5205 goto out; 5202 goto out;
@@ -5347,7 +5344,7 @@ static int btrfs_ioctl_set_fslabel(struct file *file, void __user *arg)
5347 spin_lock(&fs_info->super_lock); 5344 spin_lock(&fs_info->super_lock);
5348 strcpy(super_block->label, label); 5345 strcpy(super_block->label, label);
5349 spin_unlock(&fs_info->super_lock); 5346 spin_unlock(&fs_info->super_lock);
5350 ret = btrfs_commit_transaction(trans, root); 5347 ret = btrfs_commit_transaction(trans);
5351 5348
5352out_unlock: 5349out_unlock:
5353 mnt_drop_write_file(file); 5350 mnt_drop_write_file(file);
@@ -5519,7 +5516,7 @@ static int btrfs_ioctl_set_features(struct file *file, void __user *arg)
5519 btrfs_set_super_incompat_flags(super_block, newflags); 5516 btrfs_set_super_incompat_flags(super_block, newflags);
5520 spin_unlock(&fs_info->super_lock); 5517 spin_unlock(&fs_info->super_lock);
5521 5518
5522 ret = btrfs_commit_transaction(trans, root); 5519 ret = btrfs_commit_transaction(trans);
5523out_drop_write: 5520out_drop_write:
5524 mnt_drop_write_file(file); 5521 mnt_drop_write_file(file);
5525 5522
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 135bb7986dfb..3e473e9a4844 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -2576,9 +2576,9 @@ static void btrfs_qgroup_rescan_worker(struct btrfs_work *work)
2576 err = qgroup_rescan_leaf(fs_info, path, trans); 2576 err = qgroup_rescan_leaf(fs_info, path, trans);
2577 } 2577 }
2578 if (err > 0) 2578 if (err > 0)
2579 btrfs_commit_transaction(trans, fs_info->fs_root); 2579 btrfs_commit_transaction(trans);
2580 else 2580 else
2581 btrfs_end_transaction(trans, fs_info->fs_root); 2581 btrfs_end_transaction(trans);
2582 } 2582 }
2583 2583
2584out: 2584out:
@@ -2613,7 +2613,7 @@ out:
2613 err = ret; 2613 err = ret;
2614 btrfs_err(fs_info, "fail to update qgroup status: %d", err); 2614 btrfs_err(fs_info, "fail to update qgroup status: %d", err);
2615 } 2615 }
2616 btrfs_end_transaction(trans, fs_info->quota_root); 2616 btrfs_end_transaction(trans);
2617 2617
2618 if (btrfs_fs_closing(fs_info)) { 2618 if (btrfs_fs_closing(fs_info)) {
2619 btrfs_info(fs_info, "qgroup scan paused"); 2619 btrfs_info(fs_info, "qgroup scan paused");
@@ -2732,7 +2732,7 @@ btrfs_qgroup_rescan(struct btrfs_fs_info *fs_info)
2732 fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN; 2732 fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
2733 return PTR_ERR(trans); 2733 return PTR_ERR(trans);
2734 } 2734 }
2735 ret = btrfs_commit_transaction(trans, fs_info->fs_root); 2735 ret = btrfs_commit_transaction(trans);
2736 if (ret) { 2736 if (ret) {
2737 fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN; 2737 fs_info->qgroup_flags &= ~BTRFS_QGROUP_STATUS_FLAG_RESCAN;
2738 return ret; 2738 return ret;
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 341a099c4967..5d222c8d2213 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2270,7 +2270,7 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
2270 path->slots[level]); 2270 path->slots[level]);
2271 root_item->drop_level = level; 2271 root_item->drop_level = level;
2272 2272
2273 btrfs_end_transaction_throttle(trans, root); 2273 btrfs_end_transaction_throttle(trans);
2274 trans = NULL; 2274 trans = NULL;
2275 2275
2276 btrfs_btree_balance_dirty(fs_info); 2276 btrfs_btree_balance_dirty(fs_info);
@@ -2301,7 +2301,7 @@ out:
2301 } 2301 }
2302 2302
2303 if (trans) 2303 if (trans)
2304 btrfs_end_transaction_throttle(trans, root); 2304 btrfs_end_transaction_throttle(trans);
2305 2305
2306 btrfs_btree_balance_dirty(fs_info); 2306 btrfs_btree_balance_dirty(fs_info);
2307 2307
@@ -2346,7 +2346,7 @@ again:
2346 2346
2347 if (!err) { 2347 if (!err) {
2348 if (num_bytes != rc->merging_rsv_size) { 2348 if (num_bytes != rc->merging_rsv_size) {
2349 btrfs_end_transaction(trans, rc->extent_root); 2349 btrfs_end_transaction(trans);
2350 btrfs_block_rsv_release(fs_info, rc->block_rsv, 2350 btrfs_block_rsv_release(fs_info, rc->block_rsv,
2351 num_bytes); 2351 num_bytes);
2352 goto again; 2352 goto again;
@@ -2378,9 +2378,9 @@ again:
2378 list_splice(&reloc_roots, &rc->reloc_roots); 2378 list_splice(&reloc_roots, &rc->reloc_roots);
2379 2379
2380 if (!err) 2380 if (!err)
2381 btrfs_commit_transaction(trans, rc->extent_root); 2381 btrfs_commit_transaction(trans);
2382 else 2382 else
2383 btrfs_end_transaction(trans, rc->extent_root); 2383 btrfs_end_transaction(trans);
2384 return err; 2384 return err;
2385} 2385}
2386 2386
@@ -3555,7 +3555,7 @@ truncate:
3555 3555
3556 ret = btrfs_truncate_free_space_cache(root, trans, block_group, inode); 3556 ret = btrfs_truncate_free_space_cache(root, trans, block_group, inode);
3557 3557
3558 btrfs_end_transaction(trans, root); 3558 btrfs_end_transaction(trans);
3559 btrfs_btree_balance_dirty(fs_info); 3559 btrfs_btree_balance_dirty(fs_info);
3560out: 3560out:
3561 iput(inode); 3561 iput(inode);
@@ -3986,7 +3986,7 @@ int prepare_to_relocate(struct reloc_control *rc)
3986 */ 3986 */
3987 return PTR_ERR(trans); 3987 return PTR_ERR(trans);
3988 } 3988 }
3989 btrfs_commit_transaction(trans, rc->extent_root); 3989 btrfs_commit_transaction(trans);
3990 return 0; 3990 return 0;
3991} 3991}
3992 3992
@@ -4033,7 +4033,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
4033 } 4033 }
4034restart: 4034restart:
4035 if (update_backref_cache(trans, &rc->backref_cache)) { 4035 if (update_backref_cache(trans, &rc->backref_cache)) {
4036 btrfs_end_transaction(trans, rc->extent_root); 4036 btrfs_end_transaction(trans);
4037 continue; 4037 continue;
4038 } 4038 }
4039 4039
@@ -4121,7 +4121,7 @@ restart:
4121 } 4121 }
4122 } 4122 }
4123 4123
4124 btrfs_end_transaction_throttle(trans, rc->extent_root); 4124 btrfs_end_transaction_throttle(trans);
4125 btrfs_btree_balance_dirty(fs_info); 4125 btrfs_btree_balance_dirty(fs_info);
4126 trans = NULL; 4126 trans = NULL;
4127 4127
@@ -4150,7 +4150,7 @@ restart:
4150 clear_extent_bits(&rc->processed_blocks, 0, (u64)-1, EXTENT_DIRTY); 4150 clear_extent_bits(&rc->processed_blocks, 0, (u64)-1, EXTENT_DIRTY);
4151 4151
4152 if (trans) { 4152 if (trans) {
4153 btrfs_end_transaction_throttle(trans, rc->extent_root); 4153 btrfs_end_transaction_throttle(trans);
4154 btrfs_btree_balance_dirty(fs_info); 4154 btrfs_btree_balance_dirty(fs_info);
4155 } 4155 }
4156 4156
@@ -4181,7 +4181,7 @@ restart:
4181 err = PTR_ERR(trans); 4181 err = PTR_ERR(trans);
4182 goto out_free; 4182 goto out_free;
4183 } 4183 }
4184 btrfs_commit_transaction(trans, rc->extent_root); 4184 btrfs_commit_transaction(trans);
4185out_free: 4185out_free:
4186 btrfs_free_block_rsv(fs_info, rc->block_rsv); 4186 btrfs_free_block_rsv(fs_info, rc->block_rsv);
4187 btrfs_free_path(path); 4187 btrfs_free_path(path);
@@ -4257,7 +4257,7 @@ struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info,
4257 4257
4258 err = btrfs_orphan_add(trans, inode); 4258 err = btrfs_orphan_add(trans, inode);
4259out: 4259out:
4260 btrfs_end_transaction(trans, root); 4260 btrfs_end_transaction(trans);
4261 btrfs_btree_balance_dirty(fs_info); 4261 btrfs_btree_balance_dirty(fs_info);
4262 if (err) { 4262 if (err) {
4263 if (inode) 4263 if (inode)
@@ -4442,7 +4442,7 @@ static noinline_for_stack int mark_garbage_root(struct btrfs_root *root)
4442 ret = btrfs_update_root(trans, fs_info->tree_root, 4442 ret = btrfs_update_root(trans, fs_info->tree_root,
4443 &root->root_key, &root->root_item); 4443 &root->root_key, &root->root_item);
4444 4444
4445 err = btrfs_end_transaction(trans, fs_info->tree_root); 4445 err = btrfs_end_transaction(trans);
4446 if (err) 4446 if (err)
4447 return err; 4447 return err;
4448 return ret; 4448 return ret;
@@ -4573,7 +4573,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
4573 fs_root->reloc_root = reloc_root; 4573 fs_root->reloc_root = reloc_root;
4574 } 4574 }
4575 4575
4576 err = btrfs_commit_transaction(trans, rc->extent_root); 4576 err = btrfs_commit_transaction(trans);
4577 if (err) 4577 if (err)
4578 goto out_free; 4578 goto out_free;
4579 4579
@@ -4586,7 +4586,7 @@ int btrfs_recover_relocation(struct btrfs_root *root)
4586 err = PTR_ERR(trans); 4586 err = PTR_ERR(trans);
4587 goto out_free; 4587 goto out_free;
4588 } 4588 }
4589 err = btrfs_commit_transaction(trans, rc->extent_root); 4589 err = btrfs_commit_transaction(trans);
4590out_free: 4590out_free:
4591 kfree(rc); 4591 kfree(rc);
4592out: 4592out:
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 87728ff39622..4c6735491ee0 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -303,7 +303,7 @@ int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info)
303 } 303 }
304 err = btrfs_del_orphan_item(trans, tree_root, 304 err = btrfs_del_orphan_item(trans, tree_root,
305 root_key.objectid); 305 root_key.objectid);
306 btrfs_end_transaction(trans, tree_root); 306 btrfs_end_transaction(trans);
307 if (err) { 307 if (err) {
308 btrfs_handle_fs_error(fs_info, err, 308 btrfs_handle_fs_error(fs_info, err,
309 "Failed to delete root orphan item"); 309 "Failed to delete root orphan item");
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 09fb2fb0848e..0d63d994be10 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -839,7 +839,7 @@ static void scrub_fixup_nodatasum(struct btrfs_work *work)
839 839
840out: 840out:
841 if (trans && !IS_ERR(trans)) 841 if (trans && !IS_ERR(trans))
842 btrfs_end_transaction(trans, fixup->root); 842 btrfs_end_transaction(trans);
843 if (uncorrectable) { 843 if (uncorrectable) {
844 spin_lock(&sctx->stat_lock); 844 spin_lock(&sctx->stat_lock);
845 ++sctx->stat.uncorrectable_errors; 845 ++sctx->stat.uncorrectable_errors;
@@ -3616,8 +3616,7 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
3616 if (IS_ERR(trans)) 3616 if (IS_ERR(trans))
3617 ret = PTR_ERR(trans); 3617 ret = PTR_ERR(trans);
3618 else 3618 else
3619 ret = btrfs_commit_transaction(trans, 3619 ret = btrfs_commit_transaction(trans);
3620 root);
3621 if (ret) { 3620 if (ret) {
3622 scrub_pause_off(fs_info); 3621 scrub_pause_off(fs_info);
3623 btrfs_put_block_group(cache); 3622 btrfs_put_block_group(cache);
@@ -4202,7 +4201,7 @@ static void copy_nocow_pages_worker(struct btrfs_work *work)
4202 goto out; 4201 goto out;
4203 } 4202 }
4204 4203
4205 btrfs_end_transaction(trans, root); 4204 btrfs_end_transaction(trans);
4206 trans = NULL; 4205 trans = NULL;
4207 while (!list_empty(&nocow_ctx->inodes)) { 4206 while (!list_empty(&nocow_ctx->inodes)) {
4208 struct scrub_nocow_inode *entry; 4207 struct scrub_nocow_inode *entry;
@@ -4230,7 +4229,7 @@ out:
4230 kfree(entry); 4229 kfree(entry);
4231 } 4230 }
4232 if (trans && !IS_ERR(trans)) 4231 if (trans && !IS_ERR(trans))
4233 btrfs_end_transaction(trans, root); 4232 btrfs_end_transaction(trans);
4234 if (not_written) 4233 if (not_written)
4235 btrfs_dev_replace_stats_inc(&fs_info->dev_replace. 4234 btrfs_dev_replace_stats_inc(&fs_info->dev_replace.
4236 num_uncorrectable_read_errors); 4235 num_uncorrectable_read_errors);
diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
index 1df3b8798323..d145ce804620 100644
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -6112,7 +6112,7 @@ again:
6112 goto commit_trans; 6112 goto commit_trans;
6113 6113
6114 if (trans) 6114 if (trans)
6115 return btrfs_end_transaction(trans, sctx->send_root); 6115 return btrfs_end_transaction(trans);
6116 6116
6117 return 0; 6117 return 0;
6118 6118
@@ -6125,7 +6125,7 @@ commit_trans:
6125 goto again; 6125 goto again;
6126 } 6126 }
6127 6127
6128 return btrfs_commit_transaction(trans, sctx->send_root); 6128 return btrfs_commit_transaction(trans);
6129} 6129}
6130 6130
6131static void btrfs_root_dec_send_in_progress(struct btrfs_root* root) 6131static void btrfs_root_dec_send_in_progress(struct btrfs_root* root)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 3021b0f32e53..4a151930f201 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1206,7 +1206,7 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
1206 if (IS_ERR(trans)) 1206 if (IS_ERR(trans))
1207 return PTR_ERR(trans); 1207 return PTR_ERR(trans);
1208 } 1208 }
1209 return btrfs_commit_transaction(trans, root); 1209 return btrfs_commit_transaction(trans);
1210} 1210}
1211 1211
1212static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) 1212static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)
@@ -2251,7 +2251,7 @@ static int btrfs_freeze(struct super_block *sb)
2251 return 0; 2251 return 0;
2252 return PTR_ERR(trans); 2252 return PTR_ERR(trans);
2253 } 2253 }
2254 return btrfs_commit_transaction(trans, root); 2254 return btrfs_commit_transaction(trans);
2255} 2255}
2256 2256
2257static int btrfs_unfreeze(struct super_block *sb) 2257static int btrfs_unfreeze(struct super_block *sb)
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index a23fedde1ba1..0e0508f488b2 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -577,7 +577,7 @@ again:
577 if (cur_trans->state >= TRANS_STATE_BLOCKED && 577 if (cur_trans->state >= TRANS_STATE_BLOCKED &&
578 may_wait_transaction(fs_info, type)) { 578 may_wait_transaction(fs_info, type)) {
579 current->journal_info = h; 579 current->journal_info = h;
580 btrfs_commit_transaction(h, root); 580 btrfs_commit_transaction(h);
581 goto again; 581 goto again;
582 } 582 }
583 583
@@ -637,7 +637,7 @@ struct btrfs_trans_handle *btrfs_start_transaction_fallback_global_rsv(
637 ret = btrfs_cond_migrate_bytes(fs_info, &fs_info->trans_block_rsv, 637 ret = btrfs_cond_migrate_bytes(fs_info, &fs_info->trans_block_rsv,
638 num_bytes, min_factor); 638 num_bytes, min_factor);
639 if (ret) { 639 if (ret) {
640 btrfs_end_transaction(trans, root); 640 btrfs_end_transaction(trans);
641 return ERR_PTR(ret); 641 return ERR_PTR(ret);
642 } 642 }
643 643
@@ -795,11 +795,10 @@ static int should_end_transaction(struct btrfs_trans_handle *trans)
795 return !!btrfs_block_rsv_check(&fs_info->global_block_rsv, 5); 795 return !!btrfs_block_rsv_check(&fs_info->global_block_rsv, 5);
796} 796}
797 797
798int btrfs_should_end_transaction(struct btrfs_trans_handle *trans, 798int btrfs_should_end_transaction(struct btrfs_trans_handle *trans)
799 struct btrfs_root *root)
800{ 799{
801 struct btrfs_fs_info *fs_info = root->fs_info;
802 struct btrfs_transaction *cur_trans = trans->transaction; 800 struct btrfs_transaction *cur_trans = trans->transaction;
801 struct btrfs_fs_info *fs_info = trans->fs_info;
803 int updates; 802 int updates;
804 int err; 803 int err;
805 804
@@ -820,10 +819,10 @@ int btrfs_should_end_transaction(struct btrfs_trans_handle *trans,
820} 819}
821 820
822static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, 821static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
823 struct btrfs_root *root, int throttle) 822 int throttle)
824{ 823{
824 struct btrfs_fs_info *info = trans->fs_info;
825 struct btrfs_transaction *cur_trans = trans->transaction; 825 struct btrfs_transaction *cur_trans = trans->transaction;
826 struct btrfs_fs_info *info = root->fs_info;
827 u64 transid = trans->transid; 826 u64 transid = trans->transid;
828 unsigned long cur = trans->delayed_ref_updates; 827 unsigned long cur = trans->delayed_ref_updates;
829 int lock = (trans->type != TRANS_JOIN_NOLOCK); 828 int lock = (trans->type != TRANS_JOIN_NOLOCK);
@@ -876,7 +875,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
876 875
877 if (lock && ACCESS_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) { 876 if (lock && ACCESS_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) {
878 if (throttle) 877 if (throttle)
879 return btrfs_commit_transaction(trans, root); 878 return btrfs_commit_transaction(trans);
880 else 879 else
881 wake_up_process(info->transaction_kthread); 880 wake_up_process(info->transaction_kthread);
882 } 881 }
@@ -918,16 +917,14 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
918 return err; 917 return err;
919} 918}
920 919
921int btrfs_end_transaction(struct btrfs_trans_handle *trans, 920int btrfs_end_transaction(struct btrfs_trans_handle *trans)
922 struct btrfs_root *root)
923{ 921{
924 return __btrfs_end_transaction(trans, root, 0); 922 return __btrfs_end_transaction(trans, 0);
925} 923}
926 924
927int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans, 925int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans)
928 struct btrfs_root *root)
929{ 926{
930 return __btrfs_end_transaction(trans, root, 1); 927 return __btrfs_end_transaction(trans, 1);
931} 928}
932 929
933/* 930/*
@@ -1319,7 +1316,7 @@ int btrfs_defrag_root(struct btrfs_root *root)
1319 1316
1320 ret = btrfs_defrag_leaves(trans, root); 1317 ret = btrfs_defrag_leaves(trans, root);
1321 1318
1322 btrfs_end_transaction(trans, root); 1319 btrfs_end_transaction(trans);
1323 btrfs_btree_balance_dirty(info); 1320 btrfs_btree_balance_dirty(info);
1324 cond_resched(); 1321 cond_resched();
1325 1322
@@ -1794,7 +1791,6 @@ static void wait_current_trans_commit_start_and_unblock(
1794 */ 1791 */
1795struct btrfs_async_commit { 1792struct btrfs_async_commit {
1796 struct btrfs_trans_handle *newtrans; 1793 struct btrfs_trans_handle *newtrans;
1797 struct btrfs_root *root;
1798 struct work_struct work; 1794 struct work_struct work;
1799}; 1795};
1800 1796
@@ -1808,19 +1804,18 @@ static void do_async_commit(struct work_struct *work)
1808 * Tell lockdep about it. 1804 * Tell lockdep about it.
1809 */ 1805 */
1810 if (ac->newtrans->type & __TRANS_FREEZABLE) 1806 if (ac->newtrans->type & __TRANS_FREEZABLE)
1811 __sb_writers_acquired(ac->root->fs_info->sb, SB_FREEZE_FS); 1807 __sb_writers_acquired(ac->newtrans->fs_info->sb, SB_FREEZE_FS);
1812 1808
1813 current->journal_info = ac->newtrans; 1809 current->journal_info = ac->newtrans;
1814 1810
1815 btrfs_commit_transaction(ac->newtrans, ac->root); 1811 btrfs_commit_transaction(ac->newtrans);
1816 kfree(ac); 1812 kfree(ac);
1817} 1813}
1818 1814
1819int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, 1815int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
1820 struct btrfs_root *root,
1821 int wait_for_unblock) 1816 int wait_for_unblock)
1822{ 1817{
1823 struct btrfs_fs_info *fs_info = root->fs_info; 1818 struct btrfs_fs_info *fs_info = trans->fs_info;
1824 struct btrfs_async_commit *ac; 1819 struct btrfs_async_commit *ac;
1825 struct btrfs_transaction *cur_trans; 1820 struct btrfs_transaction *cur_trans;
1826 1821
@@ -1829,8 +1824,7 @@ int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
1829 return -ENOMEM; 1824 return -ENOMEM;
1830 1825
1831 INIT_WORK(&ac->work, do_async_commit); 1826 INIT_WORK(&ac->work, do_async_commit);
1832 ac->root = root; 1827 ac->newtrans = btrfs_join_transaction(trans->root);
1833 ac->newtrans = btrfs_join_transaction(root);
1834 if (IS_ERR(ac->newtrans)) { 1828 if (IS_ERR(ac->newtrans)) {
1835 int err = PTR_ERR(ac->newtrans); 1829 int err = PTR_ERR(ac->newtrans);
1836 kfree(ac); 1830 kfree(ac);
@@ -1841,7 +1835,7 @@ int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
1841 cur_trans = trans->transaction; 1835 cur_trans = trans->transaction;
1842 atomic_inc(&cur_trans->use_count); 1836 atomic_inc(&cur_trans->use_count);
1843 1837
1844 btrfs_end_transaction(trans, root); 1838 btrfs_end_transaction(trans);
1845 1839
1846 /* 1840 /*
1847 * Tell lockdep we've released the freeze rwsem, since the 1841 * Tell lockdep we've released the freeze rwsem, since the
@@ -1938,10 +1932,9 @@ btrfs_wait_pending_ordered(struct btrfs_transaction *cur_trans)
1938 atomic_read(&cur_trans->pending_ordered) == 0); 1932 atomic_read(&cur_trans->pending_ordered) == 0);
1939} 1933}
1940 1934
1941int btrfs_commit_transaction(struct btrfs_trans_handle *trans, 1935int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
1942 struct btrfs_root *root)
1943{ 1936{
1944 struct btrfs_fs_info *fs_info = root->fs_info; 1937 struct btrfs_fs_info *fs_info = trans->fs_info;
1945 struct btrfs_transaction *cur_trans = trans->transaction; 1938 struct btrfs_transaction *cur_trans = trans->transaction;
1946 struct btrfs_transaction *prev_trans = NULL; 1939 struct btrfs_transaction *prev_trans = NULL;
1947 int ret; 1940 int ret;
@@ -1949,7 +1942,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
1949 /* Stop the commit early if ->aborted is set */ 1942 /* Stop the commit early if ->aborted is set */
1950 if (unlikely(ACCESS_ONCE(cur_trans->aborted))) { 1943 if (unlikely(ACCESS_ONCE(cur_trans->aborted))) {
1951 ret = cur_trans->aborted; 1944 ret = cur_trans->aborted;
1952 btrfs_end_transaction(trans, root); 1945 btrfs_end_transaction(trans);
1953 return ret; 1946 return ret;
1954 } 1947 }
1955 1948
@@ -1958,7 +1951,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
1958 */ 1951 */
1959 ret = btrfs_run_delayed_refs(trans, fs_info, 0); 1952 ret = btrfs_run_delayed_refs(trans, fs_info, 0);
1960 if (ret) { 1953 if (ret) {
1961 btrfs_end_transaction(trans, root); 1954 btrfs_end_transaction(trans);
1962 return ret; 1955 return ret;
1963 } 1956 }
1964 1957
@@ -1979,7 +1972,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
1979 1972
1980 ret = btrfs_run_delayed_refs(trans, fs_info, 0); 1973 ret = btrfs_run_delayed_refs(trans, fs_info, 0);
1981 if (ret) { 1974 if (ret) {
1982 btrfs_end_transaction(trans, root); 1975 btrfs_end_transaction(trans);
1983 return ret; 1976 return ret;
1984 } 1977 }
1985 1978
@@ -2009,7 +2002,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
2009 ret = btrfs_start_dirty_block_groups(trans, fs_info); 2002 ret = btrfs_start_dirty_block_groups(trans, fs_info);
2010 } 2003 }
2011 if (ret) { 2004 if (ret) {
2012 btrfs_end_transaction(trans, root); 2005 btrfs_end_transaction(trans);
2013 return ret; 2006 return ret;
2014 } 2007 }
2015 2008
@@ -2017,7 +2010,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
2017 if (cur_trans->state >= TRANS_STATE_COMMIT_START) { 2010 if (cur_trans->state >= TRANS_STATE_COMMIT_START) {
2018 spin_unlock(&fs_info->trans_lock); 2011 spin_unlock(&fs_info->trans_lock);
2019 atomic_inc(&cur_trans->use_count); 2012 atomic_inc(&cur_trans->use_count);
2020 ret = btrfs_end_transaction(trans, root); 2013 ret = btrfs_end_transaction(trans);
2021 2014
2022 wait_for_commit(cur_trans); 2015 wait_for_commit(cur_trans);
2023 2016
@@ -2293,7 +2286,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
2293 if (trans->type & __TRANS_FREEZABLE) 2286 if (trans->type & __TRANS_FREEZABLE)
2294 sb_end_intwrite(fs_info->sb); 2287 sb_end_intwrite(fs_info->sb);
2295 2288
2296 trace_btrfs_transaction_commit(root); 2289 trace_btrfs_transaction_commit(trans->root);
2297 2290
2298 btrfs_scrub_continue(fs_info); 2291 btrfs_scrub_continue(fs_info);
2299 2292
@@ -2321,7 +2314,7 @@ cleanup_transaction:
2321 btrfs_warn(fs_info, "Skipping commit of aborted transaction."); 2314 btrfs_warn(fs_info, "Skipping commit of aborted transaction.");
2322 if (current->journal_info == trans) 2315 if (current->journal_info == trans)
2323 current->journal_info = NULL; 2316 current->journal_info = NULL;
2324 cleanup_transaction(trans, root, ret); 2317 cleanup_transaction(trans, trans->root, ret);
2325 2318
2326 return ret; 2319 return ret;
2327} 2320}
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
index 1c43ed3aa1ac..5dfb5590fff6 100644
--- a/fs/btrfs/transaction.h
+++ b/fs/btrfs/transaction.h
@@ -123,11 +123,6 @@ struct btrfs_trans_handle {
123 bool sync; 123 bool sync;
124 bool dirty; 124 bool dirty;
125 unsigned int type; 125 unsigned int type;
126 /*
127 * this root is only needed to validate that the root passed to
128 * start_transaction is the same as the one passed to end_transaction.
129 * Subvolume quota depends on this
130 */
131 struct btrfs_root *root; 126 struct btrfs_root *root;
132 struct btrfs_fs_info *fs_info; 127 struct btrfs_fs_info *fs_info;
133 struct seq_list delayed_ref_elem; 128 struct seq_list delayed_ref_elem;
@@ -185,8 +180,7 @@ static inline void btrfs_clear_skip_qgroup(struct btrfs_trans_handle *trans)
185 delayed_refs->qgroup_to_skip = 0; 180 delayed_refs->qgroup_to_skip = 0;
186} 181}
187 182
188int btrfs_end_transaction(struct btrfs_trans_handle *trans, 183int btrfs_end_transaction(struct btrfs_trans_handle *trans);
189 struct btrfs_root *root);
190struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root, 184struct btrfs_trans_handle *btrfs_start_transaction(struct btrfs_root *root,
191 unsigned int num_items); 185 unsigned int num_items);
192struct btrfs_trans_handle *btrfs_start_transaction_fallback_global_rsv( 186struct btrfs_trans_handle *btrfs_start_transaction_fallback_global_rsv(
@@ -207,15 +201,11 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid);
207void btrfs_add_dead_root(struct btrfs_root *root); 201void btrfs_add_dead_root(struct btrfs_root *root);
208int btrfs_defrag_root(struct btrfs_root *root); 202int btrfs_defrag_root(struct btrfs_root *root);
209int btrfs_clean_one_deleted_snapshot(struct btrfs_root *root); 203int btrfs_clean_one_deleted_snapshot(struct btrfs_root *root);
210int btrfs_commit_transaction(struct btrfs_trans_handle *trans, 204int btrfs_commit_transaction(struct btrfs_trans_handle *trans);
211 struct btrfs_root *root);
212int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, 205int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
213 struct btrfs_root *root,
214 int wait_for_unblock); 206 int wait_for_unblock);
215int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans, 207int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans);
216 struct btrfs_root *root); 208int btrfs_should_end_transaction(struct btrfs_trans_handle *trans);
217int btrfs_should_end_transaction(struct btrfs_trans_handle *trans,
218 struct btrfs_root *root);
219void btrfs_throttle(struct btrfs_fs_info *fs_info); 209void btrfs_throttle(struct btrfs_fs_info *fs_info);
220int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans, 210int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans,
221 struct btrfs_root *root); 211 struct btrfs_root *root);
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 61c7f6f3034e..f7324189413c 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -5695,7 +5695,7 @@ again:
5695 btrfs_free_path(path); 5695 btrfs_free_path(path);
5696 5696
5697 /* step 4: commit the transaction, which also unpins the blocks */ 5697 /* step 4: commit the transaction, which also unpins the blocks */
5698 ret = btrfs_commit_transaction(trans, fs_info->tree_root); 5698 ret = btrfs_commit_transaction(trans);
5699 if (ret) 5699 if (ret)
5700 return ret; 5700 return ret;
5701 5701
@@ -5707,7 +5707,7 @@ again:
5707 return 0; 5707 return 0;
5708error: 5708error:
5709 if (wc.trans) 5709 if (wc.trans)
5710 btrfs_end_transaction(wc.trans, fs_info->tree_root); 5710 btrfs_end_transaction(wc.trans);
5711 btrfs_free_path(path); 5711 btrfs_free_path(path);
5712 return ret; 5712 return ret;
5713} 5713}
diff --git a/fs/btrfs/uuid-tree.c b/fs/btrfs/uuid-tree.c
index 0a211d4ce8e0..161342b73ce5 100644
--- a/fs/btrfs/uuid-tree.c
+++ b/fs/btrfs/uuid-tree.c
@@ -252,7 +252,7 @@ static int btrfs_uuid_iter_rem(struct btrfs_root *uuid_root, u8 *uuid, u8 type,
252 } 252 }
253 253
254 ret = btrfs_uuid_tree_rem(trans, uuid_root->fs_info, uuid, type, subid); 254 ret = btrfs_uuid_tree_rem(trans, uuid_root->fs_info, uuid, type, subid);
255 btrfs_end_transaction(trans, uuid_root); 255 btrfs_end_transaction(trans);
256 256
257out: 257out:
258 return ret; 258 return ret;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index e7127bd61485..cf3838604987 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1773,7 +1773,7 @@ static int btrfs_rm_dev_item(struct btrfs_fs_info *fs_info,
1773 goto out; 1773 goto out;
1774out: 1774out:
1775 btrfs_free_path(path); 1775 btrfs_free_path(path);
1776 btrfs_commit_transaction(trans, root); 1776 btrfs_commit_transaction(trans);
1777 return ret; 1777 return ret;
1778} 1778}
1779 1779
@@ -2475,7 +2475,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
2475 2475
2476 fs_info->num_tolerated_disk_barrier_failures = 2476 fs_info->num_tolerated_disk_barrier_failures =
2477 btrfs_calc_num_tolerated_disk_barrier_failures(fs_info); 2477 btrfs_calc_num_tolerated_disk_barrier_failures(fs_info);
2478 ret = btrfs_commit_transaction(trans, root); 2478 ret = btrfs_commit_transaction(trans);
2479 2479
2480 if (seeding_dev) { 2480 if (seeding_dev) {
2481 mutex_unlock(&uuid_mutex); 2481 mutex_unlock(&uuid_mutex);
@@ -2494,7 +2494,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
2494 return 0; 2494 return 0;
2495 return PTR_ERR(trans); 2495 return PTR_ERR(trans);
2496 } 2496 }
2497 ret = btrfs_commit_transaction(trans, root); 2497 ret = btrfs_commit_transaction(trans);
2498 } 2498 }
2499 2499
2500 /* Update ctime/mtime for libblkid */ 2500 /* Update ctime/mtime for libblkid */
@@ -2502,7 +2502,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
2502 return ret; 2502 return ret;
2503 2503
2504error_trans: 2504error_trans:
2505 btrfs_end_transaction(trans, root); 2505 btrfs_end_transaction(trans);
2506 rcu_string_free(device->name); 2506 rcu_string_free(device->name);
2507 btrfs_sysfs_rm_device_link(fs_info->fs_devices, device); 2507 btrfs_sysfs_rm_device_link(fs_info->fs_devices, device);
2508 kfree(device); 2508 kfree(device);
@@ -2899,7 +2899,6 @@ out:
2899static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset) 2899static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset)
2900{ 2900{
2901 struct btrfs_root *root = fs_info->chunk_root; 2901 struct btrfs_root *root = fs_info->chunk_root;
2902 struct btrfs_root *extent_root = fs_info->extent_root;
2903 struct btrfs_trans_handle *trans; 2902 struct btrfs_trans_handle *trans;
2904 int ret; 2903 int ret;
2905 2904
@@ -2941,7 +2940,7 @@ static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset)
2941 * chunk tree entries 2940 * chunk tree entries
2942 */ 2941 */
2943 ret = btrfs_remove_chunk(trans, fs_info, chunk_offset); 2942 ret = btrfs_remove_chunk(trans, fs_info, chunk_offset);
2944 btrfs_end_transaction(trans, extent_root); 2943 btrfs_end_transaction(trans);
2945 return ret; 2944 return ret;
2946} 2945}
2947 2946
@@ -3067,7 +3066,7 @@ static int insert_balance_item(struct btrfs_fs_info *fs_info,
3067 btrfs_mark_buffer_dirty(leaf); 3066 btrfs_mark_buffer_dirty(leaf);
3068out: 3067out:
3069 btrfs_free_path(path); 3068 btrfs_free_path(path);
3070 err = btrfs_commit_transaction(trans, root); 3069 err = btrfs_commit_transaction(trans);
3071 if (err && !ret) 3070 if (err && !ret)
3072 ret = err; 3071 ret = err;
3073 return ret; 3072 return ret;
@@ -3106,7 +3105,7 @@ static int del_balance_item(struct btrfs_fs_info *fs_info)
3106 ret = btrfs_del_item(trans, root, path); 3105 ret = btrfs_del_item(trans, root, path);
3107out: 3106out:
3108 btrfs_free_path(path); 3107 btrfs_free_path(path);
3109 err = btrfs_commit_transaction(trans, root); 3108 err = btrfs_commit_transaction(trans);
3110 if (err && !ret) 3109 if (err && !ret)
3111 ret = err; 3110 ret = err;
3112 return ret; 3111 return ret;
@@ -3513,7 +3512,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
3513 3512
3514 ret = btrfs_grow_device(trans, device, old_size); 3513 ret = btrfs_grow_device(trans, device, old_size);
3515 if (ret) { 3514 if (ret) {
3516 btrfs_end_transaction(trans, dev_root); 3515 btrfs_end_transaction(trans);
3517 /* btrfs_grow_device never returns ret > 0 */ 3516 /* btrfs_grow_device never returns ret > 0 */
3518 WARN_ON(ret > 0); 3517 WARN_ON(ret > 0);
3519 btrfs_info_in_rcu(fs_info, 3518 btrfs_info_in_rcu(fs_info,
@@ -3523,7 +3522,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
3523 goto error; 3522 goto error;
3524 } 3523 }
3525 3524
3526 btrfs_end_transaction(trans, dev_root); 3525 btrfs_end_transaction(trans);
3527 } 3526 }
3528 3527
3529 /* step two, relocate all the chunks */ 3528 /* step two, relocate all the chunks */
@@ -3653,7 +3652,7 @@ again:
3653 3652
3654 ret = btrfs_force_chunk_alloc(trans, fs_info, 3653 ret = btrfs_force_chunk_alloc(trans, fs_info,
3655 BTRFS_BLOCK_GROUP_DATA); 3654 BTRFS_BLOCK_GROUP_DATA);
3656 btrfs_end_transaction(trans, chunk_root); 3655 btrfs_end_transaction(trans);
3657 if (ret < 0) { 3656 if (ret < 0) {
3658 mutex_unlock(&fs_info->delete_unused_bgs_mutex); 3657 mutex_unlock(&fs_info->delete_unused_bgs_mutex);
3659 goto error; 3658 goto error;
@@ -4182,7 +4181,7 @@ update_tree:
4182 4181
4183skip: 4182skip:
4184 if (trans) { 4183 if (trans) {
4185 ret = btrfs_end_transaction(trans, fs_info->uuid_root); 4184 ret = btrfs_end_transaction(trans);
4186 trans = NULL; 4185 trans = NULL;
4187 if (ret) 4186 if (ret)
4188 break; 4187 break;
@@ -4207,7 +4206,7 @@ skip:
4207out: 4206out:
4208 btrfs_free_path(path); 4207 btrfs_free_path(path);
4209 if (trans && !IS_ERR(trans)) 4208 if (trans && !IS_ERR(trans))
4210 btrfs_end_transaction(trans, fs_info->uuid_root); 4209 btrfs_end_transaction(trans);
4211 if (ret) 4210 if (ret)
4212 btrfs_warn(fs_info, "btrfs_uuid_scan_kthread failed %d", ret); 4211 btrfs_warn(fs_info, "btrfs_uuid_scan_kthread failed %d", ret);
4213 else 4212 else
@@ -4301,13 +4300,13 @@ int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info)
4301 if (IS_ERR(uuid_root)) { 4300 if (IS_ERR(uuid_root)) {
4302 ret = PTR_ERR(uuid_root); 4301 ret = PTR_ERR(uuid_root);
4303 btrfs_abort_transaction(trans, ret); 4302 btrfs_abort_transaction(trans, ret);
4304 btrfs_end_transaction(trans, tree_root); 4303 btrfs_end_transaction(trans);
4305 return ret; 4304 return ret;
4306 } 4305 }
4307 4306
4308 fs_info->uuid_root = uuid_root; 4307 fs_info->uuid_root = uuid_root;
4309 4308
4310 ret = btrfs_commit_transaction(trans, tree_root); 4309 ret = btrfs_commit_transaction(trans);
4311 if (ret) 4310 if (ret)
4312 return ret; 4311 return ret;
4313 4312
@@ -4479,7 +4478,7 @@ again:
4479 checked_pending_chunks = true; 4478 checked_pending_chunks = true;
4480 failed = 0; 4479 failed = 0;
4481 retried = false; 4480 retried = false;
4482 ret = btrfs_commit_transaction(trans, root); 4481 ret = btrfs_commit_transaction(trans);
4483 if (ret) 4482 if (ret)
4484 goto done; 4483 goto done;
4485 goto again; 4484 goto again;
@@ -4497,7 +4496,7 @@ again:
4497 4496
4498 /* Now btrfs_update_device() will change the on-disk size. */ 4497 /* Now btrfs_update_device() will change the on-disk size. */
4499 ret = btrfs_update_device(trans, device); 4498 ret = btrfs_update_device(trans, device);
4500 btrfs_end_transaction(trans, root); 4499 btrfs_end_transaction(trans);
4501done: 4500done:
4502 btrfs_free_path(path); 4501 btrfs_free_path(path);
4503 if (ret) { 4502 if (ret) {
diff --git a/fs/btrfs/xattr.c b/fs/btrfs/xattr.c
index 7dfd2f06eb55..9621c7f2503e 100644
--- a/fs/btrfs/xattr.c
+++ b/fs/btrfs/xattr.c
@@ -259,7 +259,7 @@ int __btrfs_setxattr(struct btrfs_trans_handle *trans,
259 ret = btrfs_update_inode(trans, root, inode); 259 ret = btrfs_update_inode(trans, root, inode);
260 BUG_ON(ret); 260 BUG_ON(ret);
261out: 261out:
262 btrfs_end_transaction(trans, root); 262 btrfs_end_transaction(trans);
263 return ret; 263 return ret;
264} 264}
265 265