Btrfs: replace tree->mapping with tree->private_data
[sfrench/cifs-2.6.git] / fs / btrfs / transaction.c
index 61b807de3e164e38877230cdfd1e9a545573f1be..ca0009ff47f1deb56339a2836e49f6f8c18e3b8e 100644 (file)
@@ -60,8 +60,8 @@ static const unsigned int btrfs_blocked_trans_types[TRANS_STATE_MAX] = {
 
 void btrfs_put_transaction(struct btrfs_transaction *transaction)
 {
 
 void btrfs_put_transaction(struct btrfs_transaction *transaction)
 {
-       WARN_ON(atomic_read(&transaction->use_count) == 0);
-       if (atomic_dec_and_test(&transaction->use_count)) {
+       WARN_ON(refcount_read(&transaction->use_count) == 0);
+       if (refcount_dec_and_test(&transaction->use_count)) {
                BUG_ON(!list_empty(&transaction->list));
                WARN_ON(!RB_EMPTY_ROOT(&transaction->delayed_refs.href_root));
                if (transaction->delayed_refs.pending_csums)
                BUG_ON(!list_empty(&transaction->list));
                WARN_ON(!RB_EMPTY_ROOT(&transaction->delayed_refs.href_root));
                if (transaction->delayed_refs.pending_csums)
@@ -207,7 +207,7 @@ loop:
                        spin_unlock(&fs_info->trans_lock);
                        return -EBUSY;
                }
                        spin_unlock(&fs_info->trans_lock);
                        return -EBUSY;
                }
-               atomic_inc(&cur_trans->use_count);
+               refcount_inc(&cur_trans->use_count);
                atomic_inc(&cur_trans->num_writers);
                extwriter_counter_inc(cur_trans, type);
                spin_unlock(&fs_info->trans_lock);
                atomic_inc(&cur_trans->num_writers);
                extwriter_counter_inc(cur_trans, type);
                spin_unlock(&fs_info->trans_lock);
@@ -257,7 +257,7 @@ loop:
         * One for this trans handle, one so it will live on until we
         * commit the transaction.
         */
         * One for this trans handle, one so it will live on until we
         * commit the transaction.
         */
-       atomic_set(&cur_trans->use_count, 2);
+       refcount_set(&cur_trans->use_count, 2);
        atomic_set(&cur_trans->pending_ordered, 0);
        cur_trans->flags = 0;
        cur_trans->start_time = get_seconds();
        atomic_set(&cur_trans->pending_ordered, 0);
        cur_trans->flags = 0;
        cur_trans->start_time = get_seconds();
@@ -294,7 +294,7 @@ loop:
        spin_lock_init(&cur_trans->dropped_roots_lock);
        list_add_tail(&cur_trans->list, &fs_info->trans_list);
        extent_io_tree_init(&cur_trans->dirty_pages,
        spin_lock_init(&cur_trans->dropped_roots_lock);
        list_add_tail(&cur_trans->list, &fs_info->trans_list);
        extent_io_tree_init(&cur_trans->dirty_pages,
-                            fs_info->btree_inode->i_mapping);
+                            fs_info->btree_inode);
        fs_info->generation++;
        cur_trans->transid = fs_info->generation;
        fs_info->running_transaction = cur_trans;
        fs_info->generation++;
        cur_trans->transid = fs_info->generation;
        fs_info->running_transaction = cur_trans;
@@ -432,7 +432,7 @@ static void wait_current_trans(struct btrfs_fs_info *fs_info)
        spin_lock(&fs_info->trans_lock);
        cur_trans = fs_info->running_transaction;
        if (cur_trans && is_transaction_blocked(cur_trans)) {
        spin_lock(&fs_info->trans_lock);
        cur_trans = fs_info->running_transaction;
        if (cur_trans && is_transaction_blocked(cur_trans)) {
-               atomic_inc(&cur_trans->use_count);
+               refcount_inc(&cur_trans->use_count);
                spin_unlock(&fs_info->trans_lock);
 
                wait_event(fs_info->transaction_wait,
                spin_unlock(&fs_info->trans_lock);
 
                wait_event(fs_info->transaction_wait,
@@ -572,7 +572,6 @@ again:
 
        h->type = type;
        h->can_flush_pending_bgs = true;
 
        h->type = type;
        h->can_flush_pending_bgs = true;
-       INIT_LIST_HEAD(&h->qgroup_ref_list);
        INIT_LIST_HEAD(&h->new_bgs);
 
        smp_mb();
        INIT_LIST_HEAD(&h->new_bgs);
 
        smp_mb();
@@ -744,7 +743,7 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid)
                list_for_each_entry(t, &fs_info->trans_list, list) {
                        if (t->transid == transid) {
                                cur_trans = t;
                list_for_each_entry(t, &fs_info->trans_list, list) {
                        if (t->transid == transid) {
                                cur_trans = t;
-                               atomic_inc(&cur_trans->use_count);
+                               refcount_inc(&cur_trans->use_count);
                                ret = 0;
                                break;
                        }
                                ret = 0;
                                break;
                        }
@@ -773,7 +772,7 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid)
                                if (t->state == TRANS_STATE_COMPLETED)
                                        break;
                                cur_trans = t;
                                if (t->state == TRANS_STATE_COMPLETED)
                                        break;
                                cur_trans = t;
-                               atomic_inc(&cur_trans->use_count);
+                               refcount_inc(&cur_trans->use_count);
                                break;
                        }
                }
                                break;
                        }
                }
@@ -917,7 +916,6 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
                wake_up_process(info->transaction_kthread);
                err = -EIO;
        }
                wake_up_process(info->transaction_kthread);
                err = -EIO;
        }
-       assert_qgroups_uptodate(trans);
 
        kmem_cache_free(btrfs_trans_handle_cachep, trans);
        if (must_run_delayed_refs) {
 
        kmem_cache_free(btrfs_trans_handle_cachep, trans);
        if (must_run_delayed_refs) {
@@ -1839,7 +1837,7 @@ int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
 
        /* take transaction reference */
        cur_trans = trans->transaction;
 
        /* take transaction reference */
        cur_trans = trans->transaction;
-       atomic_inc(&cur_trans->use_count);
+       refcount_inc(&cur_trans->use_count);
 
        btrfs_end_transaction(trans);
 
 
        btrfs_end_transaction(trans);
 
@@ -2015,7 +2013,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
        spin_lock(&fs_info->trans_lock);
        if (cur_trans->state >= TRANS_STATE_COMMIT_START) {
                spin_unlock(&fs_info->trans_lock);
        spin_lock(&fs_info->trans_lock);
        if (cur_trans->state >= TRANS_STATE_COMMIT_START) {
                spin_unlock(&fs_info->trans_lock);
-               atomic_inc(&cur_trans->use_count);
+               refcount_inc(&cur_trans->use_count);
                ret = btrfs_end_transaction(trans);
 
                wait_for_commit(cur_trans);
                ret = btrfs_end_transaction(trans);
 
                wait_for_commit(cur_trans);
@@ -2035,7 +2033,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
                prev_trans = list_entry(cur_trans->list.prev,
                                        struct btrfs_transaction, list);
                if (prev_trans->state != TRANS_STATE_COMPLETED) {
                prev_trans = list_entry(cur_trans->list.prev,
                                        struct btrfs_transaction, list);
                if (prev_trans->state != TRANS_STATE_COMPLETED) {
-                       atomic_inc(&prev_trans->use_count);
+                       refcount_inc(&prev_trans->use_count);
                        spin_unlock(&fs_info->trans_lock);
 
                        wait_for_commit(prev_trans);
                        spin_unlock(&fs_info->trans_lock);
 
                        wait_for_commit(prev_trans);
@@ -2130,13 +2128,6 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
                goto scrub_continue;
        }
 
                goto scrub_continue;
        }
 
-       /* Reocrd old roots for later qgroup accounting */
-       ret = btrfs_qgroup_prepare_account_extents(trans, fs_info);
-       if (ret) {
-               mutex_unlock(&fs_info->reloc_mutex);
-               goto scrub_continue;
-       }
-
        /*
         * make sure none of the code above managed to slip in a
         * delayed item
        /*
         * make sure none of the code above managed to slip in a
         * delayed item
@@ -2178,6 +2169,24 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
         */
        btrfs_free_log_root_tree(trans, fs_info);
 
         */
        btrfs_free_log_root_tree(trans, fs_info);
 
+       /*
+        * commit_fs_roots() can call btrfs_save_ino_cache(), which generates
+        * new delayed refs. Must handle them or qgroup can be wrong.
+        */
+       ret = btrfs_run_delayed_refs(trans, fs_info, (unsigned long)-1);
+       if (ret) {
+               mutex_unlock(&fs_info->tree_log_mutex);
+               mutex_unlock(&fs_info->reloc_mutex);
+               goto scrub_continue;
+       }
+
+       ret = btrfs_qgroup_prepare_account_extents(trans, fs_info);
+       if (ret) {
+               mutex_unlock(&fs_info->tree_log_mutex);
+               mutex_unlock(&fs_info->reloc_mutex);
+               goto scrub_continue;
+       }
+
        /*
         * Since fs roots are all committed, we can get a quite accurate
         * new_roots. So let's do quota accounting.
        /*
         * Since fs roots are all committed, we can get a quite accurate
         * new_roots. So let's do quota accounting.
@@ -2223,7 +2232,6 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 
        switch_commit_roots(cur_trans, fs_info);
 
 
        switch_commit_roots(cur_trans, fs_info);
 
-       assert_qgroups_uptodate(trans);
        ASSERT(list_empty(&cur_trans->dirty_bgs));
        ASSERT(list_empty(&cur_trans->io_bgs));
        update_super_roots(fs_info);
        ASSERT(list_empty(&cur_trans->dirty_bgs));
        ASSERT(list_empty(&cur_trans->io_bgs));
        update_super_roots(fs_info);