aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/dir-test.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-03-16 16:20:31 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-03-16 16:20:31 -0400
commite089f05c18ab36ed5fa7e2319052e03ab800d518 (patch)
treef20d727233bb23fa5a37fc050cf0cc5c9d5e7b48 /fs/btrfs/dir-test.c
parent88fd146c27da0f34c512f47e2b3776a0762ecd81 (diff)
Btrfs: transaction handles everywhere
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/dir-test.c')
-rw-r--r--fs/btrfs/dir-test.c70
1 files changed, 42 insertions, 28 deletions
diff --git a/fs/btrfs/dir-test.c b/fs/btrfs/dir-test.c
index f73aa7623398..e908c0c588cc 100644
--- a/fs/btrfs/dir-test.c
+++ b/fs/btrfs/dir-test.c
@@ -8,6 +8,7 @@
8#include "disk-io.h" 8#include "disk-io.h"
9#include "print-tree.h" 9#include "print-tree.h"
10#include "hash.h" 10#include "hash.h"
11#include "transaction.h"
11 12
12int keep_running = 1; 13int keep_running = 1;
13struct btrfs_super_block super; 14struct btrfs_super_block super;
@@ -38,7 +39,8 @@ again:
38 return 0; 39 return 0;
39} 40}
40 41
41static int ins_one(struct btrfs_root *root, struct radix_tree_root *radix) 42static int ins_one(struct btrfs_trans_handle *trans, struct btrfs_root *root,
43 struct radix_tree_root *radix)
42{ 44{
43 int ret; 45 int ret;
44 char buf[128]; 46 char buf[128];
@@ -48,8 +50,8 @@ static int ins_one(struct btrfs_root *root, struct radix_tree_root *radix)
48 find_num(radix, &oid, 0); 50 find_num(radix, &oid, 0);
49 sprintf(buf, "str-%lu", oid); 51 sprintf(buf, "str-%lu", oid);
50 52
51 ret = btrfs_insert_dir_item(root, buf, strlen(buf), dir_oid, file_oid, 53 ret = btrfs_insert_dir_item(trans, root, buf, strlen(buf), dir_oid,
52 1); 54 file_oid, 1);
53 if (ret) 55 if (ret)
54 goto error; 56 goto error;
55 57
@@ -68,7 +70,8 @@ error:
68 * check 70 * check
69 */ 71 */
70 btrfs_init_path(&path); 72 btrfs_init_path(&path);
71 ret = btrfs_lookup_dir_item(root, &path, dir_oid, buf, strlen(buf), 0); 73 ret = btrfs_lookup_dir_item(trans, root, &path, dir_oid, buf,
74 strlen(buf), 0);
72 if (ret) 75 if (ret)
73 goto fatal_release; 76 goto fatal_release;
74 if (!btrfs_match_dir_item_name(root, &path, buf, strlen(buf))) { 77 if (!btrfs_match_dir_item_name(root, &path, buf, strlen(buf))) {
@@ -96,7 +99,8 @@ fatal:
96 return -1; 99 return -1;
97} 100}
98 101
99static int insert_dup(struct btrfs_root *root, struct radix_tree_root *radix) 102static int insert_dup(struct btrfs_trans_handle *trans, struct btrfs_root
103 *root, struct radix_tree_root *radix)
100{ 104{
101 int ret; 105 int ret;
102 char buf[128]; 106 char buf[128];
@@ -107,8 +111,8 @@ static int insert_dup(struct btrfs_root *root, struct radix_tree_root *radix)
107 return 0; 111 return 0;
108 sprintf(buf, "str-%lu", oid); 112 sprintf(buf, "str-%lu", oid);
109 113
110 ret = btrfs_insert_dir_item(root, buf, strlen(buf), dir_oid, file_oid, 114 ret = btrfs_insert_dir_item(trans, root, buf, strlen(buf), dir_oid,
111 1); 115 file_oid, 1);
112 if (ret != -EEXIST) { 116 if (ret != -EEXIST) {
113 printf("insert on %s gave us %d\n", buf, ret); 117 printf("insert on %s gave us %d\n", buf, ret);
114 return 1; 118 return 1;
@@ -116,7 +120,8 @@ static int insert_dup(struct btrfs_root *root, struct radix_tree_root *radix)
116 return 0; 120 return 0;
117} 121}
118 122
119static int del_one(struct btrfs_root *root, struct radix_tree_root *radix) 123static int del_one(struct btrfs_trans_handle *trans, struct btrfs_root *root,
124 struct radix_tree_root *radix)
120{ 125{
121 int ret; 126 int ret;
122 char buf[128]; 127 char buf[128];
@@ -129,10 +134,11 @@ static int del_one(struct btrfs_root *root, struct radix_tree_root *radix)
129 return 0; 134 return 0;
130 sprintf(buf, "str-%lu", oid); 135 sprintf(buf, "str-%lu", oid);
131 btrfs_init_path(&path); 136 btrfs_init_path(&path);
132 ret = btrfs_lookup_dir_item(root, &path, dir_oid, buf, strlen(buf), -1); 137 ret = btrfs_lookup_dir_item(trans, root, &path, dir_oid, buf,
138 strlen(buf), -1);
133 if (ret) 139 if (ret)
134 goto out_release; 140 goto out_release;
135 ret = btrfs_del_item(root, &path); 141 ret = btrfs_del_item(trans, root, &path);
136 if (ret) 142 if (ret)
137 goto out_release; 143 goto out_release;
138 btrfs_release_path(root, &path); 144 btrfs_release_path(root, &path);
@@ -149,7 +155,8 @@ out:
149 return -1; 155 return -1;
150} 156}
151 157
152static int lookup_item(struct btrfs_root *root, struct radix_tree_root *radix) 158static int lookup_item(struct btrfs_trans_handle *trans, struct btrfs_root
159 *root, struct radix_tree_root *radix)
153{ 160{
154 struct btrfs_path path; 161 struct btrfs_path path;
155 char buf[128]; 162 char buf[128];
@@ -161,7 +168,8 @@ static int lookup_item(struct btrfs_root *root, struct radix_tree_root *radix)
161 return 0; 168 return 0;
162 sprintf(buf, "str-%lu", oid); 169 sprintf(buf, "str-%lu", oid);
163 btrfs_init_path(&path); 170 btrfs_init_path(&path);
164 ret = btrfs_lookup_dir_item(root, &path, dir_oid, buf, strlen(buf), 0); 171 ret = btrfs_lookup_dir_item(trans, root, &path, dir_oid, buf,
172 strlen(buf), 0);
165 btrfs_release_path(root, &path); 173 btrfs_release_path(root, &path);
166 if (ret) { 174 if (ret) {
167 printf("unable to find key %lu\n", oid); 175 printf("unable to find key %lu\n", oid);
@@ -170,7 +178,8 @@ static int lookup_item(struct btrfs_root *root, struct radix_tree_root *radix)
170 return 0; 178 return 0;
171} 179}
172 180
173static int lookup_enoent(struct btrfs_root *root, struct radix_tree_root *radix) 181static int lookup_enoent(struct btrfs_trans_handle *trans, struct btrfs_root
182 *root, struct radix_tree_root *radix)
174{ 183{
175 struct btrfs_path path; 184 struct btrfs_path path;
176 char buf[128]; 185 char buf[128];
@@ -182,7 +191,8 @@ static int lookup_enoent(struct btrfs_root *root, struct radix_tree_root *radix)
182 return 0; 191 return 0;
183 sprintf(buf, "str-%lu", oid); 192 sprintf(buf, "str-%lu", oid);
184 btrfs_init_path(&path); 193 btrfs_init_path(&path);
185 ret = btrfs_lookup_dir_item(root, &path, dir_oid, buf, strlen(buf), 0); 194 ret = btrfs_lookup_dir_item(trans, root, &path, dir_oid, buf,
195 strlen(buf), 0);
186 btrfs_release_path(root, &path); 196 btrfs_release_path(root, &path);
187 if (!ret) { 197 if (!ret) {
188 printf("able to find key that should not exist %lu\n", oid); 198 printf("able to find key that should not exist %lu\n", oid);
@@ -191,8 +201,8 @@ static int lookup_enoent(struct btrfs_root *root, struct radix_tree_root *radix)
191 return 0; 201 return 0;
192} 202}
193 203
194static int empty_tree(struct btrfs_root *root, struct radix_tree_root *radix, 204static int empty_tree(struct btrfs_trans_handle *trans, struct btrfs_root
195 int nr) 205 *root, struct radix_tree_root *radix, int nr)
196{ 206{
197 struct btrfs_path path; 207 struct btrfs_path path;
198 struct btrfs_key key; 208 struct btrfs_key key;
@@ -211,7 +221,7 @@ static int empty_tree(struct btrfs_root *root, struct radix_tree_root *radix,
211 key.objectid = dir_oid; 221 key.objectid = dir_oid;
212 while(nr-- >= 0) { 222 while(nr-- >= 0) {
213 btrfs_init_path(&path); 223 btrfs_init_path(&path);
214 ret = btrfs_search_slot(root, &key, &path, -1, 1); 224 ret = btrfs_search_slot(trans, root, &key, &path, -1, 1);
215 if (ret < 0) { 225 if (ret < 0) {
216 btrfs_release_path(root, &path); 226 btrfs_release_path(root, &path);
217 return ret; 227 return ret;
@@ -231,7 +241,7 @@ static int empty_tree(struct btrfs_root *root, struct radix_tree_root *radix,
231 BUG_ON(found_len > 128); 241 BUG_ON(found_len > 128);
232 buf[found_len] = '\0'; 242 buf[found_len] = '\0';
233 found = atoi(buf + 4); 243 found = atoi(buf + 4);
234 ret = btrfs_del_item(root, &path); 244 ret = btrfs_del_item(trans, root, &path);
235 count++; 245 count++;
236 if (ret) { 246 if (ret) {
237 fprintf(stderr, 247 fprintf(stderr,
@@ -252,19 +262,19 @@ error:
252 return -1; 262 return -1;
253} 263}
254 264
255static int fill_tree(struct btrfs_root *root, struct radix_tree_root *radix, 265static int fill_tree(struct btrfs_trans_handle *trans, struct btrfs_root *root,
256 int count) 266 struct radix_tree_root *radix, int count)
257{ 267{
258 int i; 268 int i;
259 int ret = 0; 269 int ret = 0;
260 for (i = 0; i < count; i++) { 270 for (i = 0; i < count; i++) {
261 ret = ins_one(root, radix); 271 ret = ins_one(trans, root, radix);
262 if (ret) { 272 if (ret) {
263 fprintf(stderr, "fill failed\n"); 273 fprintf(stderr, "fill failed\n");
264 goto out; 274 goto out;
265 } 275 }
266 if (i % 1000 == 0) { 276 if (i % 1000 == 0) {
267 ret = btrfs_commit_transaction(root, &super); 277 ret = btrfs_commit_transaction(trans, root, &super);
268 if (ret) { 278 if (ret) {
269 fprintf(stderr, "fill commit failed\n"); 279 fprintf(stderr, "fill commit failed\n");
270 return ret; 280 return ret;
@@ -280,7 +290,8 @@ out:
280 return ret; 290 return ret;
281} 291}
282 292
283static int bulk_op(struct btrfs_root *root, struct radix_tree_root *radix) 293static int bulk_op(struct btrfs_trans_handle *trans, struct btrfs_root *root,
294 struct radix_tree_root *radix)
284{ 295{
285 int ret; 296 int ret;
286 int nr = rand() % 5000; 297 int nr = rand() % 5000;
@@ -289,17 +300,18 @@ static int bulk_op(struct btrfs_root *root, struct radix_tree_root *radix)
289 /* do the bulk op much less frequently */ 300 /* do the bulk op much less frequently */
290 if (run_nr++ % 100) 301 if (run_nr++ % 100)
291 return 0; 302 return 0;
292 ret = empty_tree(root, radix, nr); 303 ret = empty_tree(trans, root, radix, nr);
293 if (ret) 304 if (ret)
294 return ret; 305 return ret;
295 ret = fill_tree(root, radix, nr); 306 ret = fill_tree(trans, root, radix, nr);
296 if (ret) 307 if (ret)
297 return ret; 308 return ret;
298 return 0; 309 return 0;
299} 310}
300 311
301 312
302int (*ops[])(struct btrfs_root *root, struct radix_tree_root *radix) = 313int (*ops[])(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct
314 radix_tree_root *radix) =
303 { ins_one, insert_dup, del_one, lookup_item, 315 { ins_one, insert_dup, del_one, lookup_item,
304 lookup_enoent, bulk_op }; 316 lookup_enoent, bulk_op };
305 317
@@ -330,11 +342,13 @@ int main(int ac, char **av)
330 int init_fill_count = 800000; 342 int init_fill_count = 800000;
331 int err = 0; 343 int err = 0;
332 int initial_only = 0; 344 int initial_only = 0;
345 struct btrfs_trans_handle *trans;
333 radix_tree_init(); 346 radix_tree_init();
334 347
335 printf("removing old tree\n"); 348 printf("removing old tree\n");
336 unlink("dbfile"); 349 unlink("dbfile");
337 root = open_ctree("dbfile", &super); 350 root = open_ctree("dbfile", &super);
351 trans = btrfs_start_transaction(root, 1);
338 352
339 signal(SIGTERM, sigstopper); 353 signal(SIGTERM, sigstopper);
340 signal(SIGINT, sigstopper); 354 signal(SIGINT, sigstopper);
@@ -353,7 +367,7 @@ int main(int ac, char **av)
353 } 367 }
354 } 368 }
355 printf("initial fill\n"); 369 printf("initial fill\n");
356 ret = fill_tree(root, &radix, init_fill_count); 370 ret = fill_tree(trans, root, &radix, init_fill_count);
357 printf("starting run\n"); 371 printf("starting run\n");
358 if (ret) { 372 if (ret) {
359 err = ret; 373 err = ret;
@@ -377,7 +391,7 @@ int main(int ac, char **av)
377 root = open_ctree("dbfile", &super); 391 root = open_ctree("dbfile", &super);
378 } 392 }
379 while(count--) { 393 while(count--) {
380 ret = ops[op](root, &radix); 394 ret = ops[op](trans, root, &radix);
381 if (ret) { 395 if (ret) {
382 fprintf(stderr, "op %d failed %d:%d\n", 396 fprintf(stderr, "op %d failed %d:%d\n",
383 op, i, iterations); 397 op, i, iterations);