aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.h
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-04-15 15:41:47 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:01 -0400
commite17cade25ff8074101d653557a78df09c16ca276 (patch)
treec4bddc201bf77c9a460e726a5cdd5ca1add8c256 /fs/btrfs/ctree.h
parentb248a4152956cbae1b23f4c70ef5b51d6ea2ecfb (diff)
Btrfs: Add chunk uuids and update multi-device back references
Block headers now store the chunk tree uuid Chunk items records the device uuid for each stripes Device extent items record better back refs to the chunk tree Block groups record better back refs to the chunk tree The chunk tree format has also changed. The objectid of BTRFS_CHUNK_ITEM_KEY used to be the logical offset of the chunk. Now it is a chunk tree id, with the logical offset being stored in the offset field of the key. This allows a single chunk tree to record multiple logical address spaces, upping the number of bytes indexed by a chunk tree from 2^64 to 2^128. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r--fs/btrfs/ctree.h80
1 files changed, 67 insertions, 13 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 09d614fcafb1..82d67c3db8bc 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -70,6 +70,7 @@ extern struct kmem_cache *btrfs_path_cachep;
70 * All files have objectids higher than this. 70 * All files have objectids higher than this.
71 */ 71 */
72#define BTRFS_FIRST_FREE_OBJECTID 256ULL 72#define BTRFS_FIRST_FREE_OBJECTID 256ULL
73#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
73 74
74 75
75/* 76/*
@@ -131,7 +132,7 @@ struct btrfs_mapping_tree {
131 struct extent_map_tree map_tree; 132 struct extent_map_tree map_tree;
132}; 133};
133 134
134#define BTRFS_DEV_UUID_SIZE 16 135#define BTRFS_UUID_SIZE 16
135struct btrfs_dev_item { 136struct btrfs_dev_item {
136 /* the internal btrfs device id */ 137 /* the internal btrfs device id */
137 __le64 devid; 138 __le64 devid;
@@ -154,17 +155,32 @@ struct btrfs_dev_item {
154 /* type and info about this device */ 155 /* type and info about this device */
155 __le64 type; 156 __le64 type;
156 157
158 /* grouping information for allocation decisions */
159 __le32 dev_group;
160
161 /* seek speed 0-100 where 100 is fastest */
162 u8 seek_speed;
163
164 /* bandwidth 0-100 where 100 is fastest */
165 u8 bandwidth;
166
157 /* btrfs generated uuid for this device */ 167 /* btrfs generated uuid for this device */
158 u8 uuid[BTRFS_DEV_UUID_SIZE]; 168 u8 uuid[BTRFS_UUID_SIZE];
159} __attribute__ ((__packed__)); 169} __attribute__ ((__packed__));
160 170
161struct btrfs_stripe { 171struct btrfs_stripe {
162 __le64 devid; 172 __le64 devid;
163 __le64 offset; 173 __le64 offset;
174 u8 dev_uuid[BTRFS_UUID_SIZE];
164} __attribute__ ((__packed__)); 175} __attribute__ ((__packed__));
165 176
166struct btrfs_chunk { 177struct btrfs_chunk {
178 /* size of this chunk in bytes */
179 __le64 length;
180
181 /* objectid of the root referencing this chunk */
167 __le64 owner; 182 __le64 owner;
183
168 __le64 stripe_len; 184 __le64 stripe_len;
169 __le64 type; 185 __le64 type;
170 186
@@ -199,10 +215,14 @@ static inline unsigned long btrfs_chunk_item_size(int num_stripes)
199 * every tree block (leaf or node) starts with this header. 215 * every tree block (leaf or node) starts with this header.
200 */ 216 */
201struct btrfs_header { 217struct btrfs_header {
218 /* these first four must match the super block */
202 u8 csum[BTRFS_CSUM_SIZE]; 219 u8 csum[BTRFS_CSUM_SIZE];
203 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ 220 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
204 __le64 bytenr; /* which block this node is supposed to live in */ 221 __le64 bytenr; /* which block this node is supposed to live in */
205 __le64 flags; 222 __le64 flags;
223
224 /* allowed to be different from the super from here on down */
225 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
206 __le64 generation; 226 __le64 generation;
207 __le64 owner; 227 __le64 owner;
208 __le32 nritems; 228 __le32 nritems;
@@ -235,6 +255,8 @@ struct btrfs_super_block {
235 u8 fsid[16]; /* FS specific uuid */ 255 u8 fsid[16]; /* FS specific uuid */
236 __le64 bytenr; /* this block number */ 256 __le64 bytenr; /* this block number */
237 __le64 flags; 257 __le64 flags;
258
259 /* allowed to be different from the btrfs_header from here own down */
238 __le64 magic; 260 __le64 magic;
239 __le64 generation; 261 __le64 generation;
240 __le64 root; 262 __le64 root;
@@ -323,14 +345,16 @@ struct btrfs_extent_ref {
323 345
324/* dev extents record free space on individual devices. The owner 346/* dev extents record free space on individual devices. The owner
325 * field points back to the chunk allocation mapping tree that allocated 347 * field points back to the chunk allocation mapping tree that allocated
326 * the extent 348 * the extent. The chunk tree uuid field is a way to double check the owner
327 */ 349 */
328struct btrfs_dev_extent { 350struct btrfs_dev_extent {
329 __le64 owner; 351 __le64 chunk_tree;
352 __le64 chunk_objectid;
353 __le64 chunk_offset;
330 __le64 length; 354 __le64 length;
355 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
331} __attribute__ ((__packed__)); 356} __attribute__ ((__packed__));
332 357
333
334struct btrfs_inode_ref { 358struct btrfs_inode_ref {
335 __le16 name_len; 359 __le16 name_len;
336 /* name goes here */ 360 /* name goes here */
@@ -424,7 +448,6 @@ struct btrfs_csum_item {
424 448
425struct btrfs_block_group_item { 449struct btrfs_block_group_item {
426 __le64 used; 450 __le64 used;
427 __le64 chunk_tree;
428 __le64 chunk_objectid; 451 __le64 chunk_objectid;
429 __le64 flags; 452 __le64 flags;
430} __attribute__ ((__packed__)); 453} __attribute__ ((__packed__));
@@ -451,6 +474,7 @@ struct btrfs_device;
451struct btrfs_fs_devices; 474struct btrfs_fs_devices;
452struct btrfs_fs_info { 475struct btrfs_fs_info {
453 u8 fsid[BTRFS_FSID_SIZE]; 476 u8 fsid[BTRFS_FSID_SIZE];
477 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
454 struct btrfs_root *extent_root; 478 struct btrfs_root *extent_root;
455 struct btrfs_root *tree_root; 479 struct btrfs_root *tree_root;
456 struct btrfs_root *chunk_root; 480 struct btrfs_root *chunk_root;
@@ -697,6 +721,9 @@ BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
697BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32); 721BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
698BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32); 722BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
699BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64); 723BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
724BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
725BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
726BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
700 727
701BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64); 728BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
702BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item, 729BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
@@ -710,12 +737,19 @@ BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
710BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item, 737BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
711 sector_size, 32); 738 sector_size, 32);
712BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64); 739BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
740BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
741 dev_group, 32);
742BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
743 seek_speed, 8);
744BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
745 bandwidth, 8);
713 746
714static inline char *btrfs_device_uuid(struct btrfs_dev_item *d) 747static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
715{ 748{
716 return (char *)d + offsetof(struct btrfs_dev_item, uuid); 749 return (char *)d + offsetof(struct btrfs_dev_item, uuid);
717} 750}
718 751
752BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
719BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64); 753BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
720BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64); 754BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
721BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32); 755BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
@@ -726,6 +760,12 @@ BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
726BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64); 760BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
727BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64); 761BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
728 762
763static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
764{
765 return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
766}
767
768BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
729BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64); 769BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
730BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk, 770BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
731 stripe_len, 64); 771 stripe_len, 64);
@@ -781,13 +821,10 @@ BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
781 used, 64); 821 used, 64);
782BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item, 822BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
783 used, 64); 823 used, 64);
784BTRFS_SETGET_STACK_FUNCS(block_group_chunk_tree, struct btrfs_block_group_item,
785 chunk_tree, 64);
786BTRFS_SETGET_FUNCS(disk_block_group_chunk_tree, struct btrfs_block_group_item,
787 chunk_tree, 64);
788BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid, 824BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
789 struct btrfs_block_group_item, chunk_objectid, 64); 825 struct btrfs_block_group_item, chunk_objectid, 64);
790BTRFS_SETGET_FUNCS(disk_block_group_chunk_objecitd, 826
827BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
791 struct btrfs_block_group_item, chunk_objectid, 64); 828 struct btrfs_block_group_item, chunk_objectid, 64);
792BTRFS_SETGET_FUNCS(disk_block_group_flags, 829BTRFS_SETGET_FUNCS(disk_block_group_flags,
793 struct btrfs_block_group_item, flags, 64); 830 struct btrfs_block_group_item, flags, 64);
@@ -850,9 +887,20 @@ BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
850BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32); 887BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
851 888
852/* struct btrfs_dev_extent */ 889/* struct btrfs_dev_extent */
853BTRFS_SETGET_FUNCS(dev_extent_owner, struct btrfs_dev_extent, owner, 64); 890BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
891 chunk_tree, 64);
892BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
893 chunk_objectid, 64);
894BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
895 chunk_offset, 64);
854BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64); 896BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
855 897
898static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
899{
900 unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
901 return (u8 *)((unsigned long)dev + ptr);
902}
903
856/* struct btrfs_extent_ref */ 904/* struct btrfs_extent_ref */
857BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64); 905BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
858BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64); 906BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
@@ -1087,6 +1135,12 @@ static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
1087 return (u8 *)ptr; 1135 return (u8 *)ptr;
1088} 1136}
1089 1137
1138static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
1139{
1140 unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
1141 return (u8 *)ptr;
1142}
1143
1090static inline u8 *btrfs_super_fsid(struct extent_buffer *eb) 1144static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
1091{ 1145{
1092 unsigned long ptr = offsetof(struct btrfs_super_block, fsid); 1146 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
@@ -1311,7 +1365,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info);
1311int btrfs_read_block_groups(struct btrfs_root *root); 1365int btrfs_read_block_groups(struct btrfs_root *root);
1312int btrfs_make_block_group(struct btrfs_trans_handle *trans, 1366int btrfs_make_block_group(struct btrfs_trans_handle *trans,
1313 struct btrfs_root *root, u64 bytes_used, 1367 struct btrfs_root *root, u64 bytes_used,
1314 u64 type, u64 chunk_tree, u64 chunk_objectid, 1368 u64 type, u64 chunk_objectid, u64 chunk_offset,
1315 u64 size); 1369 u64 size);
1316/* ctree.c */ 1370/* ctree.c */
1317int btrfs_previous_item(struct btrfs_root *root, 1371int btrfs_previous_item(struct btrfs_root *root,