diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-02-24 13:39:08 -0500 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-02-24 13:39:08 -0500 |
commit | 97571fd0c939be8ae9cb57a8c57430a244ce13ae (patch) | |
tree | 03a8fdbbe5690f88ba2222038f271858dc56e8db | |
parent | 00ec4c5161e0adcf8be3cd844cb40239dc393d70 (diff) |
Btrfs: cleanup & comment
Signed-off-by: Chris Mason <chris.mason@oracle.com>
-rw-r--r-- | fs/btrfs/ctree.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index ef8bfa837532..7645ab3259ea 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -110,6 +110,10 @@ int generic_bin_search(char *p, int item_size, struct key *key, | |||
110 | return 1; | 110 | return 1; |
111 | } | 111 | } |
112 | 112 | ||
113 | /* | ||
114 | * simple bin_search frontend that does the right thing for | ||
115 | * leaves vs nodes | ||
116 | */ | ||
113 | int bin_search(struct node *c, struct key *key, int *slot) | 117 | int bin_search(struct node *c, struct key *key, int *slot) |
114 | { | 118 | { |
115 | if (is_leaf(c->header.flags)) { | 119 | if (is_leaf(c->header.flags)) { |
@@ -130,6 +134,10 @@ int bin_search(struct node *c, struct key *key, int *slot) | |||
130 | * | 134 | * |
131 | * If the key isn't found, the path points to the slot where it should | 135 | * If the key isn't found, the path points to the slot where it should |
132 | * be inserted. | 136 | * be inserted. |
137 | * | ||
138 | * if ins_len > 0, nodes and leaves will be split as we walk down the | ||
139 | * tree. if ins_len < 0, nodes will be merged as we walk down the tree (if | ||
140 | * possible) | ||
133 | */ | 141 | */ |
134 | int search_slot(struct ctree_root *root, struct key *key, | 142 | int search_slot(struct ctree_root *root, struct key *key, |
135 | struct ctree_path *p, int ins_len) | 143 | struct ctree_path *p, int ins_len) |
@@ -379,6 +387,11 @@ int push_node_right(struct ctree_root *root, struct ctree_path *path, int level) | |||
379 | return 0; | 387 | return 0; |
380 | } | 388 | } |
381 | 389 | ||
390 | /* | ||
391 | * helper function to insert a new root level in the tree. | ||
392 | * A new node is allocated, and a single item is inserted to | ||
393 | * point to the existing root | ||
394 | */ | ||
382 | static int insert_new_root(struct ctree_root *root, | 395 | static int insert_new_root(struct ctree_root *root, |
383 | struct ctree_path *path, int level) | 396 | struct ctree_path *path, int level) |
384 | { | 397 | { |
@@ -417,6 +430,7 @@ static int insert_new_root(struct ctree_root *root, | |||
417 | /* | 430 | /* |
418 | * worker function to insert a single pointer in a node. | 431 | * worker function to insert a single pointer in a node. |
419 | * the node should have enough room for the pointer already | 432 | * the node should have enough room for the pointer already |
433 | * | ||
420 | * slot and level indicate where you want the key to go, and | 434 | * slot and level indicate where you want the key to go, and |
421 | * blocknr is the block the key points to. | 435 | * blocknr is the block the key points to. |
422 | */ | 436 | */ |
@@ -449,6 +463,13 @@ int insert_ptr(struct ctree_root *root, | |||
449 | return 0; | 463 | return 0; |
450 | } | 464 | } |
451 | 465 | ||
466 | /* | ||
467 | * split the node at the specified level in path in two. | ||
468 | * The path is corrected to point to the appropriate node after the split | ||
469 | * | ||
470 | * Before splitting this tries to make some room in the node by pushing | ||
471 | * left and right, if either one works, it returns right away. | ||
472 | */ | ||
452 | int split_node(struct ctree_root *root, struct ctree_path *path, int level) | 473 | int split_node(struct ctree_root *root, struct ctree_path *path, int level) |
453 | { | 474 | { |
454 | struct tree_buffer *t; | 475 | struct tree_buffer *t; |
@@ -744,10 +765,12 @@ int split_leaf(struct ctree_root *root, struct ctree_path *path, int data_size) | |||
744 | right = &right_buffer->leaf; | 765 | right = &right_buffer->leaf; |
745 | memset(right, 0, sizeof(*right)); | 766 | memset(right, 0, sizeof(*right)); |
746 | if (mid <= slot) { | 767 | if (mid <= slot) { |
768 | /* FIXME, just alloc a new leaf here */ | ||
747 | if (leaf_space_used(l, mid, nritems - mid) + space_needed > | 769 | if (leaf_space_used(l, mid, nritems - mid) + space_needed > |
748 | LEAF_DATA_SIZE) | 770 | LEAF_DATA_SIZE) |
749 | BUG(); | 771 | BUG(); |
750 | } else { | 772 | } else { |
773 | /* FIXME, just alloc a new leaf here */ | ||
751 | if (leaf_space_used(l, 0, mid + 1) + space_needed > | 774 | if (leaf_space_used(l, 0, mid + 1) + space_needed > |
752 | LEAF_DATA_SIZE) | 775 | LEAF_DATA_SIZE) |
753 | BUG(); | 776 | BUG(); |
@@ -983,6 +1006,10 @@ int del_item(struct ctree_root *root, struct ctree_path *path) | |||
983 | return 0; | 1006 | return 0; |
984 | } | 1007 | } |
985 | 1008 | ||
1009 | /* | ||
1010 | * walk up the tree as far as required to find the next leaf. | ||
1011 | * returns 0 if it found something or -1 if there are no greater leaves. | ||
1012 | */ | ||
986 | int next_leaf(struct ctree_root *root, struct ctree_path *path) | 1013 | int next_leaf(struct ctree_root *root, struct ctree_path *path) |
987 | { | 1014 | { |
988 | int slot; | 1015 | int slot; |
@@ -1044,7 +1071,6 @@ int main() { | |||
1044 | 1071 | ||
1045 | 1072 | ||
1046 | root = open_ctree("dbfile", &super); | 1073 | root = open_ctree("dbfile", &super); |
1047 | |||
1048 | srand(55); | 1074 | srand(55); |
1049 | for (i = 0; i < run_size; i++) { | 1075 | for (i = 0; i < run_size; i++) { |
1050 | buf = malloc(64); | 1076 | buf = malloc(64); |