btrfs: Fix possible off-by-one in btrfs_search_path_in_tree
[pandora-kernel.git] / fs / btrfs / transaction.c
index 6a0574e..292e847 100644 (file)
@@ -460,7 +460,8 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
        struct btrfs_fs_info *info = root->fs_info;
        int count = 0;
 
-       if (--trans->use_count) {
+       if (trans->use_count > 1) {
+               trans->use_count--;
                trans->block_rsv = trans->orig_rsv;
                return 0;
        }
@@ -494,17 +495,10 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
        }
 
        if (lock && cur_trans->blocked && !cur_trans->in_commit) {
-               if (throttle) {
-                       /*
-                        * We may race with somebody else here so end up having
-                        * to call end_transaction on ourselves again, so inc
-                        * our use_count.
-                        */
-                       trans->use_count++;
+               if (throttle)
                        return btrfs_commit_transaction(trans, root);
-               } else {
+               else
                        wake_up_process(info->transaction_kthread);
-               }
        }
 
        WARN_ON(cur_trans != info->running_transaction);
@@ -785,6 +779,10 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans,
 
                        btrfs_save_ino_cache(root, trans);
 
+                       /* see comments in should_cow_block() */
+                       root->force_cow = 0;
+                       smp_wmb();
+
                        if (root->commit_root != root->node) {
                                mutex_lock(&root->fs_commit_mutex);
                                switch_commit_root(root);
@@ -947,6 +945,10 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
        btrfs_tree_unlock(old);
        free_extent_buffer(old);
 
+       /* see comments in should_cow_block() */
+       root->force_cow = 1;
+       smp_wmb();
+
        btrfs_set_root_node(new_root_item, tmp);
        /* record when the snapshot was created in key.offset */
        key.offset = trans->transid;