btrfs: Don't pass fs_info to commit_fs_roots
[sfrench/cifs-2.6.git] / fs / btrfs / transaction.c
index 04f07144b45ce265b36af2754455accc89954005..f831251237fecae86f9a41de53201c7822dbcc86 100644 (file)
@@ -658,14 +658,6 @@ struct btrfs_trans_handle *btrfs_start_transaction_fallback_global_rsv(
        return trans;
 }
 
-struct btrfs_trans_handle *btrfs_start_transaction_lflush(
-                                       struct btrfs_root *root,
-                                       unsigned int num_items)
-{
-       return start_transaction(root, num_items, TRANS_START,
-                                BTRFS_RESERVE_FLUSH_LIMIT, true);
-}
-
 struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root)
 {
        return start_transaction(root, 0, TRANS_JOIN, BTRFS_RESERVE_NO_FLUSH,
@@ -826,6 +818,27 @@ int btrfs_should_end_transaction(struct btrfs_trans_handle *trans)
        return should_end_transaction(trans);
 }
 
+static void btrfs_trans_release_metadata(struct btrfs_trans_handle *trans)
+
+{
+       struct btrfs_fs_info *fs_info = trans->fs_info;
+
+       if (!trans->block_rsv) {
+               ASSERT(!trans->bytes_reserved);
+               return;
+       }
+
+       if (!trans->bytes_reserved)
+               return;
+
+       ASSERT(trans->block_rsv == &fs_info->trans_block_rsv);
+       trace_btrfs_space_reservation(fs_info, "transaction",
+                                     trans->transid, trans->bytes_reserved, 0);
+       btrfs_block_rsv_release(fs_info, trans->block_rsv,
+                               trans->bytes_reserved);
+       trans->bytes_reserved = 0;
+}
+
 static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
                                   int throttle)
 {
@@ -843,11 +856,11 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
                return 0;
        }
 
-       btrfs_trans_release_metadata(trans, info);
+       btrfs_trans_release_metadata(trans);
        trans->block_rsv = NULL;
 
        if (!list_empty(&trans->new_bgs))
-               btrfs_create_pending_block_groups(trans, info);
+               btrfs_create_pending_block_groups(trans);
 
        trans->delayed_ref_updates = 0;
        if (!trans->sync) {
@@ -864,11 +877,11 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
                        must_run_delayed_refs = 2;
        }
 
-       btrfs_trans_release_metadata(trans, info);
+       btrfs_trans_release_metadata(trans);
        trans->block_rsv = NULL;
 
        if (!list_empty(&trans->new_bgs))
-               btrfs_create_pending_block_groups(trans, info);
+               btrfs_create_pending_block_groups(trans);
 
        btrfs_trans_release_chunk_metadata(trans);
 
@@ -1072,40 +1085,33 @@ int btrfs_wait_tree_log_extents(struct btrfs_root *log_root, int mark)
 }
 
 /*
- * when btree blocks are allocated, they have some corresponding bits set for
- * them in one of two extent_io trees.  This is used to make sure all of
- * those extents are on disk for transaction or log commit
+ * When btree blocks are allocated the corresponding extents are marked dirty.
+ * This function ensures such extents are persisted on disk for transaction or
+ * log commit.
+ *
+ * @trans: transaction whose dirty pages we'd like to write
  */
-static int btrfs_write_and_wait_marked_extents(struct btrfs_fs_info *fs_info,
-                               struct extent_io_tree *dirty_pages, int mark)
+static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
+                                           struct btrfs_fs_info *fs_info)
 {
        int ret;
        int ret2;
+       struct extent_io_tree *dirty_pages = &trans->transaction->dirty_pages;
        struct blk_plug plug;
 
        blk_start_plug(&plug);
-       ret = btrfs_write_marked_extents(fs_info, dirty_pages, mark);
+       ret = btrfs_write_marked_extents(fs_info, dirty_pages, EXTENT_DIRTY);
        blk_finish_plug(&plug);
        ret2 = btrfs_wait_extents(fs_info, dirty_pages);
 
+       clear_btree_io_tree(&trans->transaction->dirty_pages);
+
        if (ret)
                return ret;
-       if (ret2)
+       else if (ret2)
                return ret2;
-       return 0;
-}
-
-static int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
-                                           struct btrfs_fs_info *fs_info)
-{
-       int ret;
-
-       ret = btrfs_write_and_wait_marked_extents(fs_info,
-                                          &trans->transaction->dirty_pages,
-                                          EXTENT_DIRTY);
-       clear_btree_io_tree(&trans->transaction->dirty_pages);
-
-       return ret;
+       else
+               return 0;
 }
 
 /*
@@ -1251,9 +1257,9 @@ void btrfs_add_dead_root(struct btrfs_root *root)
 /*
  * update all the cowonly tree roots on disk
  */
-static noinline int commit_fs_roots(struct btrfs_trans_handle *trans,
-                                   struct btrfs_fs_info *fs_info)
+static noinline int commit_fs_roots(struct btrfs_trans_handle *trans)
 {
+       struct btrfs_fs_info *fs_info = trans->fs_info;
        struct btrfs_root *gang[8];
        int i;
        int ret;
@@ -1371,7 +1377,7 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,
         */
        mutex_lock(&fs_info->tree_log_mutex);
 
-       ret = commit_fs_roots(trans, fs_info);
+       ret = commit_fs_roots(trans);
        if (ret)
                goto out;
        ret = btrfs_qgroup_account_extents(trans, fs_info);
@@ -1524,7 +1530,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
         * otherwise we corrupt the FS during
         * snapshot
         */
-       ret = btrfs_run_delayed_items(trans, fs_info);
+       ret = btrfs_run_delayed_items(trans);
        if (ret) {      /* Transaction aborted */
                btrfs_abort_transaction(trans, ret);
                goto fail;
@@ -1965,7 +1971,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
                return ret;
        }
 
-       btrfs_trans_release_metadata(trans, fs_info);
+       btrfs_trans_release_metadata(trans);
        trans->block_rsv = NULL;
 
        cur_trans = trans->transaction;
@@ -1978,7 +1984,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
        smp_wmb();
 
        if (!list_empty(&trans->new_bgs))
-               btrfs_create_pending_block_groups(trans, fs_info);
+               btrfs_create_pending_block_groups(trans);
 
        ret = btrfs_run_delayed_refs(trans, fs_info, 0);
        if (ret) {
@@ -2009,7 +2015,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
                mutex_unlock(&fs_info->ro_block_group_mutex);
 
                if (run_it)
-                       ret = btrfs_start_dirty_block_groups(trans, fs_info);
+                       ret = btrfs_start_dirty_block_groups(trans);
        }
        if (ret) {
                btrfs_end_transaction(trans);
@@ -2061,7 +2067,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
        if (ret)
                goto cleanup_transaction;
 
-       ret = btrfs_run_delayed_items(trans, fs_info);
+       ret = btrfs_run_delayed_items(trans);
        if (ret)
                goto cleanup_transaction;
 
@@ -2069,7 +2075,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
                   extwriter_counter_read(cur_trans) == 0);
 
        /* some pending stuffs might be added after the previous flush. */
-       ret = btrfs_run_delayed_items(trans, fs_info);
+       ret = btrfs_run_delayed_items(trans);
        if (ret)
                goto cleanup_transaction;
 
@@ -2122,7 +2128,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
         * because all the tree which are snapshoted will be forced to COW
         * the nodes and leaves.
         */
-       ret = btrfs_run_delayed_items(trans, fs_info);
+       ret = btrfs_run_delayed_items(trans);
        if (ret) {
                mutex_unlock(&fs_info->reloc_mutex);
                goto scrub_continue;
@@ -2157,7 +2163,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
         */
        mutex_lock(&fs_info->tree_log_mutex);
 
-       ret = commit_fs_roots(trans, fs_info);
+       ret = commit_fs_roots(trans);
        if (ret) {
                mutex_unlock(&fs_info->tree_log_mutex);
                mutex_unlock(&fs_info->reloc_mutex);
@@ -2319,7 +2325,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 scrub_continue:
        btrfs_scrub_continue(fs_info);
 cleanup_transaction:
-       btrfs_trans_release_metadata(trans, fs_info);
+       btrfs_trans_release_metadata(trans);
        btrfs_trans_release_chunk_metadata(trans);
        trans->block_rsv = NULL;
        btrfs_warn(fs_info, "Skipping commit of aborted transaction.");