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.c92
1 files changed, 46 insertions, 46 deletions
diff --git a/fs/btrfs/random-test.c b/fs/btrfs/random-test.c
index e767528bc521..a8ef0478991b 100644
--- a/fs/btrfs/random-test.c
+++ b/fs/btrfs/random-test.c
@@ -8,7 +8,7 @@
8#include "print-tree.h" 8#include "print-tree.h"
9 9
10int keep_running = 1; 10int keep_running = 1;
11struct ctree_super_block super; 11struct btrfs_super_block super;
12 12
13static int setup_key(struct radix_tree_root *root, struct btrfs_key *key, 13static int setup_key(struct radix_tree_root *root, struct btrfs_key *key,
14 int exists) 14 int exists)
@@ -36,17 +36,17 @@ again:
36 return 0; 36 return 0;
37} 37}
38 38
39static int ins_one(struct ctree_root *root, struct radix_tree_root *radix) 39static int ins_one(struct btrfs_root *root, struct radix_tree_root *radix)
40{ 40{
41 struct ctree_path path; 41 struct btrfs_path path;
42 struct btrfs_key key; 42 struct btrfs_key key;
43 int ret; 43 int ret;
44 char buf[128]; 44 char buf[128];
45 unsigned long oid; 45 unsigned long oid;
46 init_path(&path); 46 btrfs_init_path(&path);
47 ret = setup_key(radix, &key, 0); 47 ret = setup_key(radix, &key, 0);
48 sprintf(buf, "str-%Lu\n", key.objectid); 48 sprintf(buf, "str-%Lu\n", key.objectid);
49 ret = insert_item(root, &key, buf, strlen(buf)); 49 ret = btrfs_insert_item(root, &key, buf, strlen(buf));
50 if (ret) 50 if (ret)
51 goto error; 51 goto error;
52 oid = (unsigned long)key.objectid; 52 oid = (unsigned long)key.objectid;
@@ -61,18 +61,18 @@ error:
61 return -1; 61 return -1;
62} 62}
63 63
64static int insert_dup(struct ctree_root *root, struct radix_tree_root *radix) 64static int insert_dup(struct btrfs_root *root, struct radix_tree_root *radix)
65{ 65{
66 struct ctree_path path; 66 struct btrfs_path path;
67 struct btrfs_key key; 67 struct btrfs_key key;
68 int ret; 68 int ret;
69 char buf[128]; 69 char buf[128];
70 init_path(&path); 70 btrfs_init_path(&path);
71 ret = setup_key(radix, &key, 1); 71 ret = setup_key(radix, &key, 1);
72 if (ret < 0) 72 if (ret < 0)
73 return 0; 73 return 0;
74 sprintf(buf, "str-%Lu\n", key.objectid); 74 sprintf(buf, "str-%Lu\n", key.objectid);
75 ret = insert_item(root, &key, buf, strlen(buf)); 75 ret = btrfs_insert_item(root, &key, buf, strlen(buf));
76 if (ret != -EEXIST) { 76 if (ret != -EEXIST) {
77 printf("insert on %Lu gave us %d\n", key.objectid, ret); 77 printf("insert on %Lu gave us %d\n", key.objectid, ret);
78 return 1; 78 return 1;
@@ -80,21 +80,21 @@ static int insert_dup(struct ctree_root *root, struct radix_tree_root *radix)
80 return 0; 80 return 0;
81} 81}
82 82
83static int del_one(struct ctree_root *root, struct radix_tree_root *radix) 83static int del_one(struct btrfs_root *root, struct radix_tree_root *radix)
84{ 84{
85 struct ctree_path path; 85 struct btrfs_path path;
86 struct btrfs_key key; 86 struct btrfs_key key;
87 int ret; 87 int ret;
88 unsigned long *ptr; 88 unsigned long *ptr;
89 init_path(&path); 89 btrfs_init_path(&path);
90 ret = setup_key(radix, &key, 1); 90 ret = setup_key(radix, &key, 1);
91 if (ret < 0) 91 if (ret < 0)
92 return 0; 92 return 0;
93 ret = search_slot(root, &key, &path, -1, 1); 93 ret = btrfs_search_slot(root, &key, &path, -1, 1);
94 if (ret) 94 if (ret)
95 goto error; 95 goto error;
96 ret = del_item(root, &path); 96 ret = btrfs_del_item(root, &path);
97 release_path(root, &path); 97 btrfs_release_path(root, &path);
98 if (ret != 0) 98 if (ret != 0)
99 goto error; 99 goto error;
100 ptr = radix_tree_delete(radix, key.objectid); 100 ptr = radix_tree_delete(radix, key.objectid);
@@ -106,17 +106,17 @@ error:
106 return -1; 106 return -1;
107} 107}
108 108
109static int lookup_item(struct ctree_root *root, struct radix_tree_root *radix) 109static int lookup_item(struct btrfs_root *root, struct radix_tree_root *radix)
110{ 110{
111 struct ctree_path path; 111 struct btrfs_path path;
112 struct btrfs_key key; 112 struct btrfs_key key;
113 int ret; 113 int ret;
114 init_path(&path); 114 btrfs_init_path(&path);
115 ret = setup_key(radix, &key, 1); 115 ret = setup_key(radix, &key, 1);
116 if (ret < 0) 116 if (ret < 0)
117 return 0; 117 return 0;
118 ret = search_slot(root, &key, &path, 0, 1); 118 ret = btrfs_search_slot(root, &key, &path, 0, 1);
119 release_path(root, &path); 119 btrfs_release_path(root, &path);
120 if (ret) 120 if (ret)
121 goto error; 121 goto error;
122 return 0; 122 return 0;
@@ -125,17 +125,17 @@ error:
125 return -1; 125 return -1;
126} 126}
127 127
128static int lookup_enoent(struct ctree_root *root, struct radix_tree_root *radix) 128static int lookup_enoent(struct btrfs_root *root, struct radix_tree_root *radix)
129{ 129{
130 struct ctree_path path; 130 struct btrfs_path path;
131 struct btrfs_key key; 131 struct btrfs_key key;
132 int ret; 132 int ret;
133 init_path(&path); 133 btrfs_init_path(&path);
134 ret = setup_key(radix, &key, 0); 134 ret = setup_key(radix, &key, 0);
135 if (ret < 0) 135 if (ret < 0)
136 return ret; 136 return ret;
137 ret = search_slot(root, &key, &path, 0, 0); 137 ret = btrfs_search_slot(root, &key, &path, 0, 0);
138 release_path(root, &path); 138 btrfs_release_path(root, &path);
139 if (ret <= 0) 139 if (ret <= 0)
140 goto error; 140 goto error;
141 return 0; 141 return 0;
@@ -144,10 +144,10 @@ error:
144 return -1; 144 return -1;
145} 145}
146 146
147static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix, 147static int empty_tree(struct btrfs_root *root, struct radix_tree_root *radix,
148 int nr) 148 int nr)
149{ 149{
150 struct ctree_path path; 150 struct btrfs_path path;
151 struct btrfs_key key; 151 struct btrfs_key key;
152 unsigned long found = 0; 152 unsigned long found = 0;
153 int ret; 153 int ret;
@@ -159,22 +159,22 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix,
159 key.flags = 0; 159 key.flags = 0;
160 key.objectid = (unsigned long)-1; 160 key.objectid = (unsigned long)-1;
161 while(nr-- >= 0) { 161 while(nr-- >= 0) {
162 init_path(&path); 162 btrfs_init_path(&path);
163 ret = search_slot(root, &key, &path, -1, 1); 163 ret = btrfs_search_slot(root, &key, &path, -1, 1);
164 if (ret < 0) { 164 if (ret < 0) {
165 release_path(root, &path); 165 btrfs_release_path(root, &path);
166 return ret; 166 return ret;
167 } 167 }
168 if (ret != 0) { 168 if (ret != 0) {
169 if (path.slots[0] == 0) { 169 if (path.slots[0] == 0) {
170 release_path(root, &path); 170 btrfs_release_path(root, &path);
171 break; 171 break;
172 } 172 }
173 path.slots[0] -= 1; 173 path.slots[0] -= 1;
174 } 174 }
175 slot = path.slots[0]; 175 slot = path.slots[0];
176 found=btrfs_key_objectid(&path.nodes[0]->leaf.items[slot].key); 176 found=btrfs_key_objectid(&path.nodes[0]->leaf.items[slot].key);
177 ret = del_item(root, &path); 177 ret = btrfs_del_item(root, &path);
178 count++; 178 count++;
179 if (ret) { 179 if (ret) {
180 fprintf(stderr, 180 fprintf(stderr,
@@ -182,7 +182,7 @@ static int empty_tree(struct ctree_root *root, struct radix_tree_root *radix,
182 found); 182 found);
183 return -1; 183 return -1;
184 } 184 }
185 release_path(root, &path); 185 btrfs_release_path(root, &path);
186 ptr = radix_tree_delete(radix, found); 186 ptr = radix_tree_delete(radix, found);
187 if (!ptr) 187 if (!ptr)
188 goto error; 188 goto error;
@@ -195,7 +195,7 @@ error:
195 return -1; 195 return -1;
196} 196}
197 197
198static int fill_tree(struct ctree_root *root, struct radix_tree_root *radix, 198static int fill_tree(struct btrfs_root *root, struct radix_tree_root *radix,
199 int count) 199 int count)
200{ 200{
201 int i; 201 int i;
@@ -207,7 +207,7 @@ static int fill_tree(struct ctree_root *root, struct radix_tree_root *radix,
207 goto out; 207 goto out;
208 } 208 }
209 if (i % 1000 == 0) { 209 if (i % 1000 == 0) {
210 ret = commit_transaction(root, &super); 210 ret = btrfs_commit_transaction(root, &super);
211 if (ret) { 211 if (ret) {
212 fprintf(stderr, "fill commit failed\n"); 212 fprintf(stderr, "fill commit failed\n");
213 return ret; 213 return ret;
@@ -223,7 +223,7 @@ out:
223 return ret; 223 return ret;
224} 224}
225 225
226static int bulk_op(struct ctree_root *root, struct radix_tree_root *radix) 226static int bulk_op(struct btrfs_root *root, struct radix_tree_root *radix)
227{ 227{
228 int ret; 228 int ret;
229 int nr = rand() % 5000; 229 int nr = rand() % 5000;
@@ -242,13 +242,13 @@ static int bulk_op(struct ctree_root *root, struct radix_tree_root *radix)
242} 242}
243 243
244 244
245int (*ops[])(struct ctree_root *root, struct radix_tree_root *radix) = 245int (*ops[])(struct btrfs_root *root, struct radix_tree_root *radix) =
246 { ins_one, insert_dup, del_one, lookup_item, 246 { ins_one, insert_dup, del_one, lookup_item,
247 lookup_enoent, bulk_op }; 247 lookup_enoent, bulk_op };
248 248
249static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix) 249static int fill_radix(struct btrfs_root *root, struct radix_tree_root *radix)
250{ 250{
251 struct ctree_path path; 251 struct btrfs_path path;
252 struct btrfs_key key; 252 struct btrfs_key key;
253 unsigned long found; 253 unsigned long found;
254 int ret; 254 int ret;
@@ -259,16 +259,16 @@ static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix)
259 key.flags = 0; 259 key.flags = 0;
260 key.objectid = (unsigned long)-1; 260 key.objectid = (unsigned long)-1;
261 while(1) { 261 while(1) {
262 init_path(&path); 262 btrfs_init_path(&path);
263 ret = search_slot(root, &key, &path, 0, 0); 263 ret = btrfs_search_slot(root, &key, &path, 0, 0);
264 if (ret < 0) { 264 if (ret < 0) {
265 release_path(root, &path); 265 btrfs_release_path(root, &path);
266 return ret; 266 return ret;
267 } 267 }
268 slot = path.slots[0]; 268 slot = path.slots[0];
269 if (ret != 0) { 269 if (ret != 0) {
270 if (slot == 0) { 270 if (slot == 0) {
271 release_path(root, &path); 271 btrfs_release_path(root, &path);
272 break; 272 break;
273 } 273 }
274 slot -= 1; 274 slot -= 1;
@@ -287,7 +287,7 @@ static int fill_radix(struct ctree_root *root, struct radix_tree_root *radix)
287 287
288 radix_tree_preload_end(); 288 radix_tree_preload_end();
289 } 289 }
290 release_path(root, &path); 290 btrfs_release_path(root, &path);
291 key.objectid = found - 1; 291 key.objectid = found - 1;
292 if (key.objectid > found) 292 if (key.objectid > found)
293 break; 293 break;
@@ -312,7 +312,7 @@ int print_usage(void)
312int main(int ac, char **av) 312int main(int ac, char **av)
313{ 313{
314 RADIX_TREE(radix, GFP_KERNEL); 314 RADIX_TREE(radix, GFP_KERNEL);
315 struct ctree_root *root; 315 struct btrfs_root *root;
316 int i; 316 int i;
317 int ret; 317 int ret;
318 int count; 318 int count;
@@ -370,7 +370,7 @@ int main(int ac, char **av)
370 if (ret) { 370 if (ret) {
371 fprintf(stderr, "op %d failed %d:%d\n", 371 fprintf(stderr, "op %d failed %d:%d\n",
372 op, i, iterations); 372 op, i, iterations);
373 print_tree(root, root->node); 373 btrfs_print_tree(root, root->node);
374 fprintf(stderr, "op %d failed %d:%d\n", 374 fprintf(stderr, "op %d failed %d:%d\n",
375 op, i, iterations); 375 op, i, iterations);
376 err = ret; 376 err = ret;