aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.h
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r--fs/btrfs/ctree.h112
1 files changed, 66 insertions, 46 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 256689551eb0..4d05456ec32f 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -96,7 +96,7 @@ struct btrfs_key {
96struct btrfs_header { 96struct btrfs_header {
97 u8 csum[BTRFS_CSUM_SIZE]; 97 u8 csum[BTRFS_CSUM_SIZE];
98 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ 98 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
99 __le64 blocknr; /* which block this node is supposed to live in */ 99 __le64 bytenr; /* which block this node is supposed to live in */
100 __le64 generation; 100 __le64 generation;
101 __le64 owner; 101 __le64 owner;
102 __le32 nritems; 102 __le32 nritems;
@@ -122,16 +122,17 @@ struct btrfs_super_block {
122 u8 csum[BTRFS_CSUM_SIZE]; 122 u8 csum[BTRFS_CSUM_SIZE];
123 /* the first 3 fields must match struct btrfs_header */ 123 /* the first 3 fields must match struct btrfs_header */
124 u8 fsid[16]; /* FS specific uuid */ 124 u8 fsid[16]; /* FS specific uuid */
125 __le64 blocknr; /* this block number */ 125 __le64 bytenr; /* this block number */
126 __le64 magic; 126 __le64 magic;
127 __le64 generation; 127 __le64 generation;
128 __le64 root; 128 __le64 root;
129 __le64 total_blocks; 129 __le64 total_bytes;
130 __le64 blocks_used; 130 __le64 bytes_used;
131 __le64 root_dir_objectid; 131 __le64 root_dir_objectid;
132 __le32 sectorsize; 132 __le32 sectorsize;
133 __le32 nodesize; 133 __le32 nodesize;
134 __le32 leafsize; 134 __le32 leafsize;
135 u8 root_level;
135} __attribute__ ((__packed__)); 136} __attribute__ ((__packed__));
136 137
137/* 138/*
@@ -231,13 +232,14 @@ struct btrfs_dir_item {
231struct btrfs_root_item { 232struct btrfs_root_item {
232 struct btrfs_inode_item inode; 233 struct btrfs_inode_item inode;
233 __le64 root_dirid; 234 __le64 root_dirid;
234 __le64 blocknr; 235 __le64 bytenr;
235 __le64 block_limit; 236 __le64 byte_limit;
236 __le64 blocks_used; 237 __le64 bytes_used;
237 __le32 flags; 238 __le32 flags;
238 __le32 refs; 239 __le32 refs;
239 struct btrfs_disk_key drop_progress; 240 struct btrfs_disk_key drop_progress;
240 u8 drop_level; 241 u8 drop_level;
242 u8 level;
241} __attribute__ ((__packed__)); 243} __attribute__ ((__packed__));
242 244
243#define BTRFS_FILE_EXTENT_REG 0 245#define BTRFS_FILE_EXTENT_REG 0
@@ -250,8 +252,8 @@ struct btrfs_file_extent_item {
250 * disk space consumed by the extent, checksum blocks are included 252 * disk space consumed by the extent, checksum blocks are included
251 * in these numbers 253 * in these numbers
252 */ 254 */
253 __le64 disk_blocknr; 255 __le64 disk_bytenr;
254 __le64 disk_num_blocks; 256 __le64 disk_num_bytes;
255 /* 257 /*
256 * the logical offset in file blocks (no csums) 258 * the logical offset in file blocks (no csums)
257 * this extent record is for. This allows a file extent to point 259 * this extent record is for. This allows a file extent to point
@@ -263,7 +265,7 @@ struct btrfs_file_extent_item {
263 /* 265 /*
264 * the logical number of file blocks (no csums included) 266 * the logical number of file blocks (no csums included)
265 */ 267 */
266 __le64 num_blocks; 268 __le64 num_bytes;
267} __attribute__ ((__packed__)); 269} __attribute__ ((__packed__));
268 270
269struct btrfs_csum_item { 271struct btrfs_csum_item {
@@ -429,6 +431,7 @@ static inline u##bits btrfs_##name(struct extent_buffer *eb, \
429 int err; \ 431 int err; \
430 char *map_token; \ 432 char *map_token; \
431 char *kaddr; \ 433 char *kaddr; \
434 int unmap_on_exit = (eb->map_token == NULL); \
432 unsigned long map_start; \ 435 unsigned long map_start; \
433 unsigned long map_len; \ 436 unsigned long map_len; \
434 unsigned long offset = (unsigned long)s + \ 437 unsigned long offset = (unsigned long)s + \
@@ -436,12 +439,13 @@ static inline u##bits btrfs_##name(struct extent_buffer *eb, \
436 err = map_extent_buffer(eb, offset, \ 439 err = map_extent_buffer(eb, offset, \
437 sizeof(((type *)0)->member), \ 440 sizeof(((type *)0)->member), \
438 &map_token, &kaddr, \ 441 &map_token, &kaddr, \
439 &map_start, &map_len, KM_USER0); \ 442 &map_start, &map_len, KM_USER1); \
440 if (!err) { \ 443 if (!err) { \
441 __le##bits *tmp = (__le##bits *)(kaddr + offset - \ 444 __le##bits *tmp = (__le##bits *)(kaddr + offset - \
442 map_start); \ 445 map_start); \
443 u##bits res = le##bits##_to_cpu(*tmp); \ 446 u##bits res = le##bits##_to_cpu(*tmp); \
444 unmap_extent_buffer(eb, map_token, KM_USER0); \ 447 if (unmap_on_exit) \
448 unmap_extent_buffer(eb, map_token, KM_USER1); \
445 return res; \ 449 return res; \
446 } else { \ 450 } else { \
447 __le##bits res; \ 451 __le##bits res; \
@@ -457,17 +461,19 @@ static inline void btrfs_set_##name(struct extent_buffer *eb, \
457 char *kaddr; \ 461 char *kaddr; \
458 unsigned long map_start; \ 462 unsigned long map_start; \
459 unsigned long map_len; \ 463 unsigned long map_len; \
464 int unmap_on_exit = (eb->map_token == NULL); \
460 unsigned long offset = (unsigned long)s + \ 465 unsigned long offset = (unsigned long)s + \
461 offsetof(type, member); \ 466 offsetof(type, member); \
462 err = map_extent_buffer(eb, offset, \ 467 err = map_extent_buffer(eb, offset, \
463 sizeof(((type *)0)->member), \ 468 sizeof(((type *)0)->member), \
464 &map_token, &kaddr, \ 469 &map_token, &kaddr, \
465 &map_start, &map_len, KM_USER0); \ 470 &map_start, &map_len, KM_USER1); \
466 if (!err) { \ 471 if (!err) { \
467 __le##bits *tmp = (__le##bits *)(kaddr + offset - \ 472 __le##bits *tmp = (__le##bits *)(kaddr + offset - \
468 map_start); \ 473 map_start); \
469 *tmp = cpu_to_le##bits(val); \ 474 *tmp = cpu_to_le##bits(val); \
470 unmap_extent_buffer(eb, map_token, KM_USER0); \ 475 if (unmap_on_exit) \
476 unmap_extent_buffer(eb, map_token, KM_USER1); \
471 } else { \ 477 } else { \
472 val = cpu_to_le##bits(val); \ 478 val = cpu_to_le##bits(val); \
473 write_eb_member(eb, s, type, member, &val); \ 479 write_eb_member(eb, s, type, member, &val); \
@@ -483,15 +489,17 @@ static inline u##bits btrfs_##name(struct extent_buffer *eb) \
483 unsigned long map_start; \ 489 unsigned long map_start; \
484 unsigned long map_len; \ 490 unsigned long map_len; \
485 unsigned long offset = offsetof(type, member); \ 491 unsigned long offset = offsetof(type, member); \
492 int unmap_on_exit = (eb->map_token == NULL); \
486 err = map_extent_buffer(eb, offset, \ 493 err = map_extent_buffer(eb, offset, \
487 sizeof(((type *)0)->member), \ 494 sizeof(((type *)0)->member), \
488 &map_token, &kaddr, \ 495 &map_token, &kaddr, \
489 &map_start, &map_len, KM_USER0); \ 496 &map_start, &map_len, KM_USER1); \
490 if (!err) { \ 497 if (!err) { \
491 __le##bits *tmp = (__le##bits *)(kaddr + offset - \ 498 __le##bits *tmp = (__le##bits *)(kaddr + offset - \
492 map_start); \ 499 map_start); \
493 u##bits res = le##bits##_to_cpu(*tmp); \ 500 u##bits res = le##bits##_to_cpu(*tmp); \
494 unmap_extent_buffer(eb, map_token, KM_USER0); \ 501 if (unmap_on_exit) \
502 unmap_extent_buffer(eb, map_token, KM_USER1); \
495 return res; \ 503 return res; \
496 } else { \ 504 } else { \
497 __le##bits res; \ 505 __le##bits res; \
@@ -508,15 +516,17 @@ static inline void btrfs_set_##name(struct extent_buffer *eb, \
508 unsigned long map_start; \ 516 unsigned long map_start; \
509 unsigned long map_len; \ 517 unsigned long map_len; \
510 unsigned long offset = offsetof(type, member); \ 518 unsigned long offset = offsetof(type, member); \
519 int unmap_on_exit = (eb->map_token == NULL); \
511 err = map_extent_buffer(eb, offset, \ 520 err = map_extent_buffer(eb, offset, \
512 sizeof(((type *)0)->member), \ 521 sizeof(((type *)0)->member), \
513 &map_token, &kaddr, \ 522 &map_token, &kaddr, \
514 &map_start, &map_len, KM_USER0); \ 523 &map_start, &map_len, KM_USER1); \
515 if (!err) { \ 524 if (!err) { \
516 __le##bits *tmp = (__le##bits *)(kaddr + offset - \ 525 __le##bits *tmp = (__le##bits *)(kaddr + offset - \
517 map_start); \ 526 map_start); \
518 *tmp = cpu_to_le##bits(val); \ 527 *tmp = cpu_to_le##bits(val); \
519 unmap_extent_buffer(eb, map_token, KM_USER0); \ 528 if (unmap_on_exit) \
529 unmap_extent_buffer(eb, map_token, KM_USER1); \
520 } else { \ 530 } else { \
521 val = cpu_to_le##bits(val); \ 531 val = cpu_to_le##bits(val); \
522 write_eb_member(eb, NULL, type, member, &val); \ 532 write_eb_member(eb, NULL, type, member, &val); \
@@ -769,7 +779,7 @@ static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
769} 779}
770 780
771/* struct btrfs_header */ 781/* struct btrfs_header */
772BTRFS_SETGET_HEADER_FUNCS(header_blocknr, struct btrfs_header, blocknr, 64); 782BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
773BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, 783BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
774 generation, 64); 784 generation, 64);
775BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); 785BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
@@ -817,24 +827,28 @@ static inline int btrfs_is_leaf(struct extent_buffer *eb)
817 827
818/* struct btrfs_root_item */ 828/* struct btrfs_root_item */
819BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32); 829BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
820BTRFS_SETGET_FUNCS(disk_root_blocknr, struct btrfs_root_item, blocknr, 64); 830BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
831BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
821 832
822BTRFS_SETGET_STACK_FUNCS(root_blocknr, struct btrfs_root_item, blocknr, 64); 833BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
834BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
823BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64); 835BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
824BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32); 836BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
825BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32); 837BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
826BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, blocks_used, 64); 838BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
827BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, block_limit, 64); 839BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
828 840
829/* struct btrfs_super_block */ 841/* struct btrfs_super_block */
830BTRFS_SETGET_STACK_FUNCS(super_blocknr, struct btrfs_super_block, blocknr, 64); 842BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
831BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, 843BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
832 generation, 64); 844 generation, 64);
833BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); 845BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
834BTRFS_SETGET_STACK_FUNCS(super_total_blocks, struct btrfs_super_block, 846BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
835 total_blocks, 64); 847 root_level, 8);
836BTRFS_SETGET_STACK_FUNCS(super_blocks_used, struct btrfs_super_block, 848BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
837 blocks_used, 64); 849 total_bytes, 64);
850BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
851 bytes_used, 64);
838BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, 852BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
839 sectorsize, 32); 853 sectorsize, 32);
840BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, 854BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
@@ -856,33 +870,33 @@ static inline unsigned long btrfs_file_extent_inline_start(struct
856 btrfs_file_extent_item *e) 870 btrfs_file_extent_item *e)
857{ 871{
858 unsigned long offset = (unsigned long)e; 872 unsigned long offset = (unsigned long)e;
859 offset += offsetof(struct btrfs_file_extent_item, disk_blocknr); 873 offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
860 return offset; 874 return offset;
861} 875}
862 876
863static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize) 877static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
864{ 878{
865 return offsetof(struct btrfs_file_extent_item, disk_blocknr) + datasize; 879 return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
866} 880}
867 881
868static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb, 882static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
869 struct btrfs_item *e) 883 struct btrfs_item *e)
870{ 884{
871 unsigned long offset; 885 unsigned long offset;
872 offset = offsetof(struct btrfs_file_extent_item, disk_blocknr); 886 offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
873 return btrfs_item_size(eb, e) - offset; 887 return btrfs_item_size(eb, e) - offset;
874} 888}
875 889
876BTRFS_SETGET_FUNCS(file_extent_disk_blocknr, struct btrfs_file_extent_item, 890BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
877 disk_blocknr, 64); 891 disk_bytenr, 64);
878BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item, 892BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
879 generation, 64); 893 generation, 64);
880BTRFS_SETGET_FUNCS(file_extent_disk_num_blocks, struct btrfs_file_extent_item, 894BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
881 disk_num_blocks, 64); 895 disk_num_bytes, 64);
882BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item, 896BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
883 offset, 64); 897 offset, 64);
884BTRFS_SETGET_FUNCS(file_extent_num_blocks, struct btrfs_file_extent_item, 898BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
885 num_blocks, 64); 899 num_bytes, 64);
886 900
887static inline struct btrfs_root *btrfs_sb(struct super_block *sb) 901static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
888{ 902{
@@ -906,6 +920,12 @@ static inline int btrfs_set_root_name(struct btrfs_root *root,
906 return 0; 920 return 0;
907} 921}
908 922
923static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
924 if (level == 0)
925 return root->leafsize;
926 return root->nodesize;
927}
928
909/* helper function to cast into the data area of the leaf. */ 929/* helper function to cast into the data area of the leaf. */
910#define btrfs_item_ptr(leaf, slot, type) \ 930#define btrfs_item_ptr(leaf, slot, type) \
911 ((type *)(btrfs_leaf_data(leaf) + \ 931 ((type *)(btrfs_leaf_data(leaf) + \
@@ -927,7 +947,7 @@ int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
927int btrfs_copy_pinned(struct btrfs_root *root, struct extent_map_tree *copy); 947int btrfs_copy_pinned(struct btrfs_root *root, struct extent_map_tree *copy);
928struct btrfs_block_group_cache *btrfs_lookup_block_group(struct 948struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
929 btrfs_fs_info *info, 949 btrfs_fs_info *info,
930 u64 blocknr); 950 u64 bytenr);
931struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root, 951struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
932 struct btrfs_block_group_cache 952 struct btrfs_block_group_cache
933 *hint, u64 search_start, 953 *hint, u64 search_start,
@@ -935,22 +955,22 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
935int btrfs_inc_root_ref(struct btrfs_trans_handle *trans, 955int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
936 struct btrfs_root *root); 956 struct btrfs_root *root);
937struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, 957struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
938 struct btrfs_root *root, u64 hint, 958 struct btrfs_root *root, u32 size,
939 u64 empty_size); 959 u64 hint, u64 empty_size);
940int btrfs_alloc_extent(struct btrfs_trans_handle *trans, 960int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
941 struct btrfs_root *root, u64 owner, 961 struct btrfs_root *root, u64 owner,
942 u64 num_blocks, u64 empty_size, u64 search_start, 962 u64 num_bytes, u64 empty_size, u64 search_start,
943 u64 search_end, struct btrfs_key *ins, int data); 963 u64 search_end, struct btrfs_key *ins, int data);
944int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, 964int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
945 struct extent_buffer *buf); 965 struct extent_buffer *buf);
946int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root 966int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
947 *root, u64 blocknr, u64 num_blocks, int pin); 967 *root, u64 bytenr, u64 num_bytes, int pin);
948int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, 968int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
949 struct btrfs_root *root, 969 struct btrfs_root *root,
950 struct extent_map_tree *unpin); 970 struct extent_map_tree *unpin);
951int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, 971int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
952 struct btrfs_root *root, 972 struct btrfs_root *root,
953 u64 blocknr, u64 num_blocks); 973 u64 bytenr, u64 num_bytes);
954int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, 974int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
955 struct btrfs_root *root); 975 struct btrfs_root *root);
956int btrfs_free_block_groups(struct btrfs_fs_info *info); 976int btrfs_free_block_groups(struct btrfs_fs_info *info);
@@ -1040,12 +1060,12 @@ int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1040int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, 1060int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
1041 struct btrfs_root *root, 1061 struct btrfs_root *root,
1042 u64 objectid, u64 pos, u64 offset, 1062 u64 objectid, u64 pos, u64 offset,
1043 u64 disk_num_blocks, 1063 u64 disk_num_bytes,
1044 u64 num_blocks); 1064 u64 num_bytes);
1045int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, 1065int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1046 struct btrfs_root *root, 1066 struct btrfs_root *root,
1047 struct btrfs_path *path, u64 objectid, 1067 struct btrfs_path *path, u64 objectid,
1048 u64 blocknr, int mod); 1068 u64 bytenr, int mod);
1049int btrfs_csum_file_block(struct btrfs_trans_handle *trans, 1069int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1050 struct btrfs_root *root, 1070 struct btrfs_root *root,
1051 u64 objectid, u64 offset, 1071 u64 objectid, u64 offset,