aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-03-13 10:46:10 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-03-13 10:46:10 -0400
commit234b63a091e1df6bd4261dd7b3a7490074830628 (patch)
tree1947f6e49aa3c19017c948205378c5cb76a7b536 /fs
parentcf27e1eec063fa68a89c57ae0a83f93aa38851d6 (diff)
rename funcs and structs to btrfs
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/ctree.c317
-rw-r--r--fs/btrfs/ctree.h95
-rw-r--r--fs/btrfs/debug-tree.c8
-rw-r--r--fs/btrfs/disk-io.c106
-rw-r--r--fs/btrfs/disk-io.h29
-rw-r--r--fs/btrfs/extent-tree.c147
-rw-r--r--fs/btrfs/mkfs.c26
-rw-r--r--fs/btrfs/print-tree.c23
-rw-r--r--fs/btrfs/print-tree.h4
-rw-r--r--fs/btrfs/quick-test.c54
-rw-r--r--fs/btrfs/random-test.c92
11 files changed, 454 insertions, 447 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 76281073100..c8529b394d5 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -6,47 +6,47 @@
6#include "disk-io.h" 6#include "disk-io.h"
7#include "print-tree.h" 7#include "print-tree.h"
8 8
9static int split_node(struct ctree_root *root, struct ctree_path *path, 9static int split_node(struct btrfs_root *root, struct btrfs_path *path,
10 int level); 10 int level);
11static int split_leaf(struct ctree_root *root, struct ctree_path *path, 11static int split_leaf(struct btrfs_root *root, struct btrfs_path *path,
12 int data_size); 12 int data_size);
13static int push_node_left(struct ctree_root *root, struct tree_buffer *dst, 13static int push_node_left(struct btrfs_root *root, struct btrfs_buffer *dst,
14 struct tree_buffer *src); 14 struct btrfs_buffer *src);
15static int balance_node_right(struct ctree_root *root, 15static int balance_node_right(struct btrfs_root *root,
16 struct tree_buffer *dst_buf, 16 struct btrfs_buffer *dst_buf,
17 struct tree_buffer *src_buf); 17 struct btrfs_buffer *src_buf);
18static int del_ptr(struct ctree_root *root, struct ctree_path *path, int level, 18static int del_ptr(struct btrfs_root *root, struct btrfs_path *path, int level,
19 int slot); 19 int slot);
20 20
21inline void init_path(struct ctree_path *p) 21inline void btrfs_init_path(struct btrfs_path *p)
22{ 22{
23 memset(p, 0, sizeof(*p)); 23 memset(p, 0, sizeof(*p));
24} 24}
25 25
26void release_path(struct ctree_root *root, struct ctree_path *p) 26void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p)
27{ 27{
28 int i; 28 int i;
29 for (i = 0; i < MAX_LEVEL; i++) { 29 for (i = 0; i < BTRFS_MAX_LEVEL; i++) {
30 if (!p->nodes[i]) 30 if (!p->nodes[i])
31 break; 31 break;
32 tree_block_release(root, p->nodes[i]); 32 btrfs_block_release(root, p->nodes[i]);
33 } 33 }
34 memset(p, 0, sizeof(*p)); 34 memset(p, 0, sizeof(*p));
35} 35}
36 36
37int btrfs_cow_block(struct ctree_root *root, 37int btrfs_cow_block(struct btrfs_root *root,
38 struct tree_buffer *buf, 38 struct btrfs_buffer *buf,
39 struct tree_buffer *parent, 39 struct btrfs_buffer *parent,
40 int parent_slot, 40 int parent_slot,
41 struct tree_buffer **cow_ret) 41 struct btrfs_buffer **cow_ret)
42{ 42{
43 struct tree_buffer *cow; 43 struct btrfs_buffer *cow;
44 44
45 if (!list_empty(&buf->dirty)) { 45 if (!list_empty(&buf->dirty)) {
46 *cow_ret = buf; 46 *cow_ret = buf;
47 return 0; 47 return 0;
48 } 48 }
49 cow = alloc_free_block(root); 49 cow = btrfs_alloc_free_block(root);
50 memcpy(&cow->node, &buf->node, sizeof(buf->node)); 50 memcpy(&cow->node, &buf->node, sizeof(buf->node));
51 btrfs_set_header_blocknr(&cow->node.header, cow->blocknr); 51 btrfs_set_header_blocknr(&cow->node.header, cow->blocknr);
52 *cow_ret = cow; 52 *cow_ret = cow;
@@ -55,15 +55,15 @@ int btrfs_cow_block(struct ctree_root *root,
55 root->node = cow; 55 root->node = cow;
56 cow->count++; 56 cow->count++;
57 if (buf != root->commit_root) 57 if (buf != root->commit_root)
58 free_extent(root, buf->blocknr, 1); 58 btrfs_free_extent(root, buf->blocknr, 1);
59 tree_block_release(root, buf); 59 btrfs_block_release(root, buf);
60 } else { 60 } else {
61 btrfs_set_node_blockptr(&parent->node, parent_slot, 61 btrfs_set_node_blockptr(&parent->node, parent_slot,
62 cow->blocknr); 62 cow->blocknr);
63 BUG_ON(list_empty(&parent->dirty)); 63 BUG_ON(list_empty(&parent->dirty));
64 free_extent(root, buf->blocknr, 1); 64 btrfs_free_extent(root, buf->blocknr, 1);
65 } 65 }
66 tree_block_release(root, buf); 66 btrfs_block_release(root, buf);
67 return 0; 67 return 0;
68} 68}
69 69
@@ -72,7 +72,7 @@ int btrfs_cow_block(struct ctree_root *root,
72 * this returns the address of the start of the last item, 72 * this returns the address of the start of the last item,
73 * which is the stop of the leaf data stack 73 * which is the stop of the leaf data stack
74 */ 74 */
75static inline unsigned int leaf_data_end(struct leaf *leaf) 75static inline unsigned int leaf_data_end(struct btrfs_leaf *leaf)
76{ 76{
77 u32 nr = btrfs_header_nritems(&leaf->header); 77 u32 nr = btrfs_header_nritems(&leaf->header);
78 if (nr == 0) 78 if (nr == 0)
@@ -85,7 +85,7 @@ static inline unsigned int leaf_data_end(struct leaf *leaf)
85 * the start of the leaf data. IOW, how much room 85 * the start of the leaf data. IOW, how much room
86 * the leaf has left for both items and data 86 * the leaf has left for both items and data
87 */ 87 */
88int leaf_free_space(struct leaf *leaf) 88int btrfs_leaf_free_space(struct btrfs_leaf *leaf)
89{ 89{
90 int data_end = leaf_data_end(leaf); 90 int data_end = leaf_data_end(leaf);
91 int nritems = btrfs_header_nritems(&leaf->header); 91 int nritems = btrfs_header_nritems(&leaf->header);
@@ -117,11 +117,11 @@ int comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2)
117 return 0; 117 return 0;
118} 118}
119 119
120int check_node(struct ctree_path *path, int level) 120int check_node(struct btrfs_path *path, int level)
121{ 121{
122 int i; 122 int i;
123 struct node *parent = NULL; 123 struct btrfs_node *parent = NULL;
124 struct node *node = &path->nodes[level]->node; 124 struct btrfs_node *node = &path->nodes[level]->node;
125 int parent_slot; 125 int parent_slot;
126 u32 nritems = btrfs_header_nritems(&node->header); 126 u32 nritems = btrfs_header_nritems(&node->header);
127 127
@@ -146,18 +146,18 @@ int check_node(struct ctree_path *path, int level)
146 return 0; 146 return 0;
147} 147}
148 148
149int check_leaf(struct ctree_path *path, int level) 149int check_leaf(struct btrfs_path *path, int level)
150{ 150{
151 int i; 151 int i;
152 struct leaf *leaf = &path->nodes[level]->leaf; 152 struct btrfs_leaf *leaf = &path->nodes[level]->leaf;
153 struct node *parent = NULL; 153 struct btrfs_node *parent = NULL;
154 int parent_slot; 154 int parent_slot;
155 u32 nritems = btrfs_header_nritems(&leaf->header); 155 u32 nritems = btrfs_header_nritems(&leaf->header);
156 156
157 if (path->nodes[level + 1]) 157 if (path->nodes[level + 1])
158 parent = &path->nodes[level + 1]->node; 158 parent = &path->nodes[level + 1]->node;
159 parent_slot = path->slots[level + 1]; 159 parent_slot = path->slots[level + 1];
160 BUG_ON(leaf_free_space(leaf) < 0); 160 BUG_ON(btrfs_leaf_free_space(leaf) < 0);
161 161
162 if (nritems == 0) 162 if (nritems == 0)
163 return 0; 163 return 0;
@@ -186,7 +186,7 @@ int check_leaf(struct ctree_path *path, int level)
186 return 0; 186 return 0;
187} 187}
188 188
189int check_block(struct ctree_path *path, int level) 189int check_block(struct btrfs_path *path, int level)
190{ 190{
191 if (level == 0) 191 if (level == 0)
192 return check_leaf(path, level); 192 return check_leaf(path, level);
@@ -233,10 +233,10 @@ int generic_bin_search(char *p, int item_size, struct btrfs_key *key,
233 * simple bin_search frontend that does the right thing for 233 * simple bin_search frontend that does the right thing for
234 * leaves vs nodes 234 * leaves vs nodes
235 */ 235 */
236int bin_search(struct node *c, struct btrfs_key *key, int *slot) 236int bin_search(struct btrfs_node *c, struct btrfs_key *key, int *slot)
237{ 237{
238 if (btrfs_is_leaf(c)) { 238 if (btrfs_is_leaf(c)) {
239 struct leaf *l = (struct leaf *)c; 239 struct btrfs_leaf *l = (struct btrfs_leaf *)c;
240 return generic_bin_search((void *)l->items, 240 return generic_bin_search((void *)l->items,
241 sizeof(struct btrfs_item), 241 sizeof(struct btrfs_item),
242 key, btrfs_header_nritems(&c->header), 242 key, btrfs_header_nritems(&c->header),
@@ -250,11 +250,11 @@ int bin_search(struct node *c, struct btrfs_key *key, int *slot)
250 return -1; 250 return -1;
251} 251}
252 252
253struct tree_buffer *read_node_slot(struct ctree_root *root, 253struct btrfs_buffer *read_node_slot(struct btrfs_root *root,
254 struct tree_buffer *parent_buf, 254 struct btrfs_buffer *parent_buf,
255 int slot) 255 int slot)
256{ 256{
257 struct node *node = &parent_buf->node; 257 struct btrfs_node *node = &parent_buf->node;
258 if (slot < 0) 258 if (slot < 0)
259 return NULL; 259 return NULL;
260 if (slot >= btrfs_header_nritems(&node->header)) 260 if (slot >= btrfs_header_nritems(&node->header))
@@ -262,17 +262,17 @@ struct tree_buffer *read_node_slot(struct ctree_root *root,
262 return read_tree_block(root, btrfs_node_blockptr(node, slot)); 262 return read_tree_block(root, btrfs_node_blockptr(node, slot));
263} 263}
264 264
265static int balance_level(struct ctree_root *root, struct ctree_path *path, 265static int balance_level(struct btrfs_root *root, struct btrfs_path *path,
266 int level) 266 int level)
267{ 267{
268 struct tree_buffer *right_buf; 268 struct btrfs_buffer *right_buf;
269 struct tree_buffer *mid_buf; 269 struct btrfs_buffer *mid_buf;
270 struct tree_buffer *left_buf; 270 struct btrfs_buffer *left_buf;
271 struct tree_buffer *parent_buf = NULL; 271 struct btrfs_buffer *parent_buf = NULL;
272 struct node *right = NULL; 272 struct btrfs_node *right = NULL;
273 struct node *mid; 273 struct btrfs_node *mid;
274 struct node *left = NULL; 274 struct btrfs_node *left = NULL;
275 struct node *parent = NULL; 275 struct btrfs_node *parent = NULL;
276 int ret = 0; 276 int ret = 0;
277 int wret; 277 int wret;
278 int pslot; 278 int pslot;
@@ -286,12 +286,12 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
286 mid = &mid_buf->node; 286 mid = &mid_buf->node;
287 orig_ptr = btrfs_node_blockptr(mid, orig_slot); 287 orig_ptr = btrfs_node_blockptr(mid, orig_slot);
288 288
289 if (level < MAX_LEVEL - 1) 289 if (level < BTRFS_MAX_LEVEL - 1)
290 parent_buf = path->nodes[level + 1]; 290 parent_buf = path->nodes[level + 1];
291 pslot = path->slots[level + 1]; 291 pslot = path->slots[level + 1];
292 292
293 if (!parent_buf) { 293 if (!parent_buf) {
294 struct tree_buffer *child; 294 struct btrfs_buffer *child;
295 u64 blocknr = mid_buf->blocknr; 295 u64 blocknr = mid_buf->blocknr;
296 296
297 if (btrfs_header_nritems(&mid->header) != 1) 297 if (btrfs_header_nritems(&mid->header) != 1)
@@ -303,11 +303,11 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
303 root->node = child; 303 root->node = child;
304 path->nodes[level] = NULL; 304 path->nodes[level] = NULL;
305 /* once for the path */ 305 /* once for the path */
306 tree_block_release(root, mid_buf); 306 btrfs_block_release(root, mid_buf);
307 /* once for the root ptr */ 307 /* once for the root ptr */
308 tree_block_release(root, mid_buf); 308 btrfs_block_release(root, mid_buf);
309 clean_tree_block(root, mid_buf); 309 clean_tree_block(root, mid_buf);
310 return free_extent(root, blocknr, 1); 310 return btrfs_free_extent(root, blocknr, 1);
311 } 311 }
312 parent = &parent_buf->node; 312 parent = &parent_buf->node;
313 313
@@ -340,14 +340,14 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
340 ret = wret; 340 ret = wret;
341 if (btrfs_header_nritems(&right->header) == 0) { 341 if (btrfs_header_nritems(&right->header) == 0) {
342 u64 blocknr = right_buf->blocknr; 342 u64 blocknr = right_buf->blocknr;
343 tree_block_release(root, right_buf); 343 btrfs_block_release(root, right_buf);
344 clean_tree_block(root, right_buf); 344 clean_tree_block(root, right_buf);
345 right_buf = NULL; 345 right_buf = NULL;
346 right = NULL; 346 right = NULL;
347 wret = del_ptr(root, path, level + 1, pslot + 1); 347 wret = del_ptr(root, path, level + 1, pslot + 1);
348 if (wret) 348 if (wret)
349 ret = wret; 349 ret = wret;
350 wret = free_extent(root, blocknr, 1); 350 wret = btrfs_free_extent(root, blocknr, 1);
351 if (wret) 351 if (wret)
352 ret = wret; 352 ret = wret;
353 } else { 353 } else {
@@ -375,14 +375,14 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
375 if (btrfs_header_nritems(&mid->header) == 0) { 375 if (btrfs_header_nritems(&mid->header) == 0) {
376 /* we've managed to empty the middle node, drop it */ 376 /* we've managed to empty the middle node, drop it */
377 u64 blocknr = mid_buf->blocknr; 377 u64 blocknr = mid_buf->blocknr;
378 tree_block_release(root, mid_buf); 378 btrfs_block_release(root, mid_buf);
379 clean_tree_block(root, mid_buf); 379 clean_tree_block(root, mid_buf);
380 mid_buf = NULL; 380 mid_buf = NULL;
381 mid = NULL; 381 mid = NULL;
382 wret = del_ptr(root, path, level + 1, pslot); 382 wret = del_ptr(root, path, level + 1, pslot);
383 if (wret) 383 if (wret)
384 ret = wret; 384 ret = wret;
385 wret = free_extent(root, blocknr, 1); 385 wret = btrfs_free_extent(root, blocknr, 1);
386 if (wret) 386 if (wret)
387 ret = wret; 387 ret = wret;
388 } else { 388 } else {
@@ -400,7 +400,7 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
400 path->slots[level + 1] -= 1; 400 path->slots[level + 1] -= 1;
401 path->slots[level] = orig_slot; 401 path->slots[level] = orig_slot;
402 if (mid_buf) 402 if (mid_buf)
403 tree_block_release(root, mid_buf); 403 btrfs_block_release(root, mid_buf);
404 } else { 404 } else {
405 orig_slot -= btrfs_header_nritems(&left->header); 405 orig_slot -= btrfs_header_nritems(&left->header);
406 path->slots[level] = orig_slot; 406 path->slots[level] = orig_slot;
@@ -413,9 +413,9 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
413 BUG(); 413 BUG();
414 414
415 if (right_buf) 415 if (right_buf)
416 tree_block_release(root, right_buf); 416 btrfs_block_release(root, right_buf);
417 if (left_buf) 417 if (left_buf)
418 tree_block_release(root, left_buf); 418 btrfs_block_release(root, left_buf);
419 return ret; 419 return ret;
420} 420}
421 421
@@ -432,12 +432,12 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path,
432 * tree. if ins_len < 0, nodes will be merged as we walk down the tree (if 432 * tree. if ins_len < 0, nodes will be merged as we walk down the tree (if
433 * possible) 433 * possible)
434 */ 434 */
435int search_slot(struct ctree_root *root, struct btrfs_key *key, 435int btrfs_search_slot(struct btrfs_root *root, struct btrfs_key *key,
436 struct ctree_path *p, int ins_len, int cow) 436 struct btrfs_path *p, int ins_len, int cow)
437{ 437{
438 struct tree_buffer *b; 438 struct btrfs_buffer *b;
439 struct tree_buffer *cow_buf; 439 struct btrfs_buffer *cow_buf;
440 struct node *c; 440 struct btrfs_node *c;
441 int slot; 441 int slot;
442 int ret; 442 int ret;
443 int level; 443 int level;
@@ -486,9 +486,9 @@ again:
486 } 486 }
487 b = read_tree_block(root, btrfs_node_blockptr(c, slot)); 487 b = read_tree_block(root, btrfs_node_blockptr(c, slot));
488 } else { 488 } else {
489 struct leaf *l = (struct leaf *)c; 489 struct btrfs_leaf *l = (struct btrfs_leaf *)c;
490 p->slots[level] = slot; 490 p->slots[level] = slot;
491 if (ins_len > 0 && leaf_free_space(l) < 491 if (ins_len > 0 && btrfs_leaf_free_space(l) <
492 sizeof(struct btrfs_item) + ins_len) { 492 sizeof(struct btrfs_item) + ins_len) {
493 int sret = split_leaf(root, p, ins_len); 493 int sret = split_leaf(root, p, ins_len);
494 BUG_ON(sret > 0); 494 BUG_ON(sret > 0);
@@ -513,14 +513,14 @@ again:
513 * If this fails to write a tree block, it returns -1, but continues 513 * If this fails to write a tree block, it returns -1, but continues
514 * fixing up the blocks in ram so the tree is consistent. 514 * fixing up the blocks in ram so the tree is consistent.
515 */ 515 */
516static int fixup_low_keys(struct ctree_root *root, 516static int fixup_low_keys(struct btrfs_root *root,
517 struct ctree_path *path, struct btrfs_disk_key *key, 517 struct btrfs_path *path, struct btrfs_disk_key *key,
518 int level) 518 int level)
519{ 519{
520 int i; 520 int i;
521 int ret = 0; 521 int ret = 0;
522 for (i = level; i < MAX_LEVEL; i++) { 522 for (i = level; i < BTRFS_MAX_LEVEL; i++) {
523 struct node *t; 523 struct btrfs_node *t;
524 int tslot = path->slots[i]; 524 int tslot = path->slots[i];
525 if (!path->nodes[i]) 525 if (!path->nodes[i])
526 break; 526 break;
@@ -540,11 +540,11 @@ static int fixup_low_keys(struct ctree_root *root,
540 * returns 0 if some ptrs were pushed left, < 0 if there was some horrible 540 * returns 0 if some ptrs were pushed left, < 0 if there was some horrible
541 * error, and > 0 if there was no room in the left hand block. 541 * error, and > 0 if there was no room in the left hand block.
542 */ 542 */
543static int push_node_left(struct ctree_root *root, struct tree_buffer *dst_buf, 543static int push_node_left(struct btrfs_root *root, struct btrfs_buffer *dst_buf,
544 struct tree_buffer *src_buf) 544 struct btrfs_buffer *src_buf)
545{ 545{
546 struct node *src = &src_buf->node; 546 struct btrfs_node *src = &src_buf->node;
547 struct node *dst = &dst_buf->node; 547 struct btrfs_node *dst = &dst_buf->node;
548 int push_items = 0; 548 int push_items = 0;
549 int src_nritems; 549 int src_nritems;
550 int dst_nritems; 550 int dst_nritems;
@@ -587,12 +587,12 @@ static int push_node_left(struct ctree_root *root, struct tree_buffer *dst_buf,
587 * 587 *
588 * this will only push up to 1/2 the contents of the left node over 588 * this will only push up to 1/2 the contents of the left node over
589 */ 589 */
590static int balance_node_right(struct ctree_root *root, 590static int balance_node_right(struct btrfs_root *root,
591 struct tree_buffer *dst_buf, 591 struct btrfs_buffer *dst_buf,
592 struct tree_buffer *src_buf) 592 struct btrfs_buffer *src_buf)
593{ 593{
594 struct node *src = &src_buf->node; 594 struct btrfs_node *src = &src_buf->node;
595 struct node *dst = &dst_buf->node; 595 struct btrfs_node *dst = &dst_buf->node;
596 int push_items = 0; 596 int push_items = 0;
597 int max_push; 597 int max_push;
598 int src_nritems; 598 int src_nritems;
@@ -637,18 +637,18 @@ static int balance_node_right(struct ctree_root *root,
637 * 637 *
638 * returns zero on success or < 0 on failure. 638 * returns zero on success or < 0 on failure.
639 */ 639 */
640static int insert_new_root(struct ctree_root *root, 640static int insert_new_root(struct btrfs_root *root,
641 struct ctree_path *path, int level) 641 struct btrfs_path *path, int level)
642{ 642{
643 struct tree_buffer *t; 643 struct btrfs_buffer *t;
644 struct node *lower; 644 struct btrfs_node *lower;
645 struct node *c; 645 struct btrfs_node *c;
646 struct btrfs_disk_key *lower_key; 646 struct btrfs_disk_key *lower_key;
647 647
648 BUG_ON(path->nodes[level]); 648 BUG_ON(path->nodes[level]);
649 BUG_ON(path->nodes[level-1] != root->node); 649 BUG_ON(path->nodes[level-1] != root->node);
650 650
651 t = alloc_free_block(root); 651 t = btrfs_alloc_free_block(root);
652 c = &t->node; 652 c = &t->node;
653 memset(c, 0, sizeof(c)); 653 memset(c, 0, sizeof(c));
654 btrfs_set_header_nritems(&c->header, 1); 654 btrfs_set_header_nritems(&c->header, 1);
@@ -658,13 +658,13 @@ static int insert_new_root(struct ctree_root *root,
658 btrfs_header_parentid(&root->node->node.header)); 658 btrfs_header_parentid(&root->node->node.header));
659 lower = &path->nodes[level-1]->node; 659 lower = &path->nodes[level-1]->node;
660 if (btrfs_is_leaf(lower)) 660 if (btrfs_is_leaf(lower))
661 lower_key = &((struct leaf *)lower)->items[0].key; 661 lower_key = &((struct btrfs_leaf *)lower)->items[0].key;
662 else 662 else
663 lower_key = lower->keys; 663 lower_key = lower->keys;
664 memcpy(c->keys, lower_key, sizeof(struct btrfs_disk_key)); 664 memcpy(c->keys, lower_key, sizeof(struct btrfs_disk_key));
665 btrfs_set_node_blockptr(c, 0, path->nodes[level - 1]->blocknr); 665 btrfs_set_node_blockptr(c, 0, path->nodes[level - 1]->blocknr);
666 /* the super has an extra ref to root->node */ 666 /* the super has an extra ref to root->node */
667 tree_block_release(root, root->node); 667 btrfs_block_release(root, root->node);
668 root->node = t; 668 root->node = t;
669 t->count++; 669 t->count++;
670 path->nodes[level] = t; 670 path->nodes[level] = t;
@@ -681,11 +681,11 @@ static int insert_new_root(struct ctree_root *root,
681 * 681 *
682 * returns zero on success and < 0 on any error 682 * returns zero on success and < 0 on any error
683 */ 683 */
684static int insert_ptr(struct ctree_root *root, 684static int insert_ptr(struct btrfs_root *root,
685 struct ctree_path *path, struct btrfs_disk_key *key, 685 struct btrfs_path *path, struct btrfs_disk_key *key,
686 u64 blocknr, int slot, int level) 686 u64 blocknr, int slot, int level)
687{ 687{
688 struct node *lower; 688 struct btrfs_node *lower;
689 int nritems; 689 int nritems;
690 690
691 BUG_ON(!path->nodes[level]); 691 BUG_ON(!path->nodes[level]);
@@ -719,13 +719,13 @@ static int insert_ptr(struct ctree_root *root,
719 * 719 *
720 * returns 0 on success and < 0 on failure 720 * returns 0 on success and < 0 on failure
721 */ 721 */
722static int split_node(struct ctree_root *root, struct ctree_path *path, 722static int split_node(struct btrfs_root *root, struct btrfs_path *path,
723 int level) 723 int level)
724{ 724{
725 struct tree_buffer *t; 725 struct btrfs_buffer *t;
726 struct node *c; 726 struct btrfs_node *c;
727 struct tree_buffer *split_buffer; 727 struct btrfs_buffer *split_buffer;
728 struct node *split; 728 struct btrfs_node *split;
729 int mid; 729 int mid;
730 int ret; 730 int ret;
731 int wret; 731 int wret;
@@ -740,7 +740,7 @@ static int split_node(struct ctree_root *root, struct ctree_path *path,
740 return ret; 740 return ret;
741 } 741 }
742 c_nritems = btrfs_header_nritems(&c->header); 742 c_nritems = btrfs_header_nritems(&c->header);
743 split_buffer = alloc_free_block(root); 743 split_buffer = btrfs_alloc_free_block(root);
744 split = &split_buffer->node; 744 split = &split_buffer->node;
745 btrfs_set_header_flags(&split->header, btrfs_header_flags(&c->header)); 745 btrfs_set_header_flags(&split->header, btrfs_header_flags(&c->header));
746 btrfs_set_header_blocknr(&split->header, split_buffer->blocknr); 746 btrfs_set_header_blocknr(&split->header, split_buffer->blocknr);
@@ -763,11 +763,11 @@ static int split_node(struct ctree_root *root, struct ctree_path *path,
763 763
764 if (path->slots[level] >= mid) { 764 if (path->slots[level] >= mid) {
765 path->slots[level] -= mid; 765 path->slots[level] -= mid;
766 tree_block_release(root, t); 766 btrfs_block_release(root, t);
767 path->nodes[level] = split_buffer; 767 path->nodes[level] = split_buffer;
768 path->slots[level + 1] += 1; 768 path->slots[level + 1] += 1;
769 } else { 769 } else {
770 tree_block_release(root, split_buffer); 770 btrfs_block_release(root, split_buffer);
771 } 771 }
772 return ret; 772 return ret;
773} 773}
@@ -777,7 +777,7 @@ static int split_node(struct ctree_root *root, struct ctree_path *path,
777 * and nr indicate which items in the leaf to check. This totals up the 777 * and nr indicate which items in the leaf to check. This totals up the
778 * space used both by the item structs and the item data 778 * space used both by the item structs and the item data
779 */ 779 */
780static int leaf_space_used(struct leaf *l, int start, int nr) 780static int leaf_space_used(struct btrfs_leaf *l, int start, int nr)
781{ 781{
782 int data_len; 782 int data_len;
783 int end = start + nr - 1; 783 int end = start + nr - 1;
@@ -797,14 +797,14 @@ static int leaf_space_used(struct leaf *l, int start, int nr)
797 * returns 1 if the push failed because the other node didn't have enough 797 * returns 1 if the push failed because the other node didn't have enough
798 * room, 0 if everything worked out and < 0 if there were major errors. 798 * room, 0 if everything worked out and < 0 if there were major errors.
799 */ 799 */
800static int push_leaf_right(struct ctree_root *root, struct ctree_path *path, 800static int push_leaf_right(struct btrfs_root *root, struct btrfs_path *path,
801 int data_size) 801 int data_size)
802{ 802{
803 struct tree_buffer *left_buf = path->nodes[0]; 803 struct btrfs_buffer *left_buf = path->nodes[0];
804 struct leaf *left = &left_buf->leaf; 804 struct btrfs_leaf *left = &left_buf->leaf;
805 struct leaf *right; 805 struct btrfs_leaf *right;
806 struct tree_buffer *right_buf; 806 struct btrfs_buffer *right_buf;
807 struct tree_buffer *upper; 807 struct btrfs_buffer *upper;
808 int slot; 808 int slot;
809 int i; 809 int i;
810 int free_space; 810 int free_space;
@@ -825,17 +825,17 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path,
825 right_buf = read_tree_block(root, btrfs_node_blockptr(&upper->node, 825 right_buf = read_tree_block(root, btrfs_node_blockptr(&upper->node,
826 slot + 1)); 826 slot + 1));
827 right = &right_buf->leaf; 827 right = &right_buf->leaf;
828 free_space = leaf_free_space(right); 828 free_space = btrfs_leaf_free_space(right);
829 if (free_space < data_size + sizeof(struct btrfs_item)) { 829 if (free_space < data_size + sizeof(struct btrfs_item)) {
830 tree_block_release(root, right_buf); 830 btrfs_block_release(root, right_buf);
831 return 1; 831 return 1;
832 } 832 }
833 /* cow and double check */ 833 /* cow and double check */
834 btrfs_cow_block(root, right_buf, upper, slot + 1, &right_buf); 834 btrfs_cow_block(root, right_buf, upper, slot + 1, &right_buf);
835 right = &right_buf->leaf; 835 right = &right_buf->leaf;
836 free_space = leaf_free_space(right); 836 free_space = btrfs_leaf_free_space(right);
837 if (free_space < data_size + sizeof(struct btrfs_item)) { 837 if (free_space < data_size + sizeof(struct btrfs_item)) {
838 tree_block_release(root, right_buf); 838 btrfs_block_release(root, right_buf);
839 return 1; 839 return 1;
840 } 840 }
841 841
@@ -851,7 +851,7 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path,
851 push_space += btrfs_item_size(item) + sizeof(*item); 851 push_space += btrfs_item_size(item) + sizeof(*item);
852 } 852 }
853 if (push_items == 0) { 853 if (push_items == 0) {
854 tree_block_release(root, right_buf); 854 btrfs_block_release(root, right_buf);
855 return 1; 855 return 1;
856 } 856 }
857 right_nritems = btrfs_header_nritems(&right->header); 857 right_nritems = btrfs_header_nritems(&right->header);
@@ -893,11 +893,11 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path,
893 /* then fixup the leaf pointer in the path */ 893 /* then fixup the leaf pointer in the path */
894 if (path->slots[0] >= left_nritems) { 894 if (path->slots[0] >= left_nritems) {
895 path->slots[0] -= left_nritems; 895 path->slots[0] -= left_nritems;
896 tree_block_release(root, path->nodes[0]); 896 btrfs_block_release(root, path->nodes[0]);
897 path->nodes[0] = right_buf; 897 path->nodes[0] = right_buf;
898 path->slots[1] += 1; 898 path->slots[1] += 1;
899 } else { 899 } else {
900 tree_block_release(root, right_buf); 900 btrfs_block_release(root, right_buf);
901 } 901 }
902 return 0; 902 return 0;
903} 903}
@@ -905,13 +905,13 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path,
905 * push some data in the path leaf to the left, trying to free up at 905 * push some data in the path leaf to the left, trying to free up at
906 * least data_size bytes. returns zero if the push worked, nonzero otherwise 906 * least data_size bytes. returns zero if the push worked, nonzero otherwise
907 */ 907 */
908static int push_leaf_left(struct ctree_root *root, struct ctree_path *path, 908static int push_leaf_left(struct btrfs_root *root, struct btrfs_path *path,
909 int data_size) 909 int data_size)
910{ 910{
911 struct tree_buffer *right_buf = path->nodes[0]; 911 struct btrfs_buffer *right_buf = path->nodes[0];
912 struct leaf *right = &right_buf->leaf; 912 struct btrfs_leaf *right = &right_buf->leaf;
913 struct tree_buffer *t; 913 struct btrfs_buffer *t;
914 struct leaf *left; 914 struct btrfs_leaf *left;
915 int slot; 915 int slot;
916 int i; 916 int i;
917 int free_space; 917 int free_space;
@@ -932,18 +932,18 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path,
932 t = read_tree_block(root, btrfs_node_blockptr(&path->nodes[1]->node, 932 t = read_tree_block(root, btrfs_node_blockptr(&path->nodes[1]->node,
933 slot - 1)); 933 slot - 1));
934 left = &t->leaf; 934 left = &t->leaf;
935 free_space = leaf_free_space(left); 935 free_space = btrfs_leaf_free_space(left);
936 if (free_space < data_size + sizeof(struct btrfs_item)) { 936 if (free_space < data_size + sizeof(struct btrfs_item)) {
937 tree_block_release(root, t); 937 btrfs_block_release(root, t);
938 return 1; 938 return 1;
939 } 939 }
940 940
941 /* cow and double check */ 941 /* cow and double check */
942 btrfs_cow_block(root, t, path->nodes[1], slot - 1, &t); 942 btrfs_cow_block(root, t, path->nodes[1], slot - 1, &t);
943 left = &t->leaf; 943 left = &t->leaf;
944 free_space = leaf_free_space(left); 944 free_space = btrfs_leaf_free_space(left);
945 if (free_space < data_size + sizeof(struct btrfs_item)) { 945 if (free_space < data_size + sizeof(struct btrfs_item)) {
946 tree_block_release(root, t); 946 btrfs_block_release(root, t);
947 return 1; 947 return 1;
948 } 948 }
949 949
@@ -958,7 +958,7 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path,
958 push_space += btrfs_item_size(item) + sizeof(*item); 958 push_space += btrfs_item_size(item) + sizeof(*item);
959 } 959 }
960 if (push_items == 0) { 960 if (push_items == 0) {
961 tree_block_release(root, t); 961 btrfs_block_release(root, t);
962 return 1; 962 return 1;
963 } 963 }
964 /* push data from right to left */ 964 /* push data from right to left */
@@ -1009,11 +1009,11 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path,
1009 /* then fixup the leaf pointer in the path */ 1009 /* then fixup the leaf pointer in the path */
1010 if (path->slots[0] < push_items) { 1010 if (path->slots[0] < push_items) {
1011 path->slots[0] += old_left_nritems; 1011 path->slots[0] += old_left_nritems;
1012 tree_block_release(root, path->nodes[0]); 1012 btrfs_block_release(root, path->nodes[0]);
1013 path->nodes[0] = t; 1013 path->nodes[0] = t;
1014 path->slots[1] -= 1; 1014 path->slots[1] -= 1;
1015 } else { 1015 } else {
1016 tree_block_release(root, t); 1016 btrfs_block_release(root, t);
1017 path->slots[0] -= push_items; 1017 path->slots[0] -= push_items;
1018 } 1018 }
1019 BUG_ON(path->slots[0] < 0); 1019 BUG_ON(path->slots[0] < 0);
@@ -1026,16 +1026,16 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path,
1026 * 1026 *
1027 * returns 0 if all went well and < 0 on failure. 1027 * returns 0 if all went well and < 0 on failure.
1028 */ 1028 */
1029static int split_leaf(struct ctree_root *root, struct ctree_path *path, 1029static int split_leaf(struct btrfs_root *root, struct btrfs_path *path,
1030 int data_size) 1030 int data_size)
1031{ 1031{
1032 struct tree_buffer *l_buf; 1032 struct btrfs_buffer *l_buf;
1033 struct leaf *l; 1033 struct btrfs_leaf *l;
1034 u32 nritems; 1034 u32 nritems;
1035 int mid; 1035 int mid;
1036 int slot; 1036 int slot;
1037 struct leaf *right; 1037 struct btrfs_leaf *right;
1038 struct tree_buffer *right_buffer; 1038 struct btrfs_buffer *right_buffer;
1039 int space_needed = data_size + sizeof(struct btrfs_item); 1039 int space_needed = data_size + sizeof(struct btrfs_item);
1040 int data_copy_size; 1040 int data_copy_size;
1041 int rt_data_off; 1041 int rt_data_off;
@@ -1047,7 +1047,7 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path,
1047 l = &l_buf->leaf; 1047 l = &l_buf->leaf;
1048 1048
1049 /* did the pushes work? */ 1049 /* did the pushes work? */
1050 if (leaf_free_space(l) >= sizeof(struct btrfs_item) + data_size) 1050 if (btrfs_leaf_free_space(l) >= sizeof(struct btrfs_item) + data_size)
1051 return 0; 1051 return 0;
1052 1052
1053 if (!path->nodes[1]) { 1053 if (!path->nodes[1]) {
@@ -1058,7 +1058,7 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path,
1058 slot = path->slots[0]; 1058 slot = path->slots[0];
1059 nritems = btrfs_header_nritems(&l->header); 1059 nritems = btrfs_header_nritems(&l->header);
1060 mid = (nritems + 1)/ 2; 1060 mid = (nritems + 1)/ 2;
1061 right_buffer = alloc_free_block(root); 1061 right_buffer = btrfs_alloc_free_block(root);
1062 BUG_ON(!right_buffer); 1062 BUG_ON(!right_buffer);
1063 BUG_ON(mid == nritems); 1063 BUG_ON(mid == nritems);
1064 right = &right_buffer->leaf; 1064 right = &right_buffer->leaf;
@@ -1101,12 +1101,12 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path,
1101 BUG_ON(list_empty(&l_buf->dirty)); 1101 BUG_ON(list_empty(&l_buf->dirty));
1102 BUG_ON(path->slots[0] != slot); 1102 BUG_ON(path->slots[0] != slot);
1103 if (mid <= slot) { 1103 if (mid <= slot) {
1104 tree_block_release(root, path->nodes[0]); 1104 btrfs_block_release(root, path->nodes[0]);
1105 path->nodes[0] = right_buffer; 1105 path->nodes[0] = right_buffer;
1106 path->slots[0] -= mid; 1106 path->slots[0] -= mid;
1107 path->slots[1] += 1; 1107 path->slots[1] += 1;
1108 } else 1108 } else
1109 tree_block_release(root, right_buffer); 1109 btrfs_block_release(root, right_buffer);
1110 BUG_ON(path->slots[0] < 0); 1110 BUG_ON(path->slots[0] < 0);
1111 return ret; 1111 return ret;
1112} 1112}
@@ -1115,17 +1115,17 @@ static int split_leaf(struct ctree_root *root, struct ctree_path *path,
1115 * Given a key and some data, insert an item into the tree. 1115 * Given a key and some data, insert an item into the tree.
1116 * This does all the path init required, making room in the tree if needed. 1116 * This does all the path init required, making room in the tree if needed.
1117 */ 1117 */
1118int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key, 1118int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key,
1119 void *data, int data_size) 1119 void *data, int data_size)
1120{ 1120{
1121 int ret = 0; 1121 int ret = 0;
1122 int slot; 1122 int slot;
1123 int slot_orig; 1123 int slot_orig;
1124 struct leaf *leaf; 1124 struct btrfs_leaf *leaf;
1125 struct tree_buffer *leaf_buf; 1125 struct btrfs_buffer *leaf_buf;
1126 u32 nritems; 1126 u32 nritems;
1127 unsigned int data_end; 1127 unsigned int data_end;
1128 struct ctree_path path; 1128 struct btrfs_path path;
1129 struct btrfs_disk_key disk_key; 1129 struct btrfs_disk_key disk_key;
1130 1130
1131 btrfs_cpu_key_to_disk(&disk_key, cpu_key); 1131 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
@@ -1133,10 +1133,10 @@ int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key,
1133 /* create a root if there isn't one */ 1133 /* create a root if there isn't one */
1134 if (!root->node) 1134 if (!root->node)
1135 BUG(); 1135 BUG();
1136 init_path(&path); 1136 btrfs_init_path(&path);
1137 ret = search_slot(root, cpu_key, &path, data_size, 1); 1137 ret = btrfs_search_slot(root, cpu_key, &path, data_size, 1);
1138 if (ret == 0) { 1138 if (ret == 0) {
1139 release_path(root, &path); 1139 btrfs_release_path(root, &path);
1140 return -EEXIST; 1140 return -EEXIST;
1141 } 1141 }
1142 if (ret < 0) 1142 if (ret < 0)
@@ -1149,7 +1149,8 @@ int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key,
1149 nritems = btrfs_header_nritems(&leaf->header); 1149 nritems = btrfs_header_nritems(&leaf->header);
1150 data_end = leaf_data_end(leaf); 1150 data_end = leaf_data_end(leaf);
1151 1151
1152 if (leaf_free_space(leaf) < sizeof(struct btrfs_item) + data_size) 1152 if (btrfs_leaf_free_space(leaf) <
1153 sizeof(struct btrfs_item) + data_size)
1153 BUG(); 1154 BUG();
1154 1155
1155 slot = path.slots[0]; 1156 slot = path.slots[0];
@@ -1190,11 +1191,11 @@ int insert_item(struct ctree_root *root, struct btrfs_key *cpu_key,
1190 ret = fixup_low_keys(root, &path, &disk_key, 1); 1191 ret = fixup_low_keys(root, &path, &disk_key, 1);
1191 1192
1192 BUG_ON(list_empty(&leaf_buf->dirty)); 1193 BUG_ON(list_empty(&leaf_buf->dirty));
1193 if (leaf_free_space(leaf) < 0) 1194 if (btrfs_leaf_free_space(leaf) < 0)
1194 BUG(); 1195 BUG();
1195 check_leaf(&path, 0); 1196 check_leaf(&path, 0);
1196out: 1197out:
1197 release_path(root, &path); 1198 btrfs_release_path(root, &path);
1198 return ret; 1199 return ret;
1199} 1200}
1200 1201
@@ -1205,11 +1206,11 @@ out:
1205 * continuing all the way the root if required. The root is converted into 1206 * continuing all the way the root if required. The root is converted into
1206 * a leaf if all the nodes are emptied. 1207 * a leaf if all the nodes are emptied.
1207 */ 1208 */
1208static int del_ptr(struct ctree_root *root, struct ctree_path *path, int level, 1209static int del_ptr(struct btrfs_root *root, struct btrfs_path *path, int level,
1209 int slot) 1210 int slot)
1210{ 1211{
1211 struct node *node; 1212 struct btrfs_node *node;
1212 struct tree_buffer *parent = path->nodes[level]; 1213 struct btrfs_buffer *parent = path->nodes[level];
1213 u32 nritems; 1214 u32 nritems;
1214 int ret = 0; 1215 int ret = 0;
1215 int wret; 1216 int wret;
@@ -1242,11 +1243,11 @@ static int del_ptr(struct ctree_root *root, struct ctree_path *path, int level,
1242 * delete the item at the leaf level in path. If that empties 1243 * delete the item at the leaf level in path. If that empties
1243 * the leaf, remove it from the tree 1244 * the leaf, remove it from the tree
1244 */ 1245 */
1245int del_item(struct ctree_root *root, struct ctree_path *path) 1246int btrfs_del_item(struct btrfs_root *root, struct btrfs_path *path)
1246{ 1247{
1247 int slot; 1248 int slot;
1248 struct leaf *leaf; 1249 struct btrfs_leaf *leaf;
1249 struct tree_buffer *leaf_buf; 1250 struct btrfs_buffer *leaf_buf;
1250 int doff; 1251 int doff;
1251 int dsize; 1252 int dsize;
1252 int ret = 0; 1253 int ret = 0;
@@ -1286,7 +1287,7 @@ int del_item(struct ctree_root *root, struct ctree_path *path)
1286 wret = del_ptr(root, path, 1, path->slots[1]); 1287 wret = del_ptr(root, path, 1, path->slots[1]);
1287 if (wret) 1288 if (wret)
1288 ret = wret; 1289 ret = wret;
1289 wret = free_extent(root, leaf_buf->blocknr, 1); 1290 wret = btrfs_free_extent(root, leaf_buf->blocknr, 1);
1290 if (wret) 1291 if (wret)
1291 ret = wret; 1292 ret = wret;
1292 } 1293 }
@@ -1323,12 +1324,12 @@ int del_item(struct ctree_root *root, struct ctree_path *path)
1323 wret = del_ptr(root, path, 1, slot); 1324 wret = del_ptr(root, path, 1, slot);
1324 if (wret) 1325 if (wret)
1325 ret = wret; 1326 ret = wret;
1326 tree_block_release(root, leaf_buf); 1327 btrfs_block_release(root, leaf_buf);
1327 wret = free_extent(root, blocknr, 1); 1328 wret = btrfs_free_extent(root, blocknr, 1);
1328 if (wret) 1329 if (wret)
1329 ret = wret; 1330 ret = wret;
1330 } else { 1331 } else {
1331 tree_block_release(root, leaf_buf); 1332 btrfs_block_release(root, leaf_buf);
1332 } 1333 }
1333 } 1334 }
1334 } 1335 }
@@ -1340,15 +1341,15 @@ int del_item(struct ctree_root *root, struct ctree_path *path)
1340 * returns 0 if it found something or 1 if there are no greater leaves. 1341 * returns 0 if it found something or 1 if there are no greater leaves.
1341 * returns < 0 on io errors. 1342 * returns < 0 on io errors.
1342 */ 1343 */
1343int next_leaf(struct ctree_root *root, struct ctree_path *path) 1344int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path)
1344{ 1345{
1345 int slot; 1346 int slot;
1346 int level = 1; 1347 int level = 1;
1347 u64 blocknr; 1348 u64 blocknr;
1348 struct tree_buffer *c; 1349 struct btrfs_buffer *c;
1349 struct tree_buffer *next = NULL; 1350 struct btrfs_buffer *next = NULL;
1350 1351
1351 while(level < MAX_LEVEL) { 1352 while(level < BTRFS_MAX_LEVEL) {
1352 if (!path->nodes[level]) 1353 if (!path->nodes[level])
1353 return 1; 1354 return 1;
1354 slot = path->slots[level] + 1; 1355 slot = path->slots[level] + 1;
@@ -1359,7 +1360,7 @@ int next_leaf(struct ctree_root *root, struct ctree_path *path)
1359 } 1360 }
1360 blocknr = btrfs_node_blockptr(&c->node, slot); 1361 blocknr = btrfs_node_blockptr(&c->node, slot);
1361 if (next) 1362 if (next)
1362 tree_block_release(root, next); 1363 btrfs_block_release(root, next);
1363 next = read_tree_block(root, blocknr); 1364 next = read_tree_block(root, blocknr);
1364 break; 1365 break;
1365 } 1366 }
@@ -1367,7 +1368,7 @@ int next_leaf(struct ctree_root *root, struct ctree_path *path)
1367 while(1) { 1368 while(1) {
1368 level--; 1369 level--;
1369 c = path->nodes[level]; 1370 c = path->nodes[level];
1370 tree_block_release(root, c); 1371 btrfs_block_release(root, c);
1371 path->nodes[level] = next; 1372 path->nodes[level] = next;
1372 path->slots[level] = 0; 1373 path->slots[level] = 0;
1373 if (!level) 1374 if (!level)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 90cc2c9bd79..5dfcc90812c 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1,10 +1,10 @@
1#ifndef __CTREE__ 1#ifndef __BTRFS__
2#define __CTREE__ 2#define __BTRFS__
3 3
4#include "list.h" 4#include "list.h"
5#include "kerncompat.h" 5#include "kerncompat.h"
6 6
7#define CTREE_BLOCKSIZE 1024 7#define BTRFS_BLOCKSIZE 1024
8 8
9/* 9/*
10 * the key defines the order in the tree, and so it also defines (optimal) 10 * the key defines the order in the tree, and so it also defines (optimal)
@@ -46,21 +46,21 @@ struct btrfs_header {
46 /* generation flags to be added */ 46 /* generation flags to be added */
47} __attribute__ ((__packed__)); 47} __attribute__ ((__packed__));
48 48
49#define MAX_LEVEL 8 49#define BTRFS_MAX_LEVEL 8
50#define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct btrfs_header)) / \ 50#define NODEPTRS_PER_BLOCK ((BTRFS_BLOCKSIZE - sizeof(struct btrfs_header)) / \
51 (sizeof(struct btrfs_disk_key) + sizeof(u64))) 51 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
52 52
53struct tree_buffer; 53struct btrfs_buffer;
54 54
55/* 55/*
56 * in ram representation of the tree. extent_root is used for all allocations 56 * in ram representation of the tree. extent_root is used for all allocations
57 * and for the extent tree extent_root root. current_insert is used 57 * and for the extent tree extent_root root. current_insert is used
58 * only for the extent tree. 58 * only for the extent tree.
59 */ 59 */
60struct ctree_root { 60struct btrfs_root {
61 struct tree_buffer *node; 61 struct btrfs_buffer *node;
62 struct tree_buffer *commit_root; 62 struct btrfs_buffer *commit_root;
63 struct ctree_root *extent_root; 63 struct btrfs_root *extent_root;
64 struct btrfs_key current_insert; 64 struct btrfs_key current_insert;
65 struct btrfs_key last_insert; 65 struct btrfs_key last_insert;
66 int fp; 66 int fp;
@@ -74,7 +74,7 @@ struct ctree_root {
74/* 74/*
75 * describes a tree on disk 75 * describes a tree on disk
76 */ 76 */
77struct ctree_root_info { 77struct btrfs_root_info {
78 u64 fsid[2]; /* FS specific uuid */ 78 u64 fsid[2]; /* FS specific uuid */
79 u64 blocknr; /* blocknr of this block */ 79 u64 blocknr; /* blocknr of this block */
80 u64 objectid; /* inode number of this root */ 80 u64 objectid; /* inode number of this root */
@@ -88,9 +88,9 @@ struct ctree_root_info {
88 * the super block basically lists the main trees of the FS 88 * the super block basically lists the main trees of the FS
89 * it currently lacks any block count etc etc 89 * it currently lacks any block count etc etc
90 */ 90 */
91struct ctree_super_block { 91struct btrfs_super_block {
92 struct ctree_root_info root_info; 92 struct btrfs_root_info root_info;
93 struct ctree_root_info extent_info; 93 struct btrfs_root_info extent_info;
94} __attribute__ ((__packed__)); 94} __attribute__ ((__packed__));
95 95
96/* 96/*
@@ -111,13 +111,13 @@ struct btrfs_item {
111 * The data is separate from the items to get the keys closer together 111 * The data is separate from the items to get the keys closer together
112 * during searches. 112 * during searches.
113 */ 113 */
114#define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct btrfs_header)) 114#define LEAF_DATA_SIZE (BTRFS_BLOCKSIZE - sizeof(struct btrfs_header))
115struct leaf { 115struct btrfs_leaf {
116 struct btrfs_header header; 116 struct btrfs_header header;
117 union { 117 union {
118 struct btrfs_item items[LEAF_DATA_SIZE/ 118 struct btrfs_item items[LEAF_DATA_SIZE/
119 sizeof(struct btrfs_item)]; 119 sizeof(struct btrfs_item)];
120 u8 data[CTREE_BLOCKSIZE-sizeof(struct btrfs_header)]; 120 u8 data[BTRFS_BLOCKSIZE - sizeof(struct btrfs_header)];
121 }; 121 };
122} __attribute__ ((__packed__)); 122} __attribute__ ((__packed__));
123 123
@@ -125,7 +125,7 @@ struct leaf {
125 * all non-leaf blocks are nodes, they hold only keys and pointers to 125 * all non-leaf blocks are nodes, they hold only keys and pointers to
126 * other blocks 126 * other blocks
127 */ 127 */
128struct node { 128struct btrfs_node {
129 struct btrfs_header header; 129 struct btrfs_header header;
130 struct btrfs_disk_key keys[NODEPTRS_PER_BLOCK]; 130 struct btrfs_disk_key keys[NODEPTRS_PER_BLOCK];
131 __le64 blockptrs[NODEPTRS_PER_BLOCK]; 131 __le64 blockptrs[NODEPTRS_PER_BLOCK];
@@ -135,50 +135,51 @@ struct node {
135 * items in the extent btree are used to record the objectid of the 135 * items in the extent btree are used to record the objectid of the
136 * owner of the block and the number of references 136 * owner of the block and the number of references
137 */ 137 */
138struct extent_item { 138struct btrfs_extent_item {
139 __le32 refs; 139 __le32 refs;
140 __le64 owner; 140 __le64 owner;
141} __attribute__ ((__packed__)); 141} __attribute__ ((__packed__));
142 142
143/* 143/*
144 * ctree_paths remember the path taken from the root down to the leaf. 144 * btrfs_paths remember the path taken from the root down to the leaf.
145 * level 0 is always the leaf, and nodes[1...MAX_LEVEL] will point 145 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
146 * to any other levels that are present. 146 * to any other levels that are present.
147 * 147 *
148 * The slots array records the index of the item or block pointer 148 * The slots array records the index of the item or block pointer
149 * used while walking the tree. 149 * used while walking the tree.
150 */ 150 */
151struct ctree_path { 151struct btrfs_path {
152 struct tree_buffer *nodes[MAX_LEVEL]; 152 struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
153 int slots[MAX_LEVEL]; 153 int slots[BTRFS_MAX_LEVEL];
154}; 154};
155 155
156static inline u64 btrfs_extent_owner(struct extent_item *ei) 156static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
157{ 157{
158 return le64_to_cpu(ei->owner); 158 return le64_to_cpu(ei->owner);
159} 159}
160 160
161static inline void btrfs_set_extent_owner(struct extent_item *ei, u64 val) 161static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
162{ 162{
163 ei->owner = cpu_to_le64(val); 163 ei->owner = cpu_to_le64(val);
164} 164}
165 165
166static inline u32 btrfs_extent_refs(struct extent_item *ei) 166static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
167{ 167{
168 return le32_to_cpu(ei->refs); 168 return le32_to_cpu(ei->refs);
169} 169}
170 170
171static inline void btrfs_set_extent_refs(struct extent_item *ei, u32 val) 171static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
172{ 172{
173 ei->refs = cpu_to_le32(val); 173 ei->refs = cpu_to_le32(val);
174} 174}
175 175
176static inline u64 btrfs_node_blockptr(struct node *n, int nr) 176static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
177{ 177{
178 return le64_to_cpu(n->blockptrs[nr]); 178 return le64_to_cpu(n->blockptrs[nr]);
179} 179}
180 180
181static inline void btrfs_set_node_blockptr(struct node *n, int nr, u64 val) 181static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
182 u64 val)
182{ 183{
183 n->blockptrs[nr] = cpu_to_le64(val); 184 n->blockptrs[nr] = cpu_to_le64(val);
184} 185}
@@ -300,34 +301,34 @@ static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
300 301
301static inline int btrfs_header_level(struct btrfs_header *h) 302static inline int btrfs_header_level(struct btrfs_header *h)
302{ 303{
303 return btrfs_header_flags(h) & (MAX_LEVEL - 1); 304 return btrfs_header_flags(h) & (BTRFS_MAX_LEVEL - 1);
304} 305}
305 306
306static inline void btrfs_set_header_level(struct btrfs_header *h, int level) 307static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
307{ 308{
308 u16 flags; 309 u16 flags;
309 BUG_ON(level > MAX_LEVEL); 310 BUG_ON(level > BTRFS_MAX_LEVEL);
310 flags = btrfs_header_flags(h) & ~(MAX_LEVEL - 1); 311 flags = btrfs_header_flags(h) & ~(BTRFS_MAX_LEVEL - 1);
311 btrfs_set_header_flags(h, flags | level); 312 btrfs_set_header_flags(h, flags | level);
312} 313}
313 314
314static inline int btrfs_is_leaf(struct node *n) 315static inline int btrfs_is_leaf(struct btrfs_node *n)
315{ 316{
316 return (btrfs_header_level(&n->header) == 0); 317 return (btrfs_header_level(&n->header) == 0);
317} 318}
318 319
319struct tree_buffer *alloc_free_block(struct ctree_root *root); 320struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root);
320int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf); 321int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf);
321int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks); 322int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks);
322int search_slot(struct ctree_root *root, struct btrfs_key *key, 323int btrfs_search_slot(struct btrfs_root *root, struct btrfs_key *key,
323 struct ctree_path *p, int ins_len, int cow); 324 struct btrfs_path *p, int ins_len, int cow);
324void release_path(struct ctree_root *root, struct ctree_path *p); 325void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
325void init_path(struct ctree_path *p); 326void btrfs_init_path(struct btrfs_path *p);
326int del_item(struct ctree_root *root, struct ctree_path *path); 327int btrfs_del_item(struct btrfs_root *root, struct btrfs_path *path);
327int insert_item(struct ctree_root *root, struct btrfs_key *key, 328int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *key,
328 void *data, int data_size); 329 void *data, int data_size);
329int next_leaf(struct ctree_root *root, struct ctree_path *path); 330int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
330int leaf_free_space(struct leaf *leaf); 331int btrfs_leaf_free_space(struct btrfs_leaf *leaf);
331int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap); 332int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap);
332int btrfs_finish_extent_commit(struct ctree_root *root); 333int btrfs_finish_extent_commit(struct btrfs_root *root);
333#endif 334#endif
diff --git a/fs/btrfs/debug-tree.c b/fs/btrfs/debug-tree.c
index 21f607d8b05..6da0a7aa0f4 100644
--- a/fs/btrfs/debug-tree.c
+++ b/fs/btrfs/debug-tree.c
@@ -7,13 +7,13 @@
7#include "print-tree.h" 7#include "print-tree.h"
8 8
9int main(int ac, char **av) { 9int main(int ac, char **av) {
10 struct ctree_super_block super; 10 struct btrfs_super_block super;
11 struct ctree_root *root; 11 struct btrfs_root *root;
12 radix_tree_init(); 12 radix_tree_init();
13 root = open_ctree("dbfile", &super); 13 root = open_ctree("dbfile", &super);
14 printf("root tree\n"); 14 printf("root tree\n");
15 print_tree(root, root->node); 15 btrfs_print_tree(root, root->node);
16 printf("map tree\n"); 16 printf("map tree\n");
17 print_tree(root->extent_root, root->extent_root->node); 17 btrfs_print_tree(root->extent_root, root->extent_root->node);
18 return 0; 18 return 0;
19} 19}
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 065e888d2c0..c34c0c60935 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -13,7 +13,7 @@
13static int allocated_blocks = 0; 13static int allocated_blocks = 0;
14int cache_max = 10000; 14int cache_max = 10000;
15 15
16static int check_tree_block(struct ctree_root *root, struct tree_buffer *buf) 16static int check_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
17{ 17{
18 if (buf->blocknr != btrfs_header_blocknr(&buf->node.header)) 18 if (buf->blocknr != btrfs_header_blocknr(&buf->node.header))
19 BUG(); 19 BUG();
@@ -23,18 +23,18 @@ static int check_tree_block(struct ctree_root *root, struct tree_buffer *buf)
23 return 0; 23 return 0;
24} 24}
25 25
26static int free_some_buffers(struct ctree_root *root) 26static int free_some_buffers(struct btrfs_root *root)
27{ 27{
28 struct list_head *node, *next; 28 struct list_head *node, *next;
29 struct tree_buffer *b; 29 struct btrfs_buffer *b;
30 if (root->cache_size < cache_max) 30 if (root->cache_size < cache_max)
31 return 0; 31 return 0;
32 list_for_each_safe(node, next, &root->cache) { 32 list_for_each_safe(node, next, &root->cache) {
33 b = list_entry(node, struct tree_buffer, cache); 33 b = list_entry(node, struct btrfs_buffer, cache);
34 if (b->count == 1) { 34 if (b->count == 1) {
35 BUG_ON(!list_empty(&b->dirty)); 35 BUG_ON(!list_empty(&b->dirty));
36 list_del_init(&b->cache); 36 list_del_init(&b->cache);
37 tree_block_release(root, b); 37 btrfs_block_release(root, b);
38 if (root->cache_size < cache_max) 38 if (root->cache_size < cache_max)
39 break; 39 break;
40 } 40 }
@@ -42,11 +42,11 @@ static int free_some_buffers(struct ctree_root *root)
42 return 0; 42 return 0;
43} 43}
44 44
45struct tree_buffer *alloc_tree_block(struct ctree_root *root, u64 blocknr) 45struct btrfs_buffer *alloc_tree_block(struct btrfs_root *root, u64 blocknr)
46{ 46{
47 struct tree_buffer *buf; 47 struct btrfs_buffer *buf;
48 int ret; 48 int ret;
49 buf = malloc(sizeof(struct tree_buffer)); 49 buf = malloc(sizeof(struct btrfs_buffer));
50 if (!buf) 50 if (!buf)
51 return buf; 51 return buf;
52 allocated_blocks++; 52 allocated_blocks++;
@@ -66,9 +66,9 @@ struct tree_buffer *alloc_tree_block(struct ctree_root *root, u64 blocknr)
66 return buf; 66 return buf;
67} 67}
68 68
69struct tree_buffer *find_tree_block(struct ctree_root *root, u64 blocknr) 69struct btrfs_buffer *find_tree_block(struct btrfs_root *root, u64 blocknr)
70{ 70{
71 struct tree_buffer *buf; 71 struct btrfs_buffer *buf;
72 buf = radix_tree_lookup(&root->cache_radix, blocknr); 72 buf = radix_tree_lookup(&root->cache_radix, blocknr);
73 if (buf) { 73 if (buf) {
74 buf->count++; 74 buf->count++;
@@ -82,10 +82,10 @@ struct tree_buffer *find_tree_block(struct ctree_root *root, u64 blocknr)
82 return buf; 82 return buf;
83} 83}
84 84
85struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr) 85struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr)
86{ 86{
87 loff_t offset = blocknr * CTREE_BLOCKSIZE; 87 loff_t offset = blocknr * BTRFS_BLOCKSIZE;
88 struct tree_buffer *buf; 88 struct btrfs_buffer *buf;
89 int ret; 89 int ret;
90 90
91 buf = radix_tree_lookup(&root->cache_radix, blocknr); 91 buf = radix_tree_lookup(&root->cache_radix, blocknr);
@@ -95,8 +95,8 @@ struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr)
95 buf = alloc_tree_block(root, blocknr); 95 buf = alloc_tree_block(root, blocknr);
96 if (!buf) 96 if (!buf)
97 return NULL; 97 return NULL;
98 ret = pread(root->fp, &buf->node, CTREE_BLOCKSIZE, offset); 98 ret = pread(root->fp, &buf->node, BTRFS_BLOCKSIZE, offset);
99 if (ret != CTREE_BLOCKSIZE) { 99 if (ret != BTRFS_BLOCKSIZE) {
100 free(buf); 100 free(buf);
101 return NULL; 101 return NULL;
102 } 102 }
@@ -106,7 +106,7 @@ struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr)
106 return buf; 106 return buf;
107} 107}
108 108
109int dirty_tree_block(struct ctree_root *root, struct tree_buffer *buf) 109int dirty_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
110{ 110{
111 if (!list_empty(&buf->dirty)) 111 if (!list_empty(&buf->dirty))
112 return 0; 112 return 0;
@@ -115,46 +115,47 @@ int dirty_tree_block(struct ctree_root *root, struct tree_buffer *buf)
115 return 0; 115 return 0;
116} 116}
117 117
118int clean_tree_block(struct ctree_root *root, struct tree_buffer *buf) 118int clean_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
119{ 119{
120 if (!list_empty(&buf->dirty)) { 120 if (!list_empty(&buf->dirty)) {
121 list_del_init(&buf->dirty); 121 list_del_init(&buf->dirty);
122 tree_block_release(root, buf); 122 btrfs_block_release(root, buf);
123 } 123 }
124 return 0; 124 return 0;
125} 125}
126 126
127int write_tree_block(struct ctree_root *root, struct tree_buffer *buf) 127int write_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf)
128{ 128{
129 u64 blocknr = buf->blocknr; 129 u64 blocknr = buf->blocknr;
130 loff_t offset = blocknr * CTREE_BLOCKSIZE; 130 loff_t offset = blocknr * BTRFS_BLOCKSIZE;
131 int ret; 131 int ret;
132 132
133 if (buf->blocknr != btrfs_header_blocknr(&buf->node.header)) 133 if (buf->blocknr != btrfs_header_blocknr(&buf->node.header))
134 BUG(); 134 BUG();
135 ret = pwrite(root->fp, &buf->node, CTREE_BLOCKSIZE, offset); 135 ret = pwrite(root->fp, &buf->node, BTRFS_BLOCKSIZE, offset);
136 if (ret != CTREE_BLOCKSIZE) 136 if (ret != BTRFS_BLOCKSIZE)
137 return ret; 137 return ret;
138 return 0; 138 return 0;
139} 139}
140 140
141static int __commit_transaction(struct ctree_root *root) 141static int __commit_transaction(struct btrfs_root *root)
142{ 142{
143 struct tree_buffer *b; 143 struct btrfs_buffer *b;
144 int ret = 0; 144 int ret = 0;
145 int wret; 145 int wret;
146 while(!list_empty(&root->trans)) { 146 while(!list_empty(&root->trans)) {
147 b = list_entry(root->trans.next, struct tree_buffer, dirty); 147 b = list_entry(root->trans.next, struct btrfs_buffer, dirty);
148 list_del_init(&b->dirty); 148 list_del_init(&b->dirty);
149 wret = write_tree_block(root, b); 149 wret = write_tree_block(root, b);
150 if (wret) 150 if (wret)
151 ret = wret; 151 ret = wret;
152 tree_block_release(root, b); 152 btrfs_block_release(root, b);
153 } 153 }
154 return ret; 154 return ret;
155} 155}
156 156
157int commit_transaction(struct ctree_root *root, struct ctree_super_block *s) 157int btrfs_commit_transaction(struct btrfs_root *root,
158 struct btrfs_super_block *s)
158{ 159{
159 int ret = 0; 160 int ret = 0;
160 161
@@ -163,20 +164,20 @@ int commit_transaction(struct ctree_root *root, struct ctree_super_block *s)
163 ret = __commit_transaction(root->extent_root); 164 ret = __commit_transaction(root->extent_root);
164 BUG_ON(ret); 165 BUG_ON(ret);
165 if (root->commit_root != root->node) { 166 if (root->commit_root != root->node) {
166 struct tree_buffer *snap = root->commit_root; 167 struct btrfs_buffer *snap = root->commit_root;
167 root->commit_root = root->node; 168 root->commit_root = root->node;
168 root->node->count++; 169 root->node->count++;
169 ret = btrfs_drop_snapshot(root, snap); 170 ret = btrfs_drop_snapshot(root, snap);
170 BUG_ON(ret); 171 BUG_ON(ret);
171 // tree_block_release(root, snap); 172 // btrfs_block_release(root, snap);
172 } 173 }
173 write_ctree_super(root, s); 174 write_ctree_super(root, s);
174 btrfs_finish_extent_commit(root); 175 btrfs_finish_extent_commit(root);
175 return ret; 176 return ret;
176} 177}
177 178
178static int __setup_root(struct ctree_root *root, struct ctree_root *extent_root, 179static int __setup_root(struct btrfs_root *root, struct btrfs_root *extent_root,
179 struct ctree_root_info *info, int fp) 180 struct btrfs_root_info *info, int fp)
180{ 181{
181 INIT_LIST_HEAD(&root->trans); 182 INIT_LIST_HEAD(&root->trans);
182 INIT_LIST_HEAD(&root->cache); 183 INIT_LIST_HEAD(&root->cache);
@@ -191,10 +192,10 @@ static int __setup_root(struct ctree_root *root, struct ctree_root *extent_root,
191 return 0; 192 return 0;
192} 193}
193 194
194struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super) 195struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *super)
195{ 196{
196 struct ctree_root *root = malloc(sizeof(struct ctree_root)); 197 struct btrfs_root *root = malloc(sizeof(struct btrfs_root));
197 struct ctree_root *extent_root = malloc(sizeof(struct ctree_root)); 198 struct btrfs_root *extent_root = malloc(sizeof(struct btrfs_root));
198 int fp; 199 int fp;
199 int ret; 200 int ret;
200 201
@@ -207,16 +208,16 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super)
207 INIT_RADIX_TREE(&root->pinned_radix, GFP_KERNEL); 208 INIT_RADIX_TREE(&root->pinned_radix, GFP_KERNEL);
208 INIT_RADIX_TREE(&extent_root->pinned_radix, GFP_KERNEL); 209 INIT_RADIX_TREE(&extent_root->pinned_radix, GFP_KERNEL);
209 INIT_RADIX_TREE(&extent_root->cache_radix, GFP_KERNEL); 210 INIT_RADIX_TREE(&extent_root->cache_radix, GFP_KERNEL);
210 ret = pread(fp, super, sizeof(struct ctree_super_block), 211 ret = pread(fp, super, sizeof(struct btrfs_super_block),
211 CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE)); 212 BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
212 if (ret == 0 || super->root_info.tree_root == 0) { 213 if (ret == 0 || super->root_info.tree_root == 0) {
213 printf("making new FS!\n"); 214 printf("making new FS!\n");
214 ret = mkfs(fp); 215 ret = mkfs(fp);
215 if (ret) 216 if (ret)
216 return NULL; 217 return NULL;
217 ret = pread(fp, super, sizeof(struct ctree_super_block), 218 ret = pread(fp, super, sizeof(struct btrfs_super_block),
218 CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE)); 219 BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
219 if (ret != sizeof(struct ctree_super_block)) 220 if (ret != sizeof(struct btrfs_super_block))
220 return NULL; 221 return NULL;
221 } 222 }
222 BUG_ON(ret < 0); 223 BUG_ON(ret < 0);
@@ -227,18 +228,19 @@ struct ctree_root *open_ctree(char *filename, struct ctree_super_block *super)
227 return root; 228 return root;
228} 229}
229 230
230static int __update_root(struct ctree_root *root, struct ctree_root_info *info) 231static int __update_root(struct btrfs_root *root, struct btrfs_root_info *info)
231{ 232{
232 info->tree_root = root->node->blocknr; 233 info->tree_root = root->node->blocknr;
233 return 0; 234 return 0;
234} 235}
235 236
236int write_ctree_super(struct ctree_root *root, struct ctree_super_block *s) 237int write_ctree_super(struct btrfs_root *root, struct btrfs_super_block *s)
237{ 238{
238 int ret; 239 int ret;
239 __update_root(root, &s->root_info); 240 __update_root(root, &s->root_info);
240 __update_root(root->extent_root, &s->extent_info); 241 __update_root(root->extent_root, &s->extent_info);
241 ret = pwrite(root->fp, s, sizeof(*s), CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE)); 242 ret = pwrite(root->fp, s, sizeof(*s),
243 BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
242 if (ret != sizeof(*s)) { 244 if (ret != sizeof(*s)) {
243 fprintf(stderr, "failed to write new super block err %d\n", ret); 245 fprintf(stderr, "failed to write new super block err %d\n", ret);
244 return ret; 246 return ret;
@@ -246,19 +248,19 @@ int write_ctree_super(struct ctree_root *root, struct ctree_super_block *s)
246 return 0; 248 return 0;
247} 249}
248 250
249static int drop_cache(struct ctree_root *root) 251static int drop_cache(struct btrfs_root *root)
250{ 252{
251 while(!list_empty(&root->cache)) { 253 while(!list_empty(&root->cache)) {
252 struct tree_buffer *b = list_entry(root->cache.next, 254 struct btrfs_buffer *b = list_entry(root->cache.next,
253 struct tree_buffer, cache); 255 struct btrfs_buffer, cache);
254 list_del_init(&b->cache); 256 list_del_init(&b->cache);
255 tree_block_release(root, b); 257 btrfs_block_release(root, b);
256 } 258 }
257 return 0; 259 return 0;
258} 260}
259int close_ctree(struct ctree_root *root, struct ctree_super_block *s) 261int close_ctree(struct btrfs_root *root, struct btrfs_super_block *s)
260{ 262{
261 commit_transaction(root, s); 263 btrfs_commit_transaction(root, s);
262 __commit_transaction(root->extent_root); 264 __commit_transaction(root->extent_root);
263 write_ctree_super(root, s); 265 write_ctree_super(root, s);
264 drop_cache(root->extent_root); 266 drop_cache(root->extent_root);
@@ -268,16 +270,16 @@ int close_ctree(struct ctree_root *root, struct ctree_super_block *s)
268 270
269 close(root->fp); 271 close(root->fp);
270 if (root->node) 272 if (root->node)
271 tree_block_release(root, root->node); 273 btrfs_block_release(root, root->node);
272 if (root->extent_root->node) 274 if (root->extent_root->node)
273 tree_block_release(root->extent_root, root->extent_root->node); 275 btrfs_block_release(root->extent_root, root->extent_root->node);
274 tree_block_release(root, root->commit_root); 276 btrfs_block_release(root, root->commit_root);
275 free(root); 277 free(root);
276 printf("on close %d blocks are allocated\n", allocated_blocks); 278 printf("on close %d blocks are allocated\n", allocated_blocks);
277 return 0; 279 return 0;
278} 280}
279 281
280void tree_block_release(struct ctree_root *root, struct tree_buffer *buf) 282void btrfs_block_release(struct btrfs_root *root, struct btrfs_buffer *buf)
281{ 283{
282 buf->count--; 284 buf->count--;
283 if (buf->count < 0) 285 if (buf->count < 0)
diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h
index 1c0af7c56c2..b391335864b 100644
--- a/fs/btrfs/disk-io.h
+++ b/fs/btrfs/disk-io.h
@@ -2,29 +2,30 @@
2#define __DISKIO__ 2#define __DISKIO__
3#include "list.h" 3#include "list.h"
4 4
5struct tree_buffer { 5struct btrfs_buffer {
6 u64 blocknr; 6 u64 blocknr;
7 int count; 7 int count;
8 union { 8 union {
9 struct node node; 9 struct btrfs_node node;
10 struct leaf leaf; 10 struct btrfs_leaf leaf;
11 }; 11 };
12 struct list_head dirty; 12 struct list_head dirty;
13 struct list_head cache; 13 struct list_head cache;
14}; 14};
15 15
16struct tree_buffer *read_tree_block(struct ctree_root *root, u64 blocknr); 16struct btrfs_buffer *read_tree_block(struct btrfs_root *root, u64 blocknr);
17struct tree_buffer *find_tree_block(struct ctree_root *root, u64 blocknr); 17struct btrfs_buffer *find_tree_block(struct btrfs_root *root, u64 blocknr);
18int write_tree_block(struct ctree_root *root, struct tree_buffer *buf); 18int write_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf);
19int dirty_tree_block(struct ctree_root *root, struct tree_buffer *buf); 19int dirty_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf);
20int clean_tree_block(struct ctree_root *root, struct tree_buffer *buf); 20int clean_tree_block(struct btrfs_root *root, struct btrfs_buffer *buf);
21int commit_transaction(struct ctree_root *root, struct ctree_super_block *s); 21int btrfs_commit_transaction(struct btrfs_root *root,
22struct ctree_root *open_ctree(char *filename, struct ctree_super_block *s); 22 struct btrfs_super_block *s);
23int close_ctree(struct ctree_root *root, struct ctree_super_block *s); 23struct btrfs_root *open_ctree(char *filename, struct btrfs_super_block *s);
24void tree_block_release(struct ctree_root *root, struct tree_buffer *buf); 24int close_ctree(struct btrfs_root *root, struct btrfs_super_block *s);
25int write_ctree_super(struct ctree_root *root, struct ctree_super_block *s); 25void btrfs_block_release(struct btrfs_root *root, struct btrfs_buffer *buf);
26int write_ctree_super(struct btrfs_root *root, struct btrfs_super_block *s);
26int mkfs(int fd); 27int mkfs(int fd);
27 28
28#define CTREE_SUPER_INFO_OFFSET(bs) (16 * (bs)) 29#define BTRFS_SUPER_INFO_OFFSET(bs) (16 * (bs))
29 30
30#endif 31#endif
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 1676a6595cc..4a4f2d810d9 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -6,11 +6,11 @@
6#include "disk-io.h" 6#include "disk-io.h"
7#include "print-tree.h" 7#include "print-tree.h"
8 8
9static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks, 9static int find_free_extent(struct btrfs_root *orig_root, u64 num_blocks,
10 u64 search_start, u64 search_end, 10 u64 search_start, u64 search_end,
11 struct btrfs_key *ins); 11 struct btrfs_key *ins);
12static int finish_current_insert(struct ctree_root *extent_root); 12static int finish_current_insert(struct btrfs_root *extent_root);
13static int run_pending(struct ctree_root *extent_root); 13static int run_pending(struct btrfs_root *extent_root);
14 14
15/* 15/*
16 * pending extents are blocks that we're trying to allocate in the extent 16 * pending extents are blocks that we're trying to allocate in the extent
@@ -21,62 +21,63 @@ static int run_pending(struct ctree_root *extent_root);
21 */ 21 */
22#define CTREE_EXTENT_PENDING_DEL 0 22#define CTREE_EXTENT_PENDING_DEL 0
23 23
24static int inc_block_ref(struct ctree_root *root, u64 blocknr) 24static int inc_block_ref(struct btrfs_root *root, u64 blocknr)
25{ 25{
26 struct ctree_path path; 26 struct btrfs_path path;
27 int ret; 27 int ret;
28 struct btrfs_key key; 28 struct btrfs_key key;
29 struct leaf *l; 29 struct btrfs_leaf *l;
30 struct extent_item *item; 30 struct btrfs_extent_item *item;
31 struct btrfs_key ins; 31 struct btrfs_key ins;
32 u32 refs; 32 u32 refs;
33 33
34 find_free_extent(root->extent_root, 0, 0, (u64)-1, &ins); 34 find_free_extent(root->extent_root, 0, 0, (u64)-1, &ins);
35 init_path(&path); 35 btrfs_init_path(&path);
36 key.objectid = blocknr; 36 key.objectid = blocknr;
37 key.flags = 0; 37 key.flags = 0;
38 key.offset = 1; 38 key.offset = 1;
39 ret = search_slot(root->extent_root, &key, &path, 0, 1); 39 ret = btrfs_search_slot(root->extent_root, &key, &path, 0, 1);
40 if (ret != 0) 40 if (ret != 0)
41 BUG(); 41 BUG();
42 BUG_ON(ret != 0); 42 BUG_ON(ret != 0);
43 l = &path.nodes[0]->leaf; 43 l = &path.nodes[0]->leaf;
44 item = (struct extent_item *)(l->data + btrfs_item_offset(l->items + 44 item = (struct btrfs_extent_item *)(l->data +
45 path.slots[0])); 45 btrfs_item_offset(l->items +
46 path.slots[0]));
46 refs = btrfs_extent_refs(item); 47 refs = btrfs_extent_refs(item);
47 btrfs_set_extent_refs(item, refs + 1); 48 btrfs_set_extent_refs(item, refs + 1);
48 49
49 BUG_ON(list_empty(&path.nodes[0]->dirty)); 50 BUG_ON(list_empty(&path.nodes[0]->dirty));
50 release_path(root->extent_root, &path); 51 btrfs_release_path(root->extent_root, &path);
51 finish_current_insert(root->extent_root); 52 finish_current_insert(root->extent_root);
52 run_pending(root->extent_root); 53 run_pending(root->extent_root);
53 return 0; 54 return 0;
54} 55}
55 56
56static int lookup_block_ref(struct ctree_root *root, u64 blocknr, u32 *refs) 57static int lookup_block_ref(struct btrfs_root *root, u64 blocknr, u32 *refs)
57{ 58{
58 struct ctree_path path; 59 struct btrfs_path path;
59 int ret; 60 int ret;
60 struct btrfs_key key; 61 struct btrfs_key key;
61 struct leaf *l; 62 struct btrfs_leaf *l;
62 struct extent_item *item; 63 struct btrfs_extent_item *item;
63 init_path(&path); 64 btrfs_init_path(&path);
64 key.objectid = blocknr; 65 key.objectid = blocknr;
65 key.flags = 0; 66 key.flags = 0;
66 key.offset = 1; 67 key.offset = 1;
67 ret = search_slot(root->extent_root, &key, &path, 0, 0); 68 ret = btrfs_search_slot(root->extent_root, &key, &path, 0, 0);
68 if (ret != 0) 69 if (ret != 0)
69 BUG(); 70 BUG();
70 l = &path.nodes[0]->leaf; 71 l = &path.nodes[0]->leaf;
71 item = (struct extent_item *)(l->data + 72 item = (struct btrfs_extent_item *)(l->data +
72 btrfs_item_offset(l->items + 73 btrfs_item_offset(l->items +
73 path.slots[0])); 74 path.slots[0]));
74 *refs = btrfs_extent_refs(item); 75 *refs = btrfs_extent_refs(item);
75 release_path(root->extent_root, &path); 76 btrfs_release_path(root->extent_root, &path);
76 return 0; 77 return 0;
77} 78}
78 79
79int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf) 80int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf)
80{ 81{
81 u64 blocknr; 82 u64 blocknr;
82 int i; 83 int i;
@@ -93,9 +94,9 @@ int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf)
93 return 0; 94 return 0;
94} 95}
95 96
96int btrfs_finish_extent_commit(struct ctree_root *root) 97int btrfs_finish_extent_commit(struct btrfs_root *root)
97{ 98{
98 struct ctree_root *extent_root = root->extent_root; 99 struct btrfs_root *extent_root = root->extent_root;
99 unsigned long gang[8]; 100 unsigned long gang[8];
100 int ret; 101 int ret;
101 int i; 102 int i;
@@ -115,10 +116,10 @@ int btrfs_finish_extent_commit(struct ctree_root *root)
115 return 0; 116 return 0;
116} 117}
117 118
118static int finish_current_insert(struct ctree_root *extent_root) 119static int finish_current_insert(struct btrfs_root *extent_root)
119{ 120{
120 struct btrfs_key ins; 121 struct btrfs_key ins;
121 struct extent_item extent_item; 122 struct btrfs_extent_item extent_item;
122 int i; 123 int i;
123 int ret; 124 int ret;
124 125
@@ -130,7 +131,7 @@ static int finish_current_insert(struct ctree_root *extent_root)
130 131
131 for (i = 0; i < extent_root->current_insert.flags; i++) { 132 for (i = 0; i < extent_root->current_insert.flags; i++) {
132 ins.objectid = extent_root->current_insert.objectid + i; 133 ins.objectid = extent_root->current_insert.objectid + i;
133 ret = insert_item(extent_root, &ins, &extent_item, 134 ret = btrfs_insert_item(extent_root, &ins, &extent_item,
134 sizeof(extent_item)); 135 sizeof(extent_item));
135 BUG_ON(ret); 136 BUG_ON(ret);
136 } 137 }
@@ -141,14 +142,14 @@ static int finish_current_insert(struct ctree_root *extent_root)
141/* 142/*
142 * remove an extent from the root, returns 0 on success 143 * remove an extent from the root, returns 0 on success
143 */ 144 */
144int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks) 145static int __free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks)
145{ 146{
146 struct ctree_path path; 147 struct btrfs_path path;
147 struct btrfs_key key; 148 struct btrfs_key key;
148 struct ctree_root *extent_root = root->extent_root; 149 struct btrfs_root *extent_root = root->extent_root;
149 int ret; 150 int ret;
150 struct btrfs_item *item; 151 struct btrfs_item *item;
151 struct extent_item *ei; 152 struct btrfs_extent_item *ei;
152 struct btrfs_key ins; 153 struct btrfs_key ins;
153 u32 refs; 154 u32 refs;
154 155
@@ -157,16 +158,16 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
157 key.offset = num_blocks; 158 key.offset = num_blocks;
158 159
159 find_free_extent(root, 0, 0, (u64)-1, &ins); 160 find_free_extent(root, 0, 0, (u64)-1, &ins);
160 init_path(&path); 161 btrfs_init_path(&path);
161 ret = search_slot(extent_root, &key, &path, -1, 1); 162 ret = btrfs_search_slot(extent_root, &key, &path, -1, 1);
162 if (ret) { 163 if (ret) {
163 printf("failed to find %Lu\n", key.objectid); 164 printf("failed to find %Lu\n", key.objectid);
164 print_tree(extent_root, extent_root->node); 165 btrfs_print_tree(extent_root, extent_root->node);
165 printf("failed to find %Lu\n", key.objectid); 166 printf("failed to find %Lu\n", key.objectid);
166 BUG(); 167 BUG();
167 } 168 }
168 item = path.nodes[0]->leaf.items + path.slots[0]; 169 item = path.nodes[0]->leaf.items + path.slots[0];
169 ei = (struct extent_item *)(path.nodes[0]->leaf.data + 170 ei = (struct btrfs_extent_item *)(path.nodes[0]->leaf.data +
170 btrfs_item_offset(item)); 171 btrfs_item_offset(item));
171 BUG_ON(ei->refs == 0); 172 BUG_ON(ei->refs == 0);
172 refs = btrfs_extent_refs(ei) - 1; 173 refs = btrfs_extent_refs(ei) - 1;
@@ -180,14 +181,14 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
180 BUG_ON(err); 181 BUG_ON(err);
181 radix_tree_preload_end(); 182 radix_tree_preload_end();
182 } 183 }
183 ret = del_item(extent_root, &path); 184 ret = btrfs_del_item(extent_root, &path);
184 if (root != extent_root && 185 if (root != extent_root &&
185 extent_root->last_insert.objectid < blocknr) 186 extent_root->last_insert.objectid < blocknr)
186 extent_root->last_insert.objectid = blocknr; 187 extent_root->last_insert.objectid = blocknr;
187 if (ret) 188 if (ret)
188 BUG(); 189 BUG();
189 } 190 }
190 release_path(extent_root, &path); 191 btrfs_release_path(extent_root, &path);
191 finish_current_insert(extent_root); 192 finish_current_insert(extent_root);
192 return ret; 193 return ret;
193} 194}
@@ -196,10 +197,10 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
196 * find all the blocks marked as pending in the radix tree and remove 197 * find all the blocks marked as pending in the radix tree and remove
197 * them from the extent map 198 * them from the extent map
198 */ 199 */
199static int del_pending_extents(struct ctree_root *extent_root) 200static int del_pending_extents(struct btrfs_root *extent_root)
200{ 201{
201 int ret; 202 int ret;
202 struct tree_buffer *gang[4]; 203 struct btrfs_buffer *gang[4];
203 int i; 204 int i;
204 205
205 while(1) { 206 while(1) {
@@ -214,13 +215,13 @@ static int del_pending_extents(struct ctree_root *extent_root)
214 radix_tree_tag_clear(&extent_root->cache_radix, 215 radix_tree_tag_clear(&extent_root->cache_radix,
215 gang[i]->blocknr, 216 gang[i]->blocknr,
216 CTREE_EXTENT_PENDING_DEL); 217 CTREE_EXTENT_PENDING_DEL);
217 tree_block_release(extent_root, gang[i]); 218 btrfs_block_release(extent_root, gang[i]);
218 } 219 }
219 } 220 }
220 return 0; 221 return 0;
221} 222}
222 223
223static int run_pending(struct ctree_root *extent_root) 224static int run_pending(struct btrfs_root *extent_root)
224{ 225{
225 while(radix_tree_tagged(&extent_root->cache_radix, 226 while(radix_tree_tagged(&extent_root->cache_radix,
226 CTREE_EXTENT_PENDING_DEL)) 227 CTREE_EXTENT_PENDING_DEL))
@@ -232,11 +233,11 @@ static int run_pending(struct ctree_root *extent_root)
232/* 233/*
233 * remove an extent from the root, returns 0 on success 234 * remove an extent from the root, returns 0 on success
234 */ 235 */
235int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks) 236int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks)
236{ 237{
237 struct btrfs_key key; 238 struct btrfs_key key;
238 struct ctree_root *extent_root = root->extent_root; 239 struct btrfs_root *extent_root = root->extent_root;
239 struct tree_buffer *t; 240 struct btrfs_buffer *t;
240 int pending_ret; 241 int pending_ret;
241 int ret; 242 int ret;
242 243
@@ -262,11 +263,11 @@ int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks)
262 * ins->offset == number of blocks 263 * ins->offset == number of blocks
263 * Any available blocks before search_start are skipped. 264 * Any available blocks before search_start are skipped.
264 */ 265 */
265static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks, 266static int find_free_extent(struct btrfs_root *orig_root, u64 num_blocks,
266 u64 search_start, u64 search_end, 267 u64 search_start, u64 search_end,
267 struct btrfs_key *ins) 268 struct btrfs_key *ins)
268{ 269{
269 struct ctree_path path; 270 struct btrfs_path path;
270 struct btrfs_key key; 271 struct btrfs_key key;
271 int ret; 272 int ret;
272 u64 hole_size = 0; 273 u64 hole_size = 0;
@@ -274,20 +275,20 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
274 u64 last_block; 275 u64 last_block;
275 u64 test_block; 276 u64 test_block;
276 int start_found; 277 int start_found;
277 struct leaf *l; 278 struct btrfs_leaf *l;
278 struct ctree_root * root = orig_root->extent_root; 279 struct btrfs_root * root = orig_root->extent_root;
279 int total_needed = num_blocks; 280 int total_needed = num_blocks;
280 281
281 total_needed += (btrfs_header_level(&root->node->node.header) + 1) * 3; 282 total_needed += (btrfs_header_level(&root->node->node.header) + 1) * 3;
282 if (root->last_insert.objectid > search_start) 283 if (root->last_insert.objectid > search_start)
283 search_start = root->last_insert.objectid; 284 search_start = root->last_insert.objectid;
284check_failed: 285check_failed:
285 init_path(&path); 286 btrfs_init_path(&path);
286 ins->objectid = search_start; 287 ins->objectid = search_start;
287 ins->offset = 0; 288 ins->offset = 0;
288 ins->flags = 0; 289 ins->flags = 0;
289 start_found = 0; 290 start_found = 0;
290 ret = search_slot(root, ins, &path, 0, 0); 291 ret = btrfs_search_slot(root, ins, &path, 0, 0);
291 if (ret < 0) 292 if (ret < 0)
292 goto error; 293 goto error;
293 294
@@ -298,7 +299,7 @@ check_failed:
298 l = &path.nodes[0]->leaf; 299 l = &path.nodes[0]->leaf;
299 slot = path.slots[0]; 300 slot = path.slots[0];
300 if (slot >= btrfs_header_nritems(&l->header)) { 301 if (slot >= btrfs_header_nritems(&l->header)) {
301 ret = next_leaf(root, &path); 302 ret = btrfs_next_leaf(root, &path);
302 if (ret == 0) 303 if (ret == 0)
303 continue; 304 continue;
304 if (ret < 0) 305 if (ret < 0)
@@ -336,7 +337,7 @@ check_pending:
336 /* we have to make sure we didn't find an extent that has already 337 /* we have to make sure we didn't find an extent that has already
337 * been allocated by the map tree or the original allocation 338 * been allocated by the map tree or the original allocation
338 */ 339 */
339 release_path(root, &path); 340 btrfs_release_path(root, &path);
340 BUG_ON(ins->objectid < search_start); 341 BUG_ON(ins->objectid < search_start);
341 for (test_block = ins->objectid; 342 for (test_block = ins->objectid;
342 test_block < ins->objectid + total_needed; test_block++) { 343 test_block < ins->objectid + total_needed; test_block++) {
@@ -353,7 +354,7 @@ check_pending:
353 ins->offset = num_blocks; 354 ins->offset = num_blocks;
354 return 0; 355 return 0;
355error: 356error:
356 release_path(root, &path); 357 btrfs_release_path(root, &path);
357 return ret; 358 return ret;
358} 359}
359 360
@@ -364,13 +365,13 @@ error:
364 * 365 *
365 * returns 0 if everything worked, non-zero otherwise. 366 * returns 0 if everything worked, non-zero otherwise.
366 */ 367 */
367int alloc_extent(struct ctree_root *root, u64 num_blocks, u64 search_start, 368int alloc_extent(struct btrfs_root *root, u64 num_blocks, u64 search_start,
368 u64 search_end, u64 owner, struct btrfs_key *ins) 369 u64 search_end, u64 owner, struct btrfs_key *ins)
369{ 370{
370 int ret; 371 int ret;
371 int pending_ret; 372 int pending_ret;
372 struct ctree_root *extent_root = root->extent_root; 373 struct btrfs_root *extent_root = root->extent_root;
373 struct extent_item extent_item; 374 struct btrfs_extent_item extent_item;
374 375
375 btrfs_set_extent_refs(&extent_item, 1); 376 btrfs_set_extent_refs(&extent_item, 1);
376 btrfs_set_extent_owner(&extent_item, owner); 377 btrfs_set_extent_owner(&extent_item, owner);
@@ -390,7 +391,7 @@ int alloc_extent(struct ctree_root *root, u64 num_blocks, u64 search_start,
390 if (ret) 391 if (ret)
391 return ret; 392 return ret;
392 393
393 ret = insert_item(extent_root, ins, &extent_item, 394 ret = btrfs_insert_item(extent_root, ins, &extent_item,
394 sizeof(extent_item)); 395 sizeof(extent_item));
395 396
396 finish_current_insert(extent_root); 397 finish_current_insert(extent_root);
@@ -406,11 +407,11 @@ int alloc_extent(struct ctree_root *root, u64 num_blocks, u64 search_start,
406 * helper function to allocate a block for a given tree 407 * helper function to allocate a block for a given tree
407 * returns the tree buffer or NULL. 408 * returns the tree buffer or NULL.
408 */ 409 */
409struct tree_buffer *alloc_free_block(struct ctree_root *root) 410struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root)
410{ 411{
411 struct btrfs_key ins; 412 struct btrfs_key ins;
412 int ret; 413 int ret;
413 struct tree_buffer *buf; 414 struct btrfs_buffer *buf;
414 415
415 ret = alloc_extent(root, 1, 0, (unsigned long)-1, 416 ret = alloc_extent(root, 1, 0, (unsigned long)-1,
416 btrfs_header_parentid(&root->node->node.header), 417 btrfs_header_parentid(&root->node->node.header),
@@ -424,10 +425,10 @@ struct tree_buffer *alloc_free_block(struct ctree_root *root)
424 return buf; 425 return buf;
425} 426}
426 427
427int walk_down_tree(struct ctree_root *root, struct ctree_path *path, int *level) 428int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path, int *level)
428{ 429{
429 struct tree_buffer *next; 430 struct btrfs_buffer *next;
430 struct tree_buffer *cur; 431 struct btrfs_buffer *cur;
431 u64 blocknr; 432 u64 blocknr;
432 int ret; 433 int ret;
433 u32 refs; 434 u32 refs;
@@ -445,33 +446,33 @@ int walk_down_tree(struct ctree_root *root, struct ctree_path *path, int *level)
445 ret = lookup_block_ref(root, blocknr, &refs); 446 ret = lookup_block_ref(root, blocknr, &refs);
446 if (refs != 1 || *level == 1) { 447 if (refs != 1 || *level == 1) {
447 path->slots[*level]++; 448 path->slots[*level]++;
448 ret = free_extent(root, blocknr, 1); 449 ret = btrfs_free_extent(root, blocknr, 1);
449 BUG_ON(ret); 450 BUG_ON(ret);
450 continue; 451 continue;
451 } 452 }
452 BUG_ON(ret); 453 BUG_ON(ret);
453 next = read_tree_block(root, blocknr); 454 next = read_tree_block(root, blocknr);
454 if (path->nodes[*level-1]) 455 if (path->nodes[*level-1])
455 tree_block_release(root, path->nodes[*level-1]); 456 btrfs_block_release(root, path->nodes[*level-1]);
456 path->nodes[*level-1] = next; 457 path->nodes[*level-1] = next;
457 *level = btrfs_header_level(&next->node.header); 458 *level = btrfs_header_level(&next->node.header);
458 path->slots[*level] = 0; 459 path->slots[*level] = 0;
459 } 460 }
460out: 461out:
461 ret = free_extent(root, path->nodes[*level]->blocknr, 1); 462 ret = btrfs_free_extent(root, path->nodes[*level]->blocknr, 1);
462 tree_block_release(root, path->nodes[*level]); 463 btrfs_block_release(root, path->nodes[*level]);
463 path->nodes[*level] = NULL; 464 path->nodes[*level] = NULL;
464 *level += 1; 465 *level += 1;
465 BUG_ON(ret); 466 BUG_ON(ret);
466 return 0; 467 return 0;
467} 468}
468 469
469int walk_up_tree(struct ctree_root *root, struct ctree_path *path, int *level) 470int walk_up_tree(struct btrfs_root *root, struct btrfs_path *path, int *level)
470{ 471{
471 int i; 472 int i;
472 int slot; 473 int slot;
473 int ret; 474 int ret;
474 for(i = *level; i < MAX_LEVEL - 1 && path->nodes[i]; i++) { 475 for(i = *level; i < BTRFS_MAX_LEVEL - 1 && path->nodes[i]; i++) {
475 slot = path->slots[i]; 476 slot = path->slots[i];
476 if (slot < 477 if (slot <
477 btrfs_header_nritems(&path->nodes[i]->node.header)- 1) { 478 btrfs_header_nritems(&path->nodes[i]->node.header)- 1) {
@@ -479,9 +480,9 @@ int walk_up_tree(struct ctree_root *root, struct ctree_path *path, int *level)
479 *level = i; 480 *level = i;
480 return 0; 481 return 0;
481 } else { 482 } else {
482 ret = free_extent(root, 483 ret = btrfs_free_extent(root,
483 path->nodes[*level]->blocknr, 1); 484 path->nodes[*level]->blocknr, 1);
484 tree_block_release(root, path->nodes[*level]); 485 btrfs_block_release(root, path->nodes[*level]);
485 path->nodes[*level] = NULL; 486 path->nodes[*level] = NULL;
486 *level = i + 1; 487 *level = i + 1;
487 BUG_ON(ret); 488 BUG_ON(ret);
@@ -490,15 +491,15 @@ int walk_up_tree(struct ctree_root *root, struct ctree_path *path, int *level)
490 return 1; 491 return 1;
491} 492}
492 493
493int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap) 494int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap)
494{ 495{
495 int ret; 496 int ret;
496 int level; 497 int level;
497 struct ctree_path path; 498 struct btrfs_path path;
498 int i; 499 int i;
499 int orig_level; 500 int orig_level;
500 501
501 init_path(&path); 502 btrfs_init_path(&path);
502 503
503 level = btrfs_header_level(&snap->node.header); 504 level = btrfs_header_level(&snap->node.header);
504 orig_level = level; 505 orig_level = level;
@@ -514,7 +515,7 @@ int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap)
514 } 515 }
515 for (i = 0; i <= orig_level; i++) { 516 for (i = 0; i <= orig_level; i++) {
516 if (path.nodes[i]) { 517 if (path.nodes[i]) {
517 tree_block_release(root, path.nodes[i]); 518 btrfs_block_release(root, path.nodes[i]);
518 } 519 }
519 } 520 }
520 521
diff --git a/fs/btrfs/mkfs.c b/fs/btrfs/mkfs.c
index e0d3bc1d025..fc1923320de 100644
--- a/fs/btrfs/mkfs.c
+++ b/fs/btrfs/mkfs.c
@@ -12,10 +12,10 @@
12 12
13int mkfs(int fd) 13int mkfs(int fd)
14{ 14{
15 struct ctree_root_info info[2]; 15 struct btrfs_root_info info[2];
16 struct leaf empty_leaf; 16 struct btrfs_leaf empty_leaf;
17 struct btrfs_item item; 17 struct btrfs_item item;
18 struct extent_item extent_item; 18 struct btrfs_extent_item extent_item;
19 int ret; 19 int ret;
20 20
21 /* setup the super block area */ 21 /* setup the super block area */
@@ -28,7 +28,7 @@ int mkfs(int fd)
28 info[1].objectid = 2; 28 info[1].objectid = 2;
29 info[1].tree_root = 18; 29 info[1].tree_root = 18;
30 ret = pwrite(fd, info, sizeof(info), 30 ret = pwrite(fd, info, sizeof(info),
31 CTREE_SUPER_INFO_OFFSET(CTREE_BLOCKSIZE)); 31 BTRFS_SUPER_INFO_OFFSET(BTRFS_BLOCKSIZE));
32 if (ret != sizeof(info)) 32 if (ret != sizeof(info))
33 return -1; 33 return -1;
34 34
@@ -36,7 +36,7 @@ int mkfs(int fd)
36 memset(&empty_leaf, 0, sizeof(empty_leaf)); 36 memset(&empty_leaf, 0, sizeof(empty_leaf));
37 btrfs_set_header_parentid(&empty_leaf.header, 1); 37 btrfs_set_header_parentid(&empty_leaf.header, 1);
38 btrfs_set_header_blocknr(&empty_leaf.header, 17); 38 btrfs_set_header_blocknr(&empty_leaf.header, 17);
39 ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 17 * CTREE_BLOCKSIZE); 39 ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 17 * BTRFS_BLOCKSIZE);
40 if (ret != sizeof(empty_leaf)) 40 if (ret != sizeof(empty_leaf))
41 return -1; 41 return -1;
42 42
@@ -48,9 +48,9 @@ int mkfs(int fd)
48 btrfs_set_key_objectid(&item.key, 0); 48 btrfs_set_key_objectid(&item.key, 0);
49 btrfs_set_key_offset(&item.key, 17); 49 btrfs_set_key_offset(&item.key, 17);
50 btrfs_set_key_flags(&item.key, 0); 50 btrfs_set_key_flags(&item.key, 0);
51 btrfs_set_item_offset(&item, 51 btrfs_set_item_offset(&item, LEAF_DATA_SIZE -
52 LEAF_DATA_SIZE - sizeof(struct extent_item)); 52 sizeof(struct btrfs_extent_item));
53 btrfs_set_item_size(&item, sizeof(struct extent_item)); 53 btrfs_set_item_size(&item, sizeof(struct btrfs_extent_item));
54 btrfs_set_extent_refs(&extent_item, 1); 54 btrfs_set_extent_refs(&extent_item, 1);
55 btrfs_set_extent_owner(&extent_item, 0); 55 btrfs_set_extent_owner(&extent_item, 0);
56 memcpy(empty_leaf.items, &item, sizeof(item)); 56 memcpy(empty_leaf.items, &item, sizeof(item));
@@ -60,8 +60,8 @@ int mkfs(int fd)
60 /* item2, give block 17 to the root */ 60 /* item2, give block 17 to the root */
61 btrfs_set_key_objectid(&item.key, 17); 61 btrfs_set_key_objectid(&item.key, 17);
62 btrfs_set_key_offset(&item.key, 1); 62 btrfs_set_key_offset(&item.key, 1);
63 btrfs_set_item_offset(&item, 63 btrfs_set_item_offset(&item, LEAF_DATA_SIZE -
64 LEAF_DATA_SIZE - sizeof(struct extent_item) * 2); 64 sizeof(struct btrfs_extent_item) * 2);
65 btrfs_set_extent_owner(&extent_item, 1); 65 btrfs_set_extent_owner(&extent_item, 1);
66 memcpy(empty_leaf.items + 1, &item, sizeof(item)); 66 memcpy(empty_leaf.items + 1, &item, sizeof(item));
67 memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item, 67 memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item,
@@ -70,13 +70,13 @@ int mkfs(int fd)
70 /* item3, give block 18 for the extent root */ 70 /* item3, give block 18 for the extent root */
71 btrfs_set_key_objectid(&item.key, 18); 71 btrfs_set_key_objectid(&item.key, 18);
72 btrfs_set_key_offset(&item.key, 1); 72 btrfs_set_key_offset(&item.key, 1);
73 btrfs_set_item_offset(&item, 73 btrfs_set_item_offset(&item, LEAF_DATA_SIZE -
74 LEAF_DATA_SIZE - sizeof(struct extent_item) * 3); 74 sizeof(struct btrfs_extent_item) * 3);
75 btrfs_set_extent_owner(&extent_item, 2); 75 btrfs_set_extent_owner(&extent_item, 2);
76 memcpy(empty_leaf.items + 2, &item, sizeof(item)); 76 memcpy(empty_leaf.items + 2, &item, sizeof(item));
77 memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item, 77 memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item,
78 btrfs_item_size(&item)); 78 btrfs_item_size(&item));
79 ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 18 * CTREE_BLOCKSIZE); 79 ret = pwrite(fd, &empty_leaf, sizeof(empty_leaf), 18 * BTRFS_BLOCKSIZE);
80 if (ret != sizeof(empty_leaf)) 80 if (ret != sizeof(empty_leaf))
81 return -1; 81 return -1;
82 return 0; 82 return 0;
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 101278e1139..c95c85640aa 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -5,14 +5,14 @@
5#include "ctree.h" 5#include "ctree.h"
6#include "disk-io.h" 6#include "disk-io.h"
7 7
8void print_leaf(struct leaf *l) 8void btrfs_print_leaf(struct btrfs_leaf *l)
9{ 9{
10 int i; 10 int i;
11 u32 nr = btrfs_header_nritems(&l->header); 11 u32 nr = btrfs_header_nritems(&l->header);
12 struct btrfs_item *item; 12 struct btrfs_item *item;
13 struct extent_item *ei; 13 struct btrfs_extent_item *ei;
14 printf("leaf %Lu total ptrs %d free space %d\n", 14 printf("leaf %Lu total ptrs %d free space %d\n",
15 btrfs_header_blocknr(&l->header), nr, leaf_free_space(l)); 15 btrfs_header_blocknr(&l->header), nr, btrfs_leaf_free_space(l));
16 fflush(stdout); 16 fflush(stdout);
17 for (i = 0 ; i < nr ; i++) { 17 for (i = 0 ; i < nr ; i++) {
18 item = l->items + i; 18 item = l->items + i;
@@ -26,24 +26,25 @@ void print_leaf(struct leaf *l)
26 fflush(stdout); 26 fflush(stdout);
27 printf("\t\titem data %.*s\n", btrfs_item_size(item), 27 printf("\t\titem data %.*s\n", btrfs_item_size(item),
28 l->data + btrfs_item_offset(item)); 28 l->data + btrfs_item_offset(item));
29 ei = (struct extent_item *)(l->data + btrfs_item_offset(item)); 29 ei = (struct btrfs_extent_item *)(l->data +
30 btrfs_item_offset(item));
30 printf("\t\textent data refs %u owner %Lu\n", ei->refs, 31 printf("\t\textent data refs %u owner %Lu\n", ei->refs,
31 ei->owner); 32 ei->owner);
32 fflush(stdout); 33 fflush(stdout);
33 } 34 }
34} 35}
35void print_tree(struct ctree_root *root, struct tree_buffer *t) 36void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
36{ 37{
37 int i; 38 int i;
38 u32 nr; 39 u32 nr;
39 struct node *c; 40 struct btrfs_node *c;
40 41
41 if (!t) 42 if (!t)
42 return; 43 return;
43 c = &t->node; 44 c = &t->node;
44 nr = btrfs_header_nritems(&c->header); 45 nr = btrfs_header_nritems(&c->header);
45 if (btrfs_is_leaf(c)) { 46 if (btrfs_is_leaf(c)) {
46 print_leaf((struct leaf *)c); 47 btrfs_print_leaf((struct btrfs_leaf *)c);
47 return; 48 return;
48 } 49 }
49 printf("node %Lu level %d total ptrs %d free spc %u\n", t->blocknr, 50 printf("node %Lu level %d total ptrs %d free spc %u\n", t->blocknr,
@@ -58,17 +59,17 @@ void print_tree(struct ctree_root *root, struct tree_buffer *t)
58 fflush(stdout); 59 fflush(stdout);
59 } 60 }
60 for (i = 0; i < nr; i++) { 61 for (i = 0; i < nr; i++) {
61 struct tree_buffer *next_buf = read_tree_block(root, 62 struct btrfs_buffer *next_buf = read_tree_block(root,
62 btrfs_node_blockptr(c, i)); 63 btrfs_node_blockptr(c, i));
63 struct node *next = &next_buf->node; 64 struct btrfs_node *next = &next_buf->node;
64 if (btrfs_is_leaf(next) && 65 if (btrfs_is_leaf(next) &&
65 btrfs_header_level(&c->header) != 1) 66 btrfs_header_level(&c->header) != 1)
66 BUG(); 67 BUG();
67 if (btrfs_header_level(&next->header) != 68 if (btrfs_header_level(&next->header) !=
68 btrfs_header_level(&c->header) - 1) 69 btrfs_header_level(&c->header) - 1)
69 BUG(); 70 BUG();
70 print_tree(root, next_buf); 71 btrfs_print_tree(root, next_buf);
71 tree_block_release(root, next_buf); 72 btrfs_block_release(root, next_buf);
72 } 73 }
73 74
74} 75}
diff --git a/fs/btrfs/print-tree.h b/fs/btrfs/print-tree.h
index 3c1e9a3e026..e8d0b847c02 100644
--- a/fs/btrfs/print-tree.h
+++ b/fs/btrfs/print-tree.h
@@ -1,3 +1,3 @@
1 1
2void print_leaf(struct leaf *l); 2void btrfs_print_leaf(struct btrfs_leaf *l);
3void print_tree(struct ctree_root *root, struct tree_buffer *t); 3void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t);
diff --git a/fs/btrfs/quick-test.c b/fs/btrfs/quick-test.c
index ab3bda53a2f..66bdc57905d 100644
--- a/fs/btrfs/quick-test.c
+++ b/fs/btrfs/quick-test.c
@@ -22,9 +22,9 @@ int main(int ac, char **av) {
22 int run_size = 100000; 22 int run_size = 100000;
23 int max_key = 100000000; 23 int max_key = 100000000;
24 int tree_size = 0; 24 int tree_size = 0;
25 struct ctree_path path; 25 struct btrfs_path path;
26 struct ctree_super_block super; 26 struct btrfs_super_block super;
27 struct ctree_root *root; 27 struct btrfs_root *root;
28 28
29 radix_tree_init(); 29 radix_tree_init();
30 30
@@ -40,12 +40,12 @@ int main(int ac, char **av) {
40 ins.objectid = num; 40 ins.objectid = num;
41 ins.offset = 0; 41 ins.offset = 0;
42 ins.flags = 0; 42 ins.flags = 0;
43 ret = insert_item(root, &ins, buf, strlen(buf)); 43 ret = btrfs_insert_item(root, &ins, buf, strlen(buf));
44 if (!ret) 44 if (!ret)
45 tree_size++; 45 tree_size++;
46 free(buf); 46 free(buf);
47 if (i == run_size - 5) { 47 if (i == run_size - 5) {
48 commit_transaction(root, &super); 48 btrfs_commit_transaction(root, &super);
49 } 49 }
50 50
51 } 51 }
@@ -57,16 +57,16 @@ int main(int ac, char **av) {
57 for (i = 0; i < run_size; i++) { 57 for (i = 0; i < run_size; i++) {
58 num = next_key(i, max_key); 58 num = next_key(i, max_key);
59 ins.objectid = num; 59 ins.objectid = num;
60 init_path(&path); 60 btrfs_init_path(&path);
61 if (i % 10000 == 0) 61 if (i % 10000 == 0)
62 fprintf(stderr, "search %d:%d\n", num, i); 62 fprintf(stderr, "search %d:%d\n", num, i);
63 ret = search_slot(root, &ins, &path, 0, 0); 63 ret = btrfs_search_slot(root, &ins, &path, 0, 0);
64 if (ret) { 64 if (ret) {
65 print_tree(root, root->node); 65 btrfs_print_tree(root, root->node);
66 printf("unable to find %d\n", num); 66 printf("unable to find %d\n", num);
67 exit(1); 67 exit(1);
68 } 68 }
69 release_path(root, &path); 69 btrfs_release_path(root, &path);
70 } 70 }
71 close_ctree(root, &super); 71 close_ctree(root, &super);
72 root = open_ctree("dbfile", &super); 72 root = open_ctree("dbfile", &super);
@@ -81,17 +81,17 @@ int main(int ac, char **av) {
81 for (i = 0 ; i < run_size/4; i++) { 81 for (i = 0 ; i < run_size/4; i++) {
82 num = next_key(i, max_key); 82 num = next_key(i, max_key);
83 ins.objectid = num; 83 ins.objectid = num;
84 init_path(&path); 84 btrfs_init_path(&path);
85 ret = search_slot(root, &ins, &path, -1, 1); 85 ret = btrfs_search_slot(root, &ins, &path, -1, 1);
86 if (!ret) { 86 if (!ret) {
87 if (i % 10000 == 0) 87 if (i % 10000 == 0)
88 fprintf(stderr, "del %d:%d\n", num, i); 88 fprintf(stderr, "del %d:%d\n", num, i);
89 ret = del_item(root, &path); 89 ret = btrfs_del_item(root, &path);
90 if (ret != 0) 90 if (ret != 0)
91 BUG(); 91 BUG();
92 tree_size--; 92 tree_size--;
93 } 93 }
94 release_path(root, &path); 94 btrfs_release_path(root, &path);
95 } 95 }
96 close_ctree(root, &super); 96 close_ctree(root, &super);
97 root = open_ctree("dbfile", &super); 97 root = open_ctree("dbfile", &super);
@@ -103,7 +103,7 @@ int main(int ac, char **av) {
103 ins.objectid = num; 103 ins.objectid = num;
104 if (i % 10000 == 0) 104 if (i % 10000 == 0)
105 fprintf(stderr, "insert %d:%d\n", num, i); 105 fprintf(stderr, "insert %d:%d\n", num, i);
106 ret = insert_item(root, &ins, buf, strlen(buf)); 106 ret = btrfs_insert_item(root, &ins, buf, strlen(buf));
107 if (!ret) 107 if (!ret)
108 tree_size++; 108 tree_size++;
109 free(buf); 109 free(buf);
@@ -115,25 +115,25 @@ int main(int ac, char **av) {
115 for (i = 0; i < run_size; i++) { 115 for (i = 0; i < run_size; i++) {
116 num = next_key(i, max_key); 116 num = next_key(i, max_key);
117 ins.objectid = num; 117 ins.objectid = num;
118 init_path(&path); 118 btrfs_init_path(&path);
119 if (i % 10000 == 0) 119 if (i % 10000 == 0)
120 fprintf(stderr, "search %d:%d\n", num, i); 120 fprintf(stderr, "search %d:%d\n", num, i);
121 ret = search_slot(root, &ins, &path, 0, 0); 121 ret = btrfs_search_slot(root, &ins, &path, 0, 0);
122 if (ret) { 122 if (ret) {
123 print_tree(root, root->node); 123 btrfs_print_tree(root, root->node);
124 printf("unable to find %d\n", num); 124 printf("unable to find %d\n", num);
125 exit(1); 125 exit(1);
126 } 126 }
127 release_path(root, &path); 127 btrfs_release_path(root, &path);
128 } 128 }
129 printf("starting big long delete run\n"); 129 printf("starting big long delete run\n");
130 while(root->node && 130 while(root->node &&
131 btrfs_header_nritems(&root->node->node.header) > 0) { 131 btrfs_header_nritems(&root->node->node.header) > 0) {
132 struct leaf *leaf; 132 struct btrfs_leaf *leaf;
133 int slot; 133 int slot;
134 ins.objectid = (u64)-1; 134 ins.objectid = (u64)-1;
135 init_path(&path); 135 btrfs_init_path(&path);
136 ret = search_slot(root, &ins, &path, -1, 1); 136 ret = btrfs_search_slot(root, &ins, &path, -1, 1);
137 if (ret == 0) 137 if (ret == 0)
138 BUG(); 138 BUG();
139 139
@@ -149,26 +149,26 @@ int main(int ac, char **av) {
149 btrfs_disk_key_to_cpu(&last, &leaf->items[slot].key); 149 btrfs_disk_key_to_cpu(&last, &leaf->items[slot].key);
150 if (tree_size % 10000 == 0) 150 if (tree_size % 10000 == 0)
151 printf("big del %d:%d\n", tree_size, i); 151 printf("big del %d:%d\n", tree_size, i);
152 ret = del_item(root, &path); 152 ret = btrfs_del_item(root, &path);
153 if (ret != 0) { 153 if (ret != 0) {
154 printf("del_item returned %d\n", ret); 154 printf("del_item returned %d\n", ret);
155 BUG(); 155 BUG();
156 } 156 }
157 tree_size--; 157 tree_size--;
158 } 158 }
159 release_path(root, &path); 159 btrfs_release_path(root, &path);
160 } 160 }
161 /* 161 /*
162 printf("previous tree:\n"); 162 printf("previous tree:\n");
163 print_tree(root, root->commit_root); 163 btrfs_print_tree(root, root->commit_root);
164 printf("map before commit\n"); 164 printf("map before commit\n");
165 print_tree(root->extent_root, root->extent_root->node); 165 btrfs_print_tree(root->extent_root, root->extent_root->node);
166 */ 166 */
167 commit_transaction(root, &super); 167 btrfs_commit_transaction(root, &super);
168 printf("tree size is now %d\n", tree_size); 168 printf("tree size is now %d\n", tree_size);
169 printf("root %p commit root %p\n", root->node, root->commit_root); 169 printf("root %p commit root %p\n", root->node, root->commit_root);
170 printf("map tree\n"); 170 printf("map tree\n");
171 print_tree(root->extent_root, root->extent_root->node); 171 btrfs_print_tree(root->extent_root, root->extent_root->node);
172 close_ctree(root, &super); 172 close_ctree(root, &super);
173 return 0; 173 return 0;
174} 174}
diff --git a/fs/btrfs/random-test.c b/fs/btrfs/random-test.c
index e767528bc52..a8ef0478991 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;