diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-03-15 12:56:47 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-03-15 12:56:47 -0400 |
commit | 62e2749e03a855d98855f9ce032dbe72d5fad148 (patch) | |
tree | ed12521d1bde4ac7eda7f917b57b3cab1e76539d /fs/btrfs/ctree.h | |
parent | a1516c8921ce2c148b69493e858d95bc79c92f01 (diff) |
Btrfs: Use a chunk of the key flags to record the item type.
Add (untested and simple) directory item code
Fix comp_keys to use the new key ordering
Add btrfs_insert_empty_item
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r-- | fs/btrfs/ctree.h | 182 |
1 files changed, 127 insertions, 55 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 73ebc824924..e8a26fd8ea9 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -58,39 +58,6 @@ struct btrfs_header { | |||
58 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize)) | 58 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize)) |
59 | 59 | ||
60 | struct btrfs_buffer; | 60 | struct btrfs_buffer; |
61 | |||
62 | struct btrfs_root_item { | ||
63 | __le64 blocknr; | ||
64 | __le32 flags; | ||
65 | __le64 block_limit; | ||
66 | __le64 blocks_used; | ||
67 | __le32 refs; | ||
68 | }; | ||
69 | |||
70 | /* | ||
71 | * in ram representation of the tree. extent_root is used for all allocations | ||
72 | * and for the extent tree extent_root root. current_insert is used | ||
73 | * only for the extent tree. | ||
74 | */ | ||
75 | struct btrfs_root { | ||
76 | struct btrfs_buffer *node; | ||
77 | struct btrfs_buffer *commit_root; | ||
78 | struct btrfs_root *extent_root; | ||
79 | struct btrfs_root *tree_root; | ||
80 | struct btrfs_key current_insert; | ||
81 | struct btrfs_key last_insert; | ||
82 | int fp; | ||
83 | struct radix_tree_root cache_radix; | ||
84 | struct radix_tree_root pinned_radix; | ||
85 | struct list_head trans; | ||
86 | struct list_head cache; | ||
87 | int cache_size; | ||
88 | int ref_cows; | ||
89 | struct btrfs_root_item root_item; | ||
90 | struct btrfs_key root_key; | ||
91 | u32 blocksize; | ||
92 | }; | ||
93 | |||
94 | /* | 61 | /* |
95 | * the super block basically lists the main trees of the FS | 62 | * the super block basically lists the main trees of the FS |
96 | * it currently lacks any block count etc etc | 63 | * it currently lacks any block count etc etc |
@@ -108,8 +75,7 @@ struct btrfs_super_block { | |||
108 | } __attribute__ ((__packed__)); | 75 | } __attribute__ ((__packed__)); |
109 | 76 | ||
110 | /* | 77 | /* |
111 | * A leaf is full of items. The exact type of item is defined by | 78 | * A leaf is full of items. offset and size tell us where to find |
112 | * the key flags parameter. offset and size tell us where to find | ||
113 | * the item in the leaf (relative to the start of the data area) | 79 | * the item in the leaf (relative to the start of the data area) |
114 | */ | 80 | */ |
115 | struct btrfs_item { | 81 | struct btrfs_item { |
@@ -145,15 +111,6 @@ struct btrfs_node { | |||
145 | } __attribute__ ((__packed__)); | 111 | } __attribute__ ((__packed__)); |
146 | 112 | ||
147 | /* | 113 | /* |
148 | * items in the extent btree are used to record the objectid of the | ||
149 | * owner of the block and the number of references | ||
150 | */ | ||
151 | struct btrfs_extent_item { | ||
152 | __le32 refs; | ||
153 | __le64 owner; | ||
154 | } __attribute__ ((__packed__)); | ||
155 | |||
156 | /* | ||
157 | * btrfs_paths remember the path taken from the root down to the leaf. | 114 | * btrfs_paths remember the path taken from the root down to the leaf. |
158 | * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point | 115 | * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point |
159 | * to any other levels that are present. | 116 | * to any other levels that are present. |
@@ -166,6 +123,94 @@ struct btrfs_path { | |||
166 | int slots[BTRFS_MAX_LEVEL]; | 123 | int slots[BTRFS_MAX_LEVEL]; |
167 | }; | 124 | }; |
168 | 125 | ||
126 | /* | ||
127 | * items in the extent btree are used to record the objectid of the | ||
128 | * owner of the block and the number of references | ||
129 | */ | ||
130 | struct btrfs_extent_item { | ||
131 | __le32 refs; | ||
132 | __le64 owner; | ||
133 | } __attribute__ ((__packed__)); | ||
134 | |||
135 | struct btrfs_dir_item { | ||
136 | __le64 objectid; | ||
137 | __le16 flags; | ||
138 | u8 type; | ||
139 | } __attribute__ ((__packed__)); | ||
140 | |||
141 | struct btrfs_root_item { | ||
142 | __le64 blocknr; | ||
143 | __le32 flags; | ||
144 | __le64 block_limit; | ||
145 | __le64 blocks_used; | ||
146 | __le32 refs; | ||
147 | }; | ||
148 | |||
149 | /* | ||
150 | * in ram representation of the tree. extent_root is used for all allocations | ||
151 | * and for the extent tree extent_root root. current_insert is used | ||
152 | * only for the extent tree. | ||
153 | */ | ||
154 | struct btrfs_root { | ||
155 | struct btrfs_buffer *node; | ||
156 | struct btrfs_buffer *commit_root; | ||
157 | struct btrfs_root *extent_root; | ||
158 | struct btrfs_root *tree_root; | ||
159 | struct btrfs_key current_insert; | ||
160 | struct btrfs_key last_insert; | ||
161 | int fp; | ||
162 | struct radix_tree_root cache_radix; | ||
163 | struct radix_tree_root pinned_radix; | ||
164 | struct list_head trans; | ||
165 | struct list_head cache; | ||
166 | int cache_size; | ||
167 | int ref_cows; | ||
168 | struct btrfs_root_item root_item; | ||
169 | struct btrfs_key root_key; | ||
170 | u32 blocksize; | ||
171 | }; | ||
172 | |||
173 | |||
174 | /* the lower bits in the key flags defines the item type */ | ||
175 | #define BTRFS_KEY_TYPE_MAX 256 | ||
176 | #define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1) | ||
177 | #define BTRFS_INODE_ITEM_KEY 1 | ||
178 | #define BTRFS_DIR_ITEM_KEY 2 | ||
179 | #define BTRFS_ROOT_ITEM_KEY 3 | ||
180 | #define BTRFS_EXTENT_ITEM_KEY 4 | ||
181 | #define BTRFS_STRING_ITEM_KEY 5 | ||
182 | |||
183 | static inline u64 btrfs_dir_objectid(struct btrfs_dir_item *d) | ||
184 | { | ||
185 | return le64_to_cpu(d->objectid); | ||
186 | } | ||
187 | |||
188 | static inline void btrfs_set_dir_objectid(struct btrfs_dir_item *d, u64 val) | ||
189 | { | ||
190 | d->objectid = cpu_to_le64(val); | ||
191 | } | ||
192 | |||
193 | static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d) | ||
194 | { | ||
195 | return le16_to_cpu(d->flags); | ||
196 | } | ||
197 | |||
198 | static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val) | ||
199 | { | ||
200 | d->flags = cpu_to_le16(val); | ||
201 | } | ||
202 | |||
203 | static inline u8 btrfs_dir_type(struct btrfs_dir_item *d) | ||
204 | { | ||
205 | return d->type; | ||
206 | } | ||
207 | |||
208 | static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val) | ||
209 | { | ||
210 | d->type = val; | ||
211 | } | ||
212 | |||
213 | |||
169 | static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei) | 214 | static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei) |
170 | { | 215 | { |
171 | return le64_to_cpu(ei->owner); | 216 | return le64_to_cpu(ei->owner); |
@@ -238,39 +283,65 @@ static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, | |||
238 | disk->objectid = cpu_to_le64(cpu->objectid); | 283 | disk->objectid = cpu_to_le64(cpu->objectid); |
239 | } | 284 | } |
240 | 285 | ||
241 | static inline u64 btrfs_key_objectid(struct btrfs_disk_key *disk) | 286 | static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk) |
242 | { | 287 | { |
243 | return le64_to_cpu(disk->objectid); | 288 | return le64_to_cpu(disk->objectid); |
244 | } | 289 | } |
245 | 290 | ||
246 | static inline void btrfs_set_key_objectid(struct btrfs_disk_key *disk, | 291 | static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk, |
247 | u64 val) | 292 | u64 val) |
248 | { | 293 | { |
249 | disk->objectid = cpu_to_le64(val); | 294 | disk->objectid = cpu_to_le64(val); |
250 | } | 295 | } |
251 | 296 | ||
252 | static inline u64 btrfs_key_offset(struct btrfs_disk_key *disk) | 297 | static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk) |
253 | { | 298 | { |
254 | return le64_to_cpu(disk->offset); | 299 | return le64_to_cpu(disk->offset); |
255 | } | 300 | } |
256 | 301 | ||
257 | static inline void btrfs_set_key_offset(struct btrfs_disk_key *disk, | 302 | static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk, |
258 | u64 val) | 303 | u64 val) |
259 | { | 304 | { |
260 | disk->offset = cpu_to_le64(val); | 305 | disk->offset = cpu_to_le64(val); |
261 | } | 306 | } |
262 | 307 | ||
263 | static inline u32 btrfs_key_flags(struct btrfs_disk_key *disk) | 308 | static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk) |
264 | { | 309 | { |
265 | return le32_to_cpu(disk->flags); | 310 | return le32_to_cpu(disk->flags); |
266 | } | 311 | } |
267 | 312 | ||
268 | static inline void btrfs_set_key_flags(struct btrfs_disk_key *disk, | 313 | static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk, |
269 | u32 val) | 314 | u32 val) |
270 | { | 315 | { |
271 | disk->flags = cpu_to_le32(val); | 316 | disk->flags = cpu_to_le32(val); |
272 | } | 317 | } |
273 | 318 | ||
319 | static inline u32 btrfs_key_type(struct btrfs_key *key) | ||
320 | { | ||
321 | return key->flags & BTRFS_KEY_TYPE_MASK; | ||
322 | } | ||
323 | |||
324 | static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key) | ||
325 | { | ||
326 | return le32_to_cpu(key->flags) & BTRFS_KEY_TYPE_MASK; | ||
327 | } | ||
328 | |||
329 | static inline void btrfs_set_key_type(struct btrfs_key *key, u32 type) | ||
330 | { | ||
331 | BUG_ON(type >= BTRFS_KEY_TYPE_MAX); | ||
332 | key->flags = (key->flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type; | ||
333 | } | ||
334 | |||
335 | static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type) | ||
336 | { | ||
337 | u32 flags = btrfs_disk_key_flags(key); | ||
338 | BUG_ON(type >= BTRFS_KEY_TYPE_MAX); | ||
339 | flags = (flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type; | ||
340 | btrfs_set_disk_key_flags(key, flags); | ||
341 | } | ||
342 | |||
343 | |||
344 | |||
274 | static inline u64 btrfs_header_blocknr(struct btrfs_header *h) | 345 | static inline u64 btrfs_header_blocknr(struct btrfs_header *h) |
275 | { | 346 | { |
276 | return le64_to_cpu(h->blocknr); | 347 | return le64_to_cpu(h->blocknr); |
@@ -407,7 +478,6 @@ static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) | |||
407 | { | 478 | { |
408 | return (u8 *)l->items; | 479 | return (u8 *)l->items; |
409 | } | 480 | } |
410 | |||
411 | /* helper function to cast into the data area of the leaf. */ | 481 | /* helper function to cast into the data area of the leaf. */ |
412 | #define btrfs_item_ptr(leaf, slot, type) \ | 482 | #define btrfs_item_ptr(leaf, slot, type) \ |
413 | ((type *)(btrfs_leaf_data(leaf) + \ | 483 | ((type *)(btrfs_leaf_data(leaf) + \ |
@@ -422,7 +492,9 @@ void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); | |||
422 | void btrfs_init_path(struct btrfs_path *p); | 492 | void btrfs_init_path(struct btrfs_path *p); |
423 | int btrfs_del_item(struct btrfs_root *root, struct btrfs_path *path); | 493 | int btrfs_del_item(struct btrfs_root *root, struct btrfs_path *path); |
424 | int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *key, | 494 | int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *key, |
425 | void *data, int data_size); | 495 | void *data, u32 data_size); |
496 | int btrfs_insert_empty_item(struct btrfs_root *root, struct btrfs_path *path, | ||
497 | struct btrfs_key *cpu_key, u32 data_size); | ||
426 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); | 498 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); |
427 | int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf); | 499 | int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf); |
428 | int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap); | 500 | int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap); |