aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-03-12 12:01:18 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-03-12 12:01:18 -0400
commit7518a238ea0152dc849d1ed76d3cae8b44e12f46 (patch)
tree97e5c285f10bdb2576046e7bb15d239471815c28 /fs/btrfs/extent-tree.c
parent83e15a28e046dbb4534dd263d1d3dc867a8994a2 (diff)
Btrfs: get/set for struct header fields
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c53
1 files changed, 13 insertions, 40 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index e7b8a70b5e52..524c11fea24a 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -79,10 +79,10 @@ int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf)
79 79
80 if (root == root->extent_root) 80 if (root == root->extent_root)
81 return 0; 81 return 0;
82 if (is_leaf(buf->node.header.flags)) 82 if (btrfs_is_leaf(&buf->node))
83 return 0; 83 return 0;
84 84
85 for (i = 0; i < buf->node.header.nritems; i++) { 85 for (i = 0; i < btrfs_header_nritems(&buf->node.header); i++) {
86 blocknr = buf->node.blockptrs[i]; 86 blocknr = buf->node.blockptrs[i];
87 inc_block_ref(root, blocknr); 87 inc_block_ref(root, blocknr);
88 } 88 }
@@ -119,7 +119,8 @@ static int finish_current_insert(struct ctree_root *extent_root)
119 int ret; 119 int ret;
120 120
121 extent_item.refs = 1; 121 extent_item.refs = 1;
122 extent_item.owner = extent_root->node->node.header.parentid; 122 extent_item.owner =
123 btrfs_header_parentid(&extent_root->node->node.header);
123 ins.offset = 1; 124 ins.offset = 1;
124 ins.flags = 0; 125 ins.flags = 0;
125 126
@@ -269,7 +270,7 @@ static int find_free_extent(struct ctree_root *orig_root, u64 num_blocks,
269 struct ctree_root * root = orig_root->extent_root; 270 struct ctree_root * root = orig_root->extent_root;
270 int total_needed = num_blocks; 271 int total_needed = num_blocks;
271 272
272 total_needed += (node_level(root->node->node.header.flags) + 1) * 3; 273 total_needed += (btrfs_header_level(&root->node->node.header) + 1) * 3;
273 if (root->last_insert.objectid > search_start) 274 if (root->last_insert.objectid > search_start)
274 search_start = root->last_insert.objectid; 275 search_start = root->last_insert.objectid;
275check_failed: 276check_failed:
@@ -288,7 +289,7 @@ check_failed:
288 while (1) { 289 while (1) {
289 l = &path.nodes[0]->leaf; 290 l = &path.nodes[0]->leaf;
290 slot = path.slots[0]; 291 slot = path.slots[0];
291 if (slot >= l->header.nritems) { 292 if (slot >= btrfs_header_nritems(&l->header)) {
292 ret = next_leaf(root, &path); 293 ret = next_leaf(root, &path);
293 if (ret == 0) 294 if (ret == 0)
294 continue; 295 continue;
@@ -404,7 +405,7 @@ struct tree_buffer *alloc_free_block(struct ctree_root *root)
404 struct tree_buffer *buf; 405 struct tree_buffer *buf;
405 406
406 ret = alloc_extent(root, 1, 0, (unsigned long)-1, 407 ret = alloc_extent(root, 1, 0, (unsigned long)-1,
407 root->node->node.header.parentid, 408 btrfs_header_parentid(&root->node->node.header),
408 &ins); 409 &ins);
409 if (ret) { 410 if (ret) {
410 BUG(); 411 BUG();
@@ -429,7 +430,8 @@ int walk_down_tree(struct ctree_root *root, struct ctree_path *path, int *level)
429 goto out; 430 goto out;
430 while(*level > 0) { 431 while(*level > 0) {
431 cur = path->nodes[*level]; 432 cur = path->nodes[*level];
432 if (path->slots[*level] >= cur->node.header.nritems) 433 if (path->slots[*level] >=
434 btrfs_header_nritems(&cur->node.header))
433 break; 435 break;
434 blocknr = cur->node.blockptrs[path->slots[*level]]; 436 blocknr = cur->node.blockptrs[path->slots[*level]];
435 ret = lookup_block_ref(root, blocknr, &refs); 437 ret = lookup_block_ref(root, blocknr, &refs);
@@ -444,7 +446,7 @@ int walk_down_tree(struct ctree_root *root, struct ctree_path *path, int *level)
444 if (path->nodes[*level-1]) 446 if (path->nodes[*level-1])
445 tree_block_release(root, path->nodes[*level-1]); 447 tree_block_release(root, path->nodes[*level-1]);
446 path->nodes[*level-1] = next; 448 path->nodes[*level-1] = next;
447 *level = node_level(next->node.header.flags); 449 *level = btrfs_header_level(&next->node.header);
448 path->slots[*level] = 0; 450 path->slots[*level] = 0;
449 } 451 }
450out: 452out:
@@ -463,7 +465,8 @@ int walk_up_tree(struct ctree_root *root, struct ctree_path *path, int *level)
463 int ret; 465 int ret;
464 for(i = *level; i < MAX_LEVEL - 1 && path->nodes[i]; i++) { 466 for(i = *level; i < MAX_LEVEL - 1 && path->nodes[i]; i++) {
465 slot = path->slots[i]; 467 slot = path->slots[i];
466 if (slot < path->nodes[i]->node.header.nritems - 1) { 468 if (slot <
469 btrfs_header_nritems(&path->nodes[i]->node.header)- 1) {
467 path->slots[i]++; 470 path->slots[i]++;
468 *level = i; 471 *level = i;
469 return 0; 472 return 0;
@@ -489,7 +492,7 @@ int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap)
489 492
490 init_path(&path); 493 init_path(&path);
491 494
492 level = node_level(snap->node.header.flags); 495 level = btrfs_header_level(&snap->node.header);
493 orig_level = level; 496 orig_level = level;
494 path.nodes[level] = snap; 497 path.nodes[level] = snap;
495 path.slots[level] = 0; 498 path.slots[level] = 0;
@@ -509,33 +512,3 @@ int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap)
509 512
510 return 0; 513 return 0;
511} 514}
512
513
514#if 0
515int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap)
516{
517 int ret;
518 int level;
519 int refs;
520 u64 blocknr = snap->blocknr;
521
522 level = node_level(snap->node.header.flags);
523 ret = lookup_block_ref(root, snap->blocknr, &refs);
524 BUG_ON(ret);
525 if (refs == 1 && level != 0) {
526 struct node *n = &snap->node;
527 struct tree_buffer *b;
528 int i;
529 for (i = 0; i < n->header.nritems; i++) {
530 b = read_tree_block(root, n->blockptrs[i]);
531 /* FIXME, don't recurse here */
532 ret = btrfs_drop_snapshot(root, b);
533 BUG_ON(ret);
534 tree_block_release(root, b);
535 }
536 }
537 ret = free_extent(root, blocknr, 1);
538 BUG_ON(ret);
539 return 0;
540}
541#endif