aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/random-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/random-test.c')
-rw-r--r--fs/btrfs/random-test.c62
1 files changed, 36 insertions, 26 deletions
diff --git a/fs/btrfs/random-test.c b/fs/btrfs/random-test.c
index f05135f13f9a..3a38ae7a886d 100644
--- a/fs/btrfs/random-test.c
+++ b/fs/btrfs/random-test.c
@@ -6,6 +6,7 @@
6#include "ctree.h" 6#include "ctree.h"
7#include "disk-io.h" 7#include "disk-io.h"
8#include "print-tree.h" 8#include "print-tree.h"
9#include "transaction.h"
9 10
10int keep_running = 1; 11int keep_running = 1;
11struct btrfs_super_block super; 12struct btrfs_super_block super;
@@ -37,7 +38,8 @@ again:
37 return 0; 38 return 0;
38} 39}
39 40
40static int ins_one(struct btrfs_root *root, struct radix_tree_root *radix) 41static int ins_one(struct btrfs_trans_handle *trans, struct btrfs_root *root,
42 struct radix_tree_root *radix)
41{ 43{
42 struct btrfs_path path; 44 struct btrfs_path path;
43 struct btrfs_key key; 45 struct btrfs_key key;
@@ -47,7 +49,7 @@ static int ins_one(struct btrfs_root *root, struct radix_tree_root *radix)
47 btrfs_init_path(&path); 49 btrfs_init_path(&path);
48 ret = setup_key(radix, &key, 0); 50 ret = setup_key(radix, &key, 0);
49 sprintf(buf, "str-%Lu\n", key.objectid); 51 sprintf(buf, "str-%Lu\n", key.objectid);
50 ret = btrfs_insert_item(root, &key, buf, strlen(buf)); 52 ret = btrfs_insert_item(trans, root, &key, buf, strlen(buf));
51 if (ret) 53 if (ret)
52 goto error; 54 goto error;
53 oid = (unsigned long)key.objectid; 55 oid = (unsigned long)key.objectid;
@@ -62,7 +64,8 @@ error:
62 return -1; 64 return -1;
63} 65}
64 66
65static int insert_dup(struct btrfs_root *root, struct radix_tree_root *radix) 67static int insert_dup(struct btrfs_trans_handle *trans, struct btrfs_root
68 *root, struct radix_tree_root *radix)
66{ 69{
67 struct btrfs_path path; 70 struct btrfs_path path;
68 struct btrfs_key key; 71 struct btrfs_key key;
@@ -73,7 +76,7 @@ static int insert_dup(struct btrfs_root *root, struct radix_tree_root *radix)
73 if (ret < 0) 76 if (ret < 0)
74 return 0; 77 return 0;
75 sprintf(buf, "str-%Lu\n", key.objectid); 78 sprintf(buf, "str-%Lu\n", key.objectid);
76 ret = btrfs_insert_item(root, &key, buf, strlen(buf)); 79 ret = btrfs_insert_item(trans, root, &key, buf, strlen(buf));
77 if (ret != -EEXIST) { 80 if (ret != -EEXIST) {
78 printf("insert on %Lu gave us %d\n", key.objectid, ret); 81 printf("insert on %Lu gave us %d\n", key.objectid, ret);
79 return 1; 82 return 1;
@@ -81,7 +84,8 @@ static int insert_dup(struct btrfs_root *root, struct radix_tree_root *radix)
81 return 0; 84 return 0;
82} 85}
83 86
84static int del_one(struct btrfs_root *root, struct radix_tree_root *radix) 87static int del_one(struct btrfs_trans_handle *trans, struct btrfs_root *root,
88 struct radix_tree_root *radix)
85{ 89{
86 struct btrfs_path path; 90 struct btrfs_path path;
87 struct btrfs_key key; 91 struct btrfs_key key;
@@ -91,10 +95,10 @@ static int del_one(struct btrfs_root *root, struct radix_tree_root *radix)
91 ret = setup_key(radix, &key, 1); 95 ret = setup_key(radix, &key, 1);
92 if (ret < 0) 96 if (ret < 0)
93 return 0; 97 return 0;
94 ret = btrfs_search_slot(root, &key, &path, -1, 1); 98 ret = btrfs_search_slot(trans, root, &key, &path, -1, 1);
95 if (ret) 99 if (ret)
96 goto error; 100 goto error;
97 ret = btrfs_del_item(root, &path); 101 ret = btrfs_del_item(trans, root, &path);
98 btrfs_release_path(root, &path); 102 btrfs_release_path(root, &path);
99 if (ret != 0) 103 if (ret != 0)
100 goto error; 104 goto error;
@@ -107,7 +111,8 @@ error:
107 return -1; 111 return -1;
108} 112}
109 113
110static int lookup_item(struct btrfs_root *root, struct radix_tree_root *radix) 114static int lookup_item(struct btrfs_trans_handle *trans, struct btrfs_root
115 *root, struct radix_tree_root *radix)
111{ 116{
112 struct btrfs_path path; 117 struct btrfs_path path;
113 struct btrfs_key key; 118 struct btrfs_key key;
@@ -116,7 +121,7 @@ static int lookup_item(struct btrfs_root *root, struct radix_tree_root *radix)
116 ret = setup_key(radix, &key, 1); 121 ret = setup_key(radix, &key, 1);
117 if (ret < 0) 122 if (ret < 0)
118 return 0; 123 return 0;
119 ret = btrfs_search_slot(root, &key, &path, 0, 1); 124 ret = btrfs_search_slot(trans, root, &key, &path, 0, 1);
120 btrfs_release_path(root, &path); 125 btrfs_release_path(root, &path);
121 if (ret) 126 if (ret)
122 goto error; 127 goto error;
@@ -126,7 +131,8 @@ error:
126 return -1; 131 return -1;
127} 132}
128 133
129static int lookup_enoent(struct btrfs_root *root, struct radix_tree_root *radix) 134static int lookup_enoent(struct btrfs_trans_handle *trans, struct btrfs_root
135 *root, struct radix_tree_root *radix)
130{ 136{
131 struct btrfs_path path; 137 struct btrfs_path path;
132 struct btrfs_key key; 138 struct btrfs_key key;
@@ -135,7 +141,7 @@ static int lookup_enoent(struct btrfs_root *root, struct radix_tree_root *radix)
135 ret = setup_key(radix, &key, 0); 141 ret = setup_key(radix, &key, 0);
136 if (ret < 0) 142 if (ret < 0)
137 return ret; 143 return ret;
138 ret = btrfs_search_slot(root, &key, &path, 0, 0); 144 ret = btrfs_search_slot(trans, root, &key, &path, 0, 0);
139 btrfs_release_path(root, &path); 145 btrfs_release_path(root, &path);
140 if (ret <= 0) 146 if (ret <= 0)
141 goto error; 147 goto error;
@@ -145,8 +151,8 @@ error:
145 return -1; 151 return -1;
146} 152}
147 153
148static int empty_tree(struct btrfs_root *root, struct radix_tree_root *radix, 154static int empty_tree(struct btrfs_trans_handle *trans, struct btrfs_root
149 int nr) 155 *root, struct radix_tree_root *radix, int nr)
150{ 156{
151 struct btrfs_path path; 157 struct btrfs_path path;
152 struct btrfs_key key; 158 struct btrfs_key key;
@@ -162,7 +168,7 @@ static int empty_tree(struct btrfs_root *root, struct radix_tree_root *radix,
162 key.objectid = (unsigned long)-1; 168 key.objectid = (unsigned long)-1;
163 while(nr-- >= 0) { 169 while(nr-- >= 0) {
164 btrfs_init_path(&path); 170 btrfs_init_path(&path);
165 ret = btrfs_search_slot(root, &key, &path, -1, 1); 171 ret = btrfs_search_slot(trans, root, &key, &path, -1, 1);
166 if (ret < 0) { 172 if (ret < 0) {
167 btrfs_release_path(root, &path); 173 btrfs_release_path(root, &path);
168 return ret; 174 return ret;
@@ -177,7 +183,7 @@ static int empty_tree(struct btrfs_root *root, struct radix_tree_root *radix,
177 slot = path.slots[0]; 183 slot = path.slots[0];
178 found = btrfs_disk_key_objectid( 184 found = btrfs_disk_key_objectid(
179 &path.nodes[0]->leaf.items[slot].key); 185 &path.nodes[0]->leaf.items[slot].key);
180 ret = btrfs_del_item(root, &path); 186 ret = btrfs_del_item(trans, root, &path);
181 count++; 187 count++;
182 if (ret) { 188 if (ret) {
183 fprintf(stderr, 189 fprintf(stderr,
@@ -198,19 +204,19 @@ error:
198 return -1; 204 return -1;
199} 205}
200 206
201static int fill_tree(struct btrfs_root *root, struct radix_tree_root *radix, 207static int fill_tree(struct btrfs_trans_handle *trans, struct btrfs_root *root,
202 int count) 208 struct radix_tree_root *radix, int count)
203{ 209{
204 int i; 210 int i;
205 int ret = 0; 211 int ret = 0;
206 for (i = 0; i < count; i++) { 212 for (i = 0; i < count; i++) {
207 ret = ins_one(root, radix); 213 ret = ins_one(trans, root, radix);
208 if (ret) { 214 if (ret) {
209 fprintf(stderr, "fill failed\n"); 215 fprintf(stderr, "fill failed\n");
210 goto out; 216 goto out;
211 } 217 }
212 if (i % 1000 == 0) { 218 if (i % 1000 == 0) {
213 ret = btrfs_commit_transaction(root, &super); 219 ret = btrfs_commit_transaction(trans, root, &super);
214 if (ret) { 220 if (ret) {
215 fprintf(stderr, "fill commit failed\n"); 221 fprintf(stderr, "fill commit failed\n");
216 return ret; 222 return ret;
@@ -226,7 +232,8 @@ out:
226 return ret; 232 return ret;
227} 233}
228 234
229static int bulk_op(struct btrfs_root *root, struct radix_tree_root *radix) 235static int bulk_op(struct btrfs_trans_handle *trans, struct btrfs_root *root,
236 struct radix_tree_root *radix)
230{ 237{
231 int ret; 238 int ret;
232 int nr = rand() % 5000; 239 int nr = rand() % 5000;
@@ -235,17 +242,18 @@ static int bulk_op(struct btrfs_root *root, struct radix_tree_root *radix)
235 /* do the bulk op much less frequently */ 242 /* do the bulk op much less frequently */
236 if (run_nr++ % 100) 243 if (run_nr++ % 100)
237 return 0; 244 return 0;
238 ret = empty_tree(root, radix, nr); 245 ret = empty_tree(trans, root, radix, nr);
239 if (ret) 246 if (ret)
240 return ret; 247 return ret;
241 ret = fill_tree(root, radix, nr); 248 ret = fill_tree(trans, root, radix, nr);
242 if (ret) 249 if (ret)
243 return ret; 250 return ret;
244 return 0; 251 return 0;
245} 252}
246 253
247 254
248int (*ops[])(struct btrfs_root *root, struct radix_tree_root *radix) = 255int (*ops[])(struct btrfs_trans_handle *,
256 struct btrfs_root *root, struct radix_tree_root *radix) =
249 { ins_one, insert_dup, del_one, lookup_item, 257 { ins_one, insert_dup, del_one, lookup_item,
250 lookup_enoent, bulk_op }; 258 lookup_enoent, bulk_op };
251 259
@@ -264,7 +272,7 @@ static int fill_radix(struct btrfs_root *root, struct radix_tree_root *radix)
264 key.objectid = (unsigned long)-1; 272 key.objectid = (unsigned long)-1;
265 while(1) { 273 while(1) {
266 btrfs_init_path(&path); 274 btrfs_init_path(&path);
267 ret = btrfs_search_slot(root, &key, &path, 0, 0); 275 ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
268 if (ret < 0) { 276 if (ret < 0) {
269 btrfs_release_path(root, &path); 277 btrfs_release_path(root, &path);
270 return ret; 278 return ret;
@@ -325,6 +333,7 @@ int main(int ac, char **av)
325 int init_fill_count = 800000; 333 int init_fill_count = 800000;
326 int err = 0; 334 int err = 0;
327 int initial_only = 0; 335 int initial_only = 0;
336 struct btrfs_trans_handle *trans;
328 radix_tree_init(); 337 radix_tree_init();
329 root = open_ctree("dbfile", &super); 338 root = open_ctree("dbfile", &super);
330 fill_radix(root, &radix); 339 fill_radix(root, &radix);
@@ -346,7 +355,8 @@ int main(int ac, char **av)
346 } 355 }
347 } 356 }
348 printf("initial fill\n"); 357 printf("initial fill\n");
349 ret = fill_tree(root, &radix, init_fill_count); 358 trans = btrfs_start_transaction(root, 1);
359 ret = fill_tree(trans, root, &radix, init_fill_count);
350 printf("starting run\n"); 360 printf("starting run\n");
351 if (ret) { 361 if (ret) {
352 err = ret; 362 err = ret;
@@ -370,7 +380,7 @@ int main(int ac, char **av)
370 root = open_ctree("dbfile", &super); 380 root = open_ctree("dbfile", &super);
371 } 381 }
372 while(count--) { 382 while(count--) {
373 ret = ops[op](root, &radix); 383 ret = ops[op](trans, root, &radix);
374 if (ret) { 384 if (ret) {
375 fprintf(stderr, "op %d failed %d:%d\n", 385 fprintf(stderr, "op %d failed %d:%d\n",
376 op, i, iterations); 386 op, i, iterations);