diff options
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/ctree.c | 31 | ||||
-rw-r--r-- | fs/btrfs/ctree.h | 12 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 4 | ||||
-rw-r--r-- | fs/btrfs/print-tree.c | 4 |
4 files changed, 33 insertions, 18 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 105556470055..762810731001 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -58,7 +58,8 @@ int btrfs_cow_block(struct ctree_root *root, | |||
58 | free_extent(root, buf->blocknr, 1); | 58 | free_extent(root, buf->blocknr, 1); |
59 | tree_block_release(root, buf); | 59 | tree_block_release(root, buf); |
60 | } else { | 60 | } else { |
61 | parent->node.blockptrs[parent_slot] = cow->blocknr; | 61 | btrfs_set_node_blockptr(&parent->node, parent_slot, |
62 | cow->blocknr); | ||
62 | BUG_ON(list_empty(&parent->dirty)); | 63 | BUG_ON(list_empty(&parent->dirty)); |
63 | free_extent(root, buf->blocknr, 1); | 64 | free_extent(root, buf->blocknr, 1); |
64 | } | 65 | } |
@@ -133,7 +134,7 @@ int check_node(struct ctree_path *path, int level) | |||
133 | parent_key = &parent->keys[parent_slot]; | 134 | parent_key = &parent->keys[parent_slot]; |
134 | BUG_ON(memcmp(parent_key, node->keys, | 135 | BUG_ON(memcmp(parent_key, node->keys, |
135 | sizeof(struct btrfs_disk_key))); | 136 | sizeof(struct btrfs_disk_key))); |
136 | BUG_ON(parent->blockptrs[parent_slot] != | 137 | BUG_ON(btrfs_node_blockptr(parent, parent_slot) != |
137 | btrfs_header_blocknr(&node->header)); | 138 | btrfs_header_blocknr(&node->header)); |
138 | } | 139 | } |
139 | BUG_ON(nritems > NODEPTRS_PER_BLOCK); | 140 | BUG_ON(nritems > NODEPTRS_PER_BLOCK); |
@@ -166,7 +167,7 @@ int check_leaf(struct ctree_path *path, int level) | |||
166 | parent_key = &parent->keys[parent_slot]; | 167 | parent_key = &parent->keys[parent_slot]; |
167 | BUG_ON(memcmp(parent_key, &leaf->items[0].key, | 168 | BUG_ON(memcmp(parent_key, &leaf->items[0].key, |
168 | sizeof(struct btrfs_disk_key))); | 169 | sizeof(struct btrfs_disk_key))); |
169 | BUG_ON(parent->blockptrs[parent_slot] != | 170 | BUG_ON(btrfs_node_blockptr(parent, parent_slot) != |
170 | btrfs_header_blocknr(&leaf->header)); | 171 | btrfs_header_blocknr(&leaf->header)); |
171 | } | 172 | } |
172 | for (i = 0; nritems > 1 && i < nritems - 2; i++) { | 173 | for (i = 0; nritems > 1 && i < nritems - 2; i++) { |
@@ -258,7 +259,7 @@ struct tree_buffer *read_node_slot(struct ctree_root *root, | |||
258 | return NULL; | 259 | return NULL; |
259 | if (slot >= btrfs_header_nritems(&node->header)) | 260 | if (slot >= btrfs_header_nritems(&node->header)) |
260 | return NULL; | 261 | return NULL; |
261 | return read_tree_block(root, node->blockptrs[slot]); | 262 | return read_tree_block(root, btrfs_node_blockptr(node, slot)); |
262 | } | 263 | } |
263 | 264 | ||
264 | static int balance_level(struct ctree_root *root, struct ctree_path *path, | 265 | static int balance_level(struct ctree_root *root, struct ctree_path *path, |
@@ -283,7 +284,7 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path, | |||
283 | 284 | ||
284 | mid_buf = path->nodes[level]; | 285 | mid_buf = path->nodes[level]; |
285 | mid = &mid_buf->node; | 286 | mid = &mid_buf->node; |
286 | orig_ptr = mid->blockptrs[orig_slot]; | 287 | orig_ptr = btrfs_node_blockptr(mid, orig_slot); |
287 | 288 | ||
288 | if (level < MAX_LEVEL - 1) | 289 | if (level < MAX_LEVEL - 1) |
289 | parent_buf = path->nodes[level + 1]; | 290 | parent_buf = path->nodes[level + 1]; |
@@ -407,7 +408,8 @@ static int balance_level(struct ctree_root *root, struct ctree_path *path, | |||
407 | } | 408 | } |
408 | /* double check we haven't messed things up */ | 409 | /* double check we haven't messed things up */ |
409 | check_block(path, level); | 410 | check_block(path, level); |
410 | if (orig_ptr != path->nodes[level]->node.blockptrs[path->slots[level]]) | 411 | if (orig_ptr != btrfs_node_blockptr(&path->nodes[level]->node, |
412 | path->slots[level])) | ||
411 | BUG(); | 413 | BUG(); |
412 | 414 | ||
413 | if (right_buf) | 415 | if (right_buf) |
@@ -482,7 +484,7 @@ again: | |||
482 | slot = p->slots[level]; | 484 | slot = p->slots[level]; |
483 | BUG_ON(btrfs_header_nritems(&c->header) == 1); | 485 | BUG_ON(btrfs_header_nritems(&c->header) == 1); |
484 | } | 486 | } |
485 | b = read_tree_block(root, c->blockptrs[slot]); | 487 | b = read_tree_block(root, btrfs_node_blockptr(c, slot)); |
486 | } else { | 488 | } else { |
487 | struct leaf *l = (struct leaf *)c; | 489 | struct leaf *l = (struct leaf *)c; |
488 | p->slots[level] = slot; | 490 | p->slots[level] = slot; |
@@ -660,7 +662,7 @@ static int insert_new_root(struct ctree_root *root, | |||
660 | else | 662 | else |
661 | lower_key = lower->keys; | 663 | lower_key = lower->keys; |
662 | memcpy(c->keys, lower_key, sizeof(struct btrfs_disk_key)); | 664 | memcpy(c->keys, lower_key, sizeof(struct btrfs_disk_key)); |
663 | c->blockptrs[0] = path->nodes[level-1]->blocknr; | 665 | btrfs_set_node_blockptr(c, 0, path->nodes[level - 1]->blocknr); |
664 | /* the super has an extra ref to root->node */ | 666 | /* the super has an extra ref to root->node */ |
665 | tree_block_release(root, root->node); | 667 | tree_block_release(root, root->node); |
666 | root->node = t; | 668 | root->node = t; |
@@ -700,7 +702,7 @@ static int insert_ptr(struct ctree_root *root, | |||
700 | (nritems - slot) * sizeof(u64)); | 702 | (nritems - slot) * sizeof(u64)); |
701 | } | 703 | } |
702 | memcpy(lower->keys + slot, key, sizeof(struct btrfs_disk_key)); | 704 | memcpy(lower->keys + slot, key, sizeof(struct btrfs_disk_key)); |
703 | lower->blockptrs[slot] = blocknr; | 705 | btrfs_set_node_blockptr(lower, slot, blocknr); |
704 | btrfs_set_header_nritems(&lower->header, nritems + 1); | 706 | btrfs_set_header_nritems(&lower->header, nritems + 1); |
705 | if (lower->keys[1].objectid == 0) | 707 | if (lower->keys[1].objectid == 0) |
706 | BUG(); | 708 | BUG(); |
@@ -820,7 +822,8 @@ static int push_leaf_right(struct ctree_root *root, struct ctree_path *path, | |||
820 | if (slot >= btrfs_header_nritems(&upper->node.header) - 1) { | 822 | if (slot >= btrfs_header_nritems(&upper->node.header) - 1) { |
821 | return 1; | 823 | return 1; |
822 | } | 824 | } |
823 | right_buf = read_tree_block(root, upper->node.blockptrs[slot + 1]); | 825 | right_buf = read_tree_block(root, btrfs_node_blockptr(&upper->node, |
826 | slot + 1)); | ||
824 | right = &right_buf->leaf; | 827 | right = &right_buf->leaf; |
825 | free_space = leaf_free_space(right); | 828 | free_space = leaf_free_space(right); |
826 | if (free_space < data_size + sizeof(struct btrfs_item)) { | 829 | if (free_space < data_size + sizeof(struct btrfs_item)) { |
@@ -926,7 +929,8 @@ static int push_leaf_left(struct ctree_root *root, struct ctree_path *path, | |||
926 | if (!path->nodes[1]) { | 929 | if (!path->nodes[1]) { |
927 | return 1; | 930 | return 1; |
928 | } | 931 | } |
929 | t = read_tree_block(root, path->nodes[1]->node.blockptrs[slot - 1]); | 932 | t = read_tree_block(root, btrfs_node_blockptr(&path->nodes[1]->node, |
933 | slot - 1)); | ||
930 | left = &t->leaf; | 934 | left = &t->leaf; |
931 | free_space = leaf_free_space(left); | 935 | free_space = leaf_free_space(left); |
932 | if (free_space < data_size + sizeof(struct btrfs_item)) { | 936 | if (free_space < data_size + sizeof(struct btrfs_item)) { |
@@ -1353,7 +1357,7 @@ int next_leaf(struct ctree_root *root, struct ctree_path *path) | |||
1353 | level++; | 1357 | level++; |
1354 | continue; | 1358 | continue; |
1355 | } | 1359 | } |
1356 | blocknr = c->node.blockptrs[slot]; | 1360 | blocknr = btrfs_node_blockptr(&c->node, slot); |
1357 | if (next) | 1361 | if (next) |
1358 | tree_block_release(root, next); | 1362 | tree_block_release(root, next); |
1359 | next = read_tree_block(root, blocknr); | 1363 | next = read_tree_block(root, blocknr); |
@@ -1368,7 +1372,8 @@ int next_leaf(struct ctree_root *root, struct ctree_path *path) | |||
1368 | path->slots[level] = 0; | 1372 | path->slots[level] = 0; |
1369 | if (!level) | 1373 | if (!level) |
1370 | break; | 1374 | break; |
1371 | next = read_tree_block(root, next->node.blockptrs[0]); | 1375 | next = read_tree_block(root, |
1376 | btrfs_node_blockptr(&next->node, 0)); | ||
1372 | } | 1377 | } |
1373 | return 0; | 1378 | return 0; |
1374 | } | 1379 | } |
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index b03df154dcdb..a8454c401cee 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -128,7 +128,7 @@ struct leaf { | |||
128 | struct node { | 128 | struct 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 | u64 blockptrs[NODEPTRS_PER_BLOCK]; | 131 | __le64 blockptrs[NODEPTRS_PER_BLOCK]; |
132 | } __attribute__ ((__packed__)); | 132 | } __attribute__ ((__packed__)); |
133 | 133 | ||
134 | /* | 134 | /* |
@@ -153,6 +153,16 @@ struct ctree_path { | |||
153 | int slots[MAX_LEVEL]; | 153 | int slots[MAX_LEVEL]; |
154 | }; | 154 | }; |
155 | 155 | ||
156 | static inline u64 btrfs_node_blockptr(struct node *n, int nr) | ||
157 | { | ||
158 | return le64_to_cpu(n->blockptrs[nr]); | ||
159 | } | ||
160 | |||
161 | static inline void btrfs_set_node_blockptr(struct node *n, int nr, u64 val) | ||
162 | { | ||
163 | n->blockptrs[nr] = cpu_to_le64(val); | ||
164 | } | ||
165 | |||
156 | static inline u16 btrfs_item_offset(struct btrfs_item *item) | 166 | static inline u16 btrfs_item_offset(struct btrfs_item *item) |
157 | { | 167 | { |
158 | return le16_to_cpu(item->offset); | 168 | return le16_to_cpu(item->offset); |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index fdf95bd07f90..e511f48eb48e 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -85,7 +85,7 @@ int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf) | |||
85 | return 0; | 85 | return 0; |
86 | 86 | ||
87 | for (i = 0; i < btrfs_header_nritems(&buf->node.header); i++) { | 87 | for (i = 0; i < btrfs_header_nritems(&buf->node.header); i++) { |
88 | blocknr = buf->node.blockptrs[i]; | 88 | blocknr = btrfs_node_blockptr(&buf->node, i); |
89 | inc_block_ref(root, blocknr); | 89 | inc_block_ref(root, blocknr); |
90 | } | 90 | } |
91 | return 0; | 91 | return 0; |
@@ -437,7 +437,7 @@ int walk_down_tree(struct ctree_root *root, struct ctree_path *path, int *level) | |||
437 | if (path->slots[*level] >= | 437 | if (path->slots[*level] >= |
438 | btrfs_header_nritems(&cur->node.header)) | 438 | btrfs_header_nritems(&cur->node.header)) |
439 | break; | 439 | break; |
440 | blocknr = cur->node.blockptrs[path->slots[*level]]; | 440 | blocknr = btrfs_node_blockptr(&cur->node, path->slots[*level]); |
441 | ret = lookup_block_ref(root, blocknr, &refs); | 441 | ret = lookup_block_ref(root, blocknr, &refs); |
442 | if (refs != 1 || *level == 1) { | 442 | if (refs != 1 || *level == 1) { |
443 | path->slots[*level]++; | 443 | path->slots[*level]++; |
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c index 33f5ee4052c1..101278e1139a 100644 --- a/fs/btrfs/print-tree.c +++ b/fs/btrfs/print-tree.c | |||
@@ -54,12 +54,12 @@ void print_tree(struct ctree_root *root, struct tree_buffer *t) | |||
54 | printf("\tkey %d (%Lu %u %Lu) block %Lu\n", | 54 | printf("\tkey %d (%Lu %u %Lu) block %Lu\n", |
55 | i, | 55 | i, |
56 | c->keys[i].objectid, c->keys[i].flags, c->keys[i].offset, | 56 | c->keys[i].objectid, c->keys[i].flags, c->keys[i].offset, |
57 | c->blockptrs[i]); | 57 | btrfs_node_blockptr(c, i)); |
58 | fflush(stdout); | 58 | fflush(stdout); |
59 | } | 59 | } |
60 | for (i = 0; i < nr; i++) { | 60 | for (i = 0; i < nr; i++) { |
61 | struct tree_buffer *next_buf = read_tree_block(root, | 61 | struct tree_buffer *next_buf = read_tree_block(root, |
62 | c->blockptrs[i]); | 62 | btrfs_node_blockptr(c, i)); |
63 | struct node *next = &next_buf->node; | 63 | struct node *next = &next_buf->node; |
64 | if (btrfs_is_leaf(next) && | 64 | if (btrfs_is_leaf(next) && |
65 | btrfs_header_level(&c->header) != 1) | 65 | btrfs_header_level(&c->header) != 1) |