Btrfs: Fixup reference counting on cows

Signed-off-by: Chris Mason <chris.mason@oracle.com>
diff --git a/fs/btrfs/random-test.c b/fs/btrfs/random-test.c
index dcc852a..7b37b6b 100644
--- a/fs/btrfs/random-test.c
+++ b/fs/btrfs/random-test.c
@@ -8,6 +8,7 @@
 #include "print-tree.h"
 
 int keep_running = 1;
+struct ctree_super_block super;
 
 static int setup_key(struct radix_tree_root *root, struct key *key, int exists)
 {
@@ -59,11 +60,6 @@
 	return -1;
 }
 
-static int run_commit(struct ctree_root *root, struct radix_tree_root *radix)
-{
-	return commit_transaction(root);
-}
-
 static int insert_dup(struct ctree_root *root, struct radix_tree_root *radix)
 {
 	struct ctree_path path;
@@ -210,7 +206,7 @@
 			goto out;
 		}
 		if (i % 1000 == 0) {
-			ret = commit_transaction(root);
+			ret = commit_transaction(root, &super);
 			if (ret) {
 				fprintf(stderr, "fill commit failed\n");
 				return ret;
@@ -229,7 +225,7 @@
 static int bulk_op(struct ctree_root *root, struct radix_tree_root *radix)
 {
 	int ret;
-	int nr = rand() % 20000;
+	int nr = rand() % 5000;
 	static int run_nr = 0;
 
 	/* do the bulk op much less frequently */
@@ -247,7 +243,7 @@
 
 int (*ops[])(struct ctree_root *root, struct radix_tree_root *radix) =
 	{ ins_one, insert_dup, del_one, lookup_item,
-	  lookup_enoent, bulk_op, run_commit };
+	  lookup_enoent, bulk_op };
 
 static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix)
 {
@@ -314,7 +310,6 @@
 int main(int ac, char **av)
 {
 	RADIX_TREE(radix, GFP_KERNEL);
-	struct ctree_super_block super;
 	struct ctree_root *root;
 	int i;
 	int ret;
@@ -365,8 +360,7 @@
 			printf("open & close, root level %d nritems %d\n",
 				node_level(root->node->node.header.flags),
 				root->node->node.header.nritems);
-			write_ctree_super(root, &super);
-			close_ctree(root);
+			close_ctree(root, &super);
 			root = open_ctree("dbfile", &super);
 		}
 		while(count--) {
@@ -380,7 +374,7 @@
 				err = ret;
 				goto out;
 			}
-			if (ops[op] == bulk_op || ops[op] == run_commit)
+			if (ops[op] == bulk_op)
 				break;
 			if (keep_running == 0) {
 				err = 0;
@@ -389,8 +383,7 @@
 		}
 	}
 out:
-	write_ctree_super(root, &super);
-	close_ctree(root);
+	close_ctree(root, &super);
 	return err;
 }