diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-02-26 10:40:21 -0500 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-02-26 10:40:21 -0500 |
commit | fec577fb7f516e0d12ff821b1af272fd754e120a (patch) | |
tree | f98b8adbf462cb3a146bcc3ec29e76beba5178ce /fs/btrfs/ctree.h | |
parent | 97571fd0c939be8ae9cb57a8c57430a244ce13ae (diff) |
Btrfs: Add fsx-style randomized tree tester
Add debug-tree command to print the tree
Add extent-tree.c to the repo
Comment ctree.h
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r-- | fs/btrfs/ctree.h | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index b92fbbb5ecd7..18daccd84535 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -1,22 +1,36 @@ | |||
1 | #ifndef __CTREE__ | 1 | #ifndef __CTREE__ |
2 | #define __CTREE__ | 2 | #define __CTREE__ |
3 | 3 | ||
4 | #define CTREE_BLOCKSIZE 4096 | 4 | #define CTREE_BLOCKSIZE 1024 |
5 | 5 | ||
6 | /* | ||
7 | * the key defines the order in the tree, and so it also defines (optimal) | ||
8 | * block layout. objectid corresonds to the inode number. The flags | ||
9 | * tells us things about the object, and is a kind of stream selector. | ||
10 | * so for a given inode, keys with flags of 1 might refer to the inode | ||
11 | * data, flags of 2 may point to file data in the btree and flags == 3 | ||
12 | * may point to extents. | ||
13 | * | ||
14 | * offset is the starting byte offset for this key in the stream. | ||
15 | */ | ||
6 | struct key { | 16 | struct key { |
7 | u64 objectid; | 17 | u64 objectid; |
8 | u32 flags; | 18 | u32 flags; |
9 | u64 offset; | 19 | u64 offset; |
10 | } __attribute__ ((__packed__)); | 20 | } __attribute__ ((__packed__)); |
11 | 21 | ||
22 | /* | ||
23 | * every tree block (leaf or node) starts with this header. | ||
24 | */ | ||
12 | struct header { | 25 | struct header { |
13 | u64 fsid[2]; /* FS specific uuid */ | 26 | u64 fsid[2]; /* FS specific uuid */ |
14 | u64 blocknr; | 27 | u64 blocknr; /* which block this node is supposed to live in */ |
15 | u64 parentid; | 28 | u64 parentid; /* objectid of the tree root */ |
16 | u32 csum; | 29 | u32 csum; |
17 | u32 ham; | 30 | u32 ham; |
18 | u16 nritems; | 31 | u16 nritems; |
19 | u16 flags; | 32 | u16 flags; |
33 | /* generation flags to be added */ | ||
20 | } __attribute__ ((__packed__)); | 34 | } __attribute__ ((__packed__)); |
21 | 35 | ||
22 | #define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct header)) / \ | 36 | #define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct header)) / \ |
@@ -28,6 +42,11 @@ struct header { | |||
28 | 42 | ||
29 | struct tree_buffer; | 43 | struct tree_buffer; |
30 | 44 | ||
45 | /* | ||
46 | * in ram representation of the tree. extent_root is used for all allocations | ||
47 | * and for the extent tree extent_root root. current_insert is used | ||
48 | * only for the extent tree. | ||
49 | */ | ||
31 | struct ctree_root { | 50 | struct ctree_root { |
32 | struct tree_buffer *node; | 51 | struct tree_buffer *node; |
33 | struct ctree_root *extent_root; | 52 | struct ctree_root *extent_root; |
@@ -36,27 +55,46 @@ struct ctree_root { | |||
36 | struct radix_tree_root cache_radix; | 55 | struct radix_tree_root cache_radix; |
37 | }; | 56 | }; |
38 | 57 | ||
58 | /* | ||
59 | * describes a tree on disk | ||
60 | */ | ||
39 | struct ctree_root_info { | 61 | struct ctree_root_info { |
40 | u64 fsid[2]; /* FS specific uuid */ | 62 | u64 fsid[2]; /* FS specific uuid */ |
41 | u64 blocknr; /* blocknr of this block */ | 63 | u64 blocknr; /* blocknr of this block */ |
42 | u64 objectid; /* inode number of this root */ | 64 | u64 objectid; /* inode number of this root */ |
43 | u64 tree_root; /* the tree root */ | 65 | u64 tree_root; /* the tree root block */ |
44 | u32 csum; | 66 | u32 csum; |
45 | u32 ham; | 67 | u32 ham; |
46 | u64 snapuuid[2]; /* root specific uuid */ | 68 | u64 snapuuid[2]; /* root specific uuid */ |
47 | } __attribute__ ((__packed__)); | 69 | } __attribute__ ((__packed__)); |
48 | 70 | ||
71 | /* | ||
72 | * the super block basically lists the main trees of the FS | ||
73 | * it currently lacks any block count etc etc | ||
74 | */ | ||
49 | struct ctree_super_block { | 75 | struct ctree_super_block { |
50 | struct ctree_root_info root_info; | 76 | struct ctree_root_info root_info; |
51 | struct ctree_root_info extent_info; | 77 | struct ctree_root_info extent_info; |
52 | } __attribute__ ((__packed__)); | 78 | } __attribute__ ((__packed__)); |
53 | 79 | ||
80 | /* | ||
81 | * A leaf is full of items. The exact type of item is defined by | ||
82 | * the key flags parameter. offset and size tell us where to find | ||
83 | * the item in the leaf (relative to the start of the data area) | ||
84 | */ | ||
54 | struct item { | 85 | struct item { |
55 | struct key key; | 86 | struct key key; |
56 | u16 offset; | 87 | u16 offset; |
57 | u16 size; | 88 | u16 size; |
58 | } __attribute__ ((__packed__)); | 89 | } __attribute__ ((__packed__)); |
59 | 90 | ||
91 | /* | ||
92 | * leaves have an item area and a data area: | ||
93 | * [item0, item1....itemN] [free space] [dataN...data1, data0] | ||
94 | * | ||
95 | * The data is separate from the items to get the keys closer together | ||
96 | * during searches. | ||
97 | */ | ||
60 | #define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct header)) | 98 | #define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct header)) |
61 | struct leaf { | 99 | struct leaf { |
62 | struct header header; | 100 | struct header header; |
@@ -66,17 +104,33 @@ struct leaf { | |||
66 | }; | 104 | }; |
67 | } __attribute__ ((__packed__)); | 105 | } __attribute__ ((__packed__)); |
68 | 106 | ||
107 | /* | ||
108 | * all non-leaf blocks are nodes, they hold only keys and pointers to | ||
109 | * other blocks | ||
110 | */ | ||
69 | struct node { | 111 | struct node { |
70 | struct header header; | 112 | struct header header; |
71 | struct key keys[NODEPTRS_PER_BLOCK]; | 113 | struct key keys[NODEPTRS_PER_BLOCK]; |
72 | u64 blockptrs[NODEPTRS_PER_BLOCK]; | 114 | u64 blockptrs[NODEPTRS_PER_BLOCK]; |
73 | } __attribute__ ((__packed__)); | 115 | } __attribute__ ((__packed__)); |
74 | 116 | ||
117 | /* | ||
118 | * items in the extent btree are used to record the objectid of the | ||
119 | * owner of the block and the number of references | ||
120 | */ | ||
75 | struct extent_item { | 121 | struct extent_item { |
76 | u32 refs; | 122 | u32 refs; |
77 | u64 owner; | 123 | u64 owner; |
78 | } __attribute__ ((__packed__)); | 124 | } __attribute__ ((__packed__)); |
79 | 125 | ||
126 | /* | ||
127 | * ctree_paths remember the path taken from the root down to the leaf. | ||
128 | * level 0 is always the leaf, and nodes[1...MAX_LEVEL] will point | ||
129 | * to any other levels that are present. | ||
130 | * | ||
131 | * The slots array records the index of the item or block pointer | ||
132 | * used while walking the tree. | ||
133 | */ | ||
80 | struct ctree_path { | 134 | struct ctree_path { |
81 | struct tree_buffer *nodes[MAX_LEVEL]; | 135 | struct tree_buffer *nodes[MAX_LEVEL]; |
82 | int slots[MAX_LEVEL]; | 136 | int slots[MAX_LEVEL]; |