btrfs: item helper prep work for snapshot_id
cover btrfs: item helper prep work for snapshot_id
Hello,
I sent a bunch of patches previously to rework a lot of our helpers in preparation of adding the snapshot_id to the btrfs_header. I missed a few important areas with those patches, so here's the remaining work to make it easier to expand the size of the btrfs_header. These are general fixups and cleanups that don't rely on the extent tree v2 work. Thanks,
Josef
Josef Bacik (12):
btrfs: move btrfs_node_key into ctree.h
btrfs: add a btrfs_node_key_ptr helper, convert the users
btrfs: introduce *_leaf_data helpers
btrfs: make BTRFS_LEAF_DATA_OFFSET take an eb arg
btrfs: pass eb to the node_key_ptr helpers
btrfs: pass eb to the item_nr_offset helper
btrfs: add snapshot_id to the btrfs_header and related defs
btrfs: move the header SETGET funcs
btrfs: move the super SETGET funcs
btrfs: move BTRFS_LEAF related definitions below super SETGET funcs
btrfs: const-ify fs_info for the compat flag handlers
btrfs: use _offset helpers instead of offsetof in generic_bin_search
fs/btrfs/ctree.c | 151 ++++++------ fs/btrfs/ctree.h | 411 +++++++++++++++++--------------- fs/btrfs/extent_io.c | 6 +- fs/btrfs/struct-funcs.c | 8 - fs/btrfs/tree-checker.c | 4 +- fs/btrfs/tree-mod-log.c | 4 +- include/uapi/linux/btrfs_tree.h | 1 + 7 files changed, 303 insertions(+), 282 deletions(-)
Signature · 1 line
2.26.3
PATCH 1/12 btrfs: move btrfs_node_key into ctree.h
This is randomly in struct-funcs.c, well away from all of the other related functions, move this to where it's family lives.
--- fs/btrfs/ctree.h | 9 +++++++-- fs/btrfs/struct-funcs.c | 8 -------- 2 files changed, 7 insertions(+), 10 deletions(-)
fs/btrfs/ctree.h +7 -2
@@ -1998,8 +1998,13 @@ static inline unsigned long btrfs_node_key_ptr_offset(int nr)sizeof (struct btrfs_key_ptr ) * nr; } -void btrfs_node_key (const struct extent_buffer *eb, -struct btrfs_disk_key *disk_key,int nr); +static inline void btrfs_node_key (const struct extent_buffer *eb, +struct btrfs_disk_key *disk_key,int nr) +{ +unsigned long ptr =btrfs_node_key_ptr_offset (nr); + read_eb_member(eb, (struct btrfs_key_ptr *)ptr, struct btrfs_key_ptr, + key, disk_key); +}static inline void btrfs_set_node_key (const struct extent_buffer *eb,struct btrfs_disk_key *disk_key,int nr)
fs/btrfs/struct-funcs.c +0 -8
@@ -161,11 +161,3 @@ DEFINE_BTRFS_SETGET_BITS(8) DEFINE_BTRFS_SETGET_BITS(16) DEFINE_BTRFS_SETGET_BITS(32)DEFINE_BTRFS_SETGET_BITS (64 ) - -void btrfs_node_key (const struct extent_buffer *eb, -struct btrfs_disk_key *disk_key,int nr) -{ -unsigned long ptr =btrfs_node_key_ptr_offset (nr); -read_eb_member (eb, (struct btrfs_key_ptr *)ptr, - struct btrfs_key_ptr, key, disk_key); -}
Signature · 1 line
2.26.3
PATCH 2/12 btrfs: add a btrfs_node_key_ptr helper, convert the users
In reply to Josef BacikAll of the node helpers are getting the pointer offset and then casting to btrfs_key_ptr. Instead do this with a helper similar to how we do it with items and change all the helpers to use the new helper.
--- fs/btrfs/ctree.h | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-)
fs/btrfs/ctree.h +19 -29
@@ -1958,61 +1958,51 @@ BTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr, BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr, generation,64 ); -static inline u64 btrfs_node_blockptr (const struct extent_buffer *eb,int nr) +static inline unsigned long btrfs_node_key_ptr_offset (int nr) { -unsigned long ptr; - ptr = offsetof(struct btrfs_node , ptrs) + +return offsetof(struct btrfs_node , ptrs) +sizeof (struct btrfs_key_ptr ) * nr; -return btrfs_key_blockptr (eb, (struct btrfs_key_ptr *)ptr); +} + +static inline struct btrfs_key_ptr *btrfs_node_key_ptr (int nr) +{ +return (struct btrfs_key_ptr *)btrfs_node_key_ptr_offset (nr); +} + +static inline u64 btrfs_node_blockptr (const struct extent_buffer *eb,int nr) +{ +return btrfs_key_blockptr (eb,btrfs_node_key_ptr (nr)); }static inline void btrfs_set_node_blockptr (const struct extent_buffer *eb,int nr,u64 val) { -unsigned long ptr; - ptr = offsetof(struct btrfs_node , ptrs) + -sizeof (struct btrfs_key_ptr ) * nr; -btrfs_set_key_blockptr (eb, (struct btrfs_key_ptr *)ptr, val); +btrfs_set_key_blockptr (eb,btrfs_node_key_ptr (nr), val); }static inline u64 btrfs_node_ptr_generation (const struct extent_buffer *eb,int nr) { -unsigned long ptr; - ptr = offsetof(struct btrfs_node , ptrs) + -sizeof (struct btrfs_key_ptr ) * nr; -return btrfs_key_generation (eb, (struct btrfs_key_ptr *)ptr); +return btrfs_key_generation (eb,btrfs_node_key_ptr (nr)); }static inline void btrfs_set_node_ptr_generation (const struct extent_buffer *eb,int nr,u64 val) { -unsigned long ptr; - ptr = offsetof(struct btrfs_node , ptrs) + -sizeof (struct btrfs_key_ptr ) * nr; -btrfs_set_key_generation (eb, (struct btrfs_key_ptr *)ptr, val); -} - -static inline unsigned long btrfs_node_key_ptr_offset (int nr) -{ -return offsetof(struct btrfs_node , ptrs) + -sizeof (struct btrfs_key_ptr ) * nr; +btrfs_set_key_generation (eb,btrfs_node_key_ptr (nr), val); }static inline void btrfs_node_key (const struct extent_buffer *eb,struct btrfs_disk_key *disk_key,int nr) { -unsigned long ptr =btrfs_node_key_ptr_offset (nr); - read_eb_member(eb, (struct btrfs_key_ptr *)ptr, struct btrfs_key_ptr, - key, disk_key); + read_eb_member(eb, btrfs_node_key_ptr(nr), struct btrfs_key_ptr, key, + disk_key); }static inline void btrfs_set_node_key (const struct extent_buffer *eb,struct btrfs_disk_key *disk_key,int nr) { -unsigned long ptr; - ptr =btrfs_node_key_ptr_offset (nr); -write_eb_member (eb, (struct btrfs_key_ptr *)ptr, - struct btrfs_key_ptr, key, disk_key); + write_eb_member(eb, btrfs_node_key_ptr(nr), struct btrfs_key_ptr, key, + disk_key); }/* struct btrfs_item */
Signature · 1 line
2.26.3
Re: [PATCH 02/12] btrfs: add a btrfs_node_key_ptr helper, convert the users
Quoted 5 lines · Josef Bacik
All of the node helpers are getting the pointer offset and then casting to
btrfs_key_ptr. Instead do this with a helper similar to how we do it with items and change all the helpers to use the new helper.Signed-off-by Josef Bacik <[email protected]>
This patch is already included in the btrfs-progs: cleanup btrfs_item* accessors series as patch 12.
Re: [PATCH 02/12] btrfs: add a btrfs_node_key_ptr helper, convert the users
Quoted 11 lines · Nikolay Borisov
Quoted 5 lines · Josef Bacik
All of the node helpers are getting the pointer offset and then casting to btrfs_key_ptr. Instead do this with a helper similar to how we do it with items and change all the helpers to use the new helper.
Signed-off-by Josef Bacik <[email protected]>This patch is already included in the btrfs-progs: cleanup btrfs_item* accessors series as patch 12.
Ah, this is the kernel portion... disregard.
PATCH 3/12 btrfs: introduce *_leaf_data helpers
In reply to Josef BacikThe item offsets are set not taking into account the BTRFS_LEAF_DATA_OFFSET, which is to say they ignore the size of the header.
ie btrfs_item_offset(nr) is actually sizeof(struct btrfs_header) + btrfs_item_offset(nr) into the leaf.
Because of this anywhere we do memmove/copy of the item data we have to add BTRFS_LEAF_DATA_OFFSET to the offsets we're using. Which means we have the following pattern
copy_extent_buffer(src, dst,
BTRFS_LEAF_DATA_OFFSET + btrfs_item_offset(nr), BTRFS_LEAF_DATA_OFFSET + other_offset, size);
in a lot of spaces. Clean this up by adding two helpers that do the appropriate offset adjustment, and change all the users to simply pass in the item_offset offsets.
--- fs/btrfs/ctree.c | 84 ++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 38 deletions(-)
fs/btrfs/ctree.c +46 -38
@@ -43,6 +43,31 @@ static const struct btrfs_csums { .driver = "blake2b-256" }, }; +/* +* These helpers take the btrfs_item_offset() values and adjust them based on +* the header size. Do not use these with the value adjusted for the header, +* simply use the raw btrfs_item_offset() values. +*/ +static inline void memmove_leaf_data (const struct extent_buffer *dst, +unsigned long dst_offset, +unsigned long src_offset, +unsigned long len) +{ + dst_offset +=BTRFS_LEAF_DATA_OFFSET ; + src_offset +=BTRFS_LEAF_DATA_OFFSET ; +memmove_extent_buffer (dst, dst_offset, src_offset, len); +} + +static inline void copy_leaf_data (const struct extent_buffer *dst, +const struct extent_buffer *src, +unsigned long dst_offset, +unsigned long src_offset,unsigned long len) +{ + dst_offset +=BTRFS_LEAF_DATA_OFFSET ; + src_offset +=BTRFS_LEAF_DATA_OFFSET ; +copy_extent_buffer (dst, src, dst_offset, src_offset, len); +} +int btrfs_super_csum_size (const struct btrfs_super_block *s) {u16 t =btrfs_super_csum_type (s);
@@ -2880,16 +2905,12 @@ static noinline int __push_leaf_right(struct btrfs_path *path,/* make room in the right data area */ data_end =leaf_data_end (right); -memmove_extent_buffer (right, -BTRFS_LEAF_DATA_OFFSET + data_end - push_space, -BTRFS_LEAF_DATA_OFFSET + data_end, -BTRFS_LEAF_DATA_SIZE (fs_info) - data_end); +memmove_leaf_data (right, data_end - push_space, data_end, +BTRFS_LEAF_DATA_SIZE (fs_info) - data_end);/* copy from the left data area */ -copy_extent_buffer (right, left,BTRFS_LEAF_DATA_OFFSET + -BTRFS_LEAF_DATA_SIZE (fs_info) - push_space, -BTRFS_LEAF_DATA_OFFSET +leaf_data_end (left), - push_space); +copy_leaf_data (right, left,BTRFS_LEAF_DATA_SIZE (fs_info) - push_space, +leaf_data_end (left), push_space); memmove_extent_buffer(right, btrfs_item_nr_offset(push_items), btrfs_item_nr_offset(0),
@@ -3098,11 +3119,8 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size, push_space =BTRFS_LEAF_DATA_SIZE (fs_info) -btrfs_item_offset (right, push_items -1 ); -copy_extent_buffer (left, right,BTRFS_LEAF_DATA_OFFSET + -leaf_data_end (left) - push_space, -BTRFS_LEAF_DATA_OFFSET + -btrfs_item_offset (right, push_items -1 ), - push_space); +copy_leaf_data (left, right,leaf_data_end (left) - push_space, +btrfs_item_offset (right, push_items -1 ), push_space); old_left_nritems =btrfs_header_nritems (left);BUG_ON (old_left_nritems <=0 );
@@ -3125,10 +3143,9 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size,if (push_items < right_nritems) { push_space =btrfs_item_offset (right, push_items -1 ) -leaf_data_end (right); -memmove_extent_buffer (right,BTRFS_LEAF_DATA_OFFSET + -BTRFS_LEAF_DATA_SIZE (fs_info) - push_space, -BTRFS_LEAF_DATA_OFFSET + -leaf_data_end (right), push_space); +memmove_leaf_data (right, +BTRFS_LEAF_DATA_SIZE (fs_info) - push_space, +leaf_data_end (right), push_space); memmove_extent_buffer(right, btrfs_item_nr_offset(0), btrfs_item_nr_offset(push_items),
@@ -3269,10 +3286,8 @@ static noinline void copy_for_split(struct btrfs_trans_handle *trans,btrfs_item_nr_offset (mid), nritems * sizeof(struct btrfs_item)); -copy_extent_buffer (right, l, -BTRFS_LEAF_DATA_OFFSET +BTRFS_LEAF_DATA_SIZE (fs_info) - - data_copy_size,BTRFS_LEAF_DATA_OFFSET + -leaf_data_end (l), data_copy_size); +copy_leaf_data (right, l,BTRFS_LEAF_DATA_SIZE (fs_info) - data_copy_size, +leaf_data_end (l), data_copy_size); rt_data_off =BTRFS_LEAF_DATA_SIZE (fs_info) -btrfs_item_data_end (l, mid);
@@ -3755,9 +3770,8 @@ void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end)/* shift the data */ if (from_end) { -memmove_extent_buffer (leaf,BTRFS_LEAF_DATA_OFFSET + - data_end + size_diff,BTRFS_LEAF_DATA_OFFSET + - data_end, old_data_start + new_size - data_end); +memmove_leaf_data (leaf, data_end + size_diff, data_end, + old_data_start + new_size - data_end); }else {struct btrfs_disk_key disk_key;u64 offset;
@@ -3782,9 +3796,8 @@ void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end) } } -memmove_extent_buffer (leaf,BTRFS_LEAF_DATA_OFFSET + - data_end + size_diff,BTRFS_LEAF_DATA_OFFSET + - data_end, old_data_start - data_end); +memmove_leaf_data (leaf, data_end + size_diff, data_end, + old_data_start - data_end); offset =btrfs_disk_key_offset (&disk_key);btrfs_set_disk_key_offset (&disk_key, offset + size_diff);
@@ -3849,9 +3862,8 @@ void btrfs_extend_item(struct btrfs_path *path, u32 data_size) }/* shift the data */ -memmove_extent_buffer (leaf,BTRFS_LEAF_DATA_OFFSET + - data_end - data_size,BTRFS_LEAF_DATA_OFFSET + - data_end, old_data - data_end); +memmove_leaf_data (leaf, data_end - data_size, data_end, + old_data - data_end); data_end = old_data; old_size =btrfs_item_size (leaf, slot);
@@ -3939,10 +3951,8 @@ static void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *p (nritems - slot) * sizeof(struct btrfs_item));/* shift the data */ -memmove_extent_buffer (leaf,BTRFS_LEAF_DATA_OFFSET + - data_end - batch->total_data_size, -BTRFS_LEAF_DATA_OFFSET + data_end, - old_data - data_end); +memmove_leaf_data (leaf, data_end - batch->total_data_size, + data_end, old_data - data_end); data_end = old_data; }
@@ -4177,10 +4187,8 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,for (i =0 ; i < nr; i++) dsize +=btrfs_item_size (leaf, slot + i); -memmove_extent_buffer (leaf,BTRFS_LEAF_DATA_OFFSET + - data_end + dsize, -BTRFS_LEAF_DATA_OFFSET + data_end, - last_off - data_end); +memmove_leaf_data (leaf, data_end + dsize, data_end, + last_off - data_end);btrfs_init_map_token (&token, leaf);for (i = slot + nr; i < nritems; i++) {
Signature · 1 line
2.26.3
PATCH 4/12 btrfs: make BTRFS_LEAF_DATA_OFFSET take an eb arg
In reply to Josef BacikWhen I expand the size of the btrfs_header we're going to need to conditionally return a different offset.
--- fs/btrfs/ctree.c | 8 ++++---- fs/btrfs/ctree.h | 9 ++++++--- fs/btrfs/extent_io.c | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-)
fs/btrfs/ctree.c +4 -4
@@ -53,8 +53,8 @@ static inline void memmove_leaf_data(const struct extent_buffer *dst, unsigned long src_offset, unsigned long len) { - dst_offset +=BTRFS_LEAF_DATA_OFFSET ; - src_offset +=BTRFS_LEAF_DATA_OFFSET ; + dst_offset +=BTRFS_LEAF_DATA_OFFSET (dst); + src_offset +=BTRFS_LEAF_DATA_OFFSET (dst);memmove_extent_buffer (dst, dst_offset, src_offset, len); }
@@ -63,8 +63,8 @@ static inline void copy_leaf_data(const struct extent_buffer *dst,unsigned long dst_offset, unsigned long src_offset, unsigned long len) { - dst_offset += BTRFS_LEAF_DATA_OFFSET; - src_offset +=BTRFS_LEAF_DATA_OFFSET ; + dst_offset += BTRFS_LEAF_DATA_OFFSET(dst); + src_offset +=BTRFS_LEAF_DATA_OFFSET (dst);copy_extent_buffer (dst, src, dst_offset, src_offset, len); }
fs/btrfs/ctree.h +6 -3
@@ -1422,7 +1422,10 @@ static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info)return info->nodesize -sizeof (struct btrfs_header ); } -#define BTRFS_LEAF_DATA_OFFSET offsetof(struct btrfs_leaf, items) +static inline unsigned long BTRFS_LEAF_DATA_OFFSET (const struct extent_buffer *leaf) +{ +return offsetof(struct btrfs_leaf , items); +}static inline u32 BTRFS_MAX_ITEM_SIZE (const struct btrfs_fs_info *info) {
@@ -2692,11 +2695,11 @@ BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_right,/* helper function to cast into the data area of the leaf. */ #define btrfs_item_ptr (leaf, slot, type) \ - ((type *)(BTRFS_LEAF_DATA_OFFSET + \ + ((type *)(BTRFS_LEAF_DATA_OFFSET(leaf) + \ btrfs_item_offset(leaf, slot)))#define btrfs_item_ptr_offset (leaf, slot) \ - ((unsigned long)(BTRFS_LEAF_DATA_OFFSET + \ + ((unsigned long)(BTRFS_LEAF_DATA_OFFSET(leaf) + \ btrfs_item_offset(leaf, slot)))static inline u32 btrfs_crc32c (u32 crc,const void *address,unsigned length)
fs/btrfs/extent_io.c +1 -1
@@ -4508,7 +4508,7 @@ static void prepare_eb_write(struct extent_buffer *eb)* header 0 1 2 .. N ... data_N .. data_2 data_1 data_0 */ start =btrfs_item_nr_offset (nritems); - end =BTRFS_LEAF_DATA_OFFSET +leaf_data_end (eb); + end =BTRFS_LEAF_DATA_OFFSET (eb) +leaf_data_end (eb);memzero_extent_buffer (eb, start, end - start); } }
Signature · 1 line
2.26.3
PATCH 5/12 btrfs: pass eb to the node_key_ptr helpers
In reply to Josef BacikThese helpers are going to require the eb in order to determine the size of the header we need to use, so add the eb to the arguments and change all of the callers to pass in the eb.
--- fs/btrfs/ctree.c | 28 ++++++++++++++-------------- fs/btrfs/ctree.h | 20 +++++++++++--------- fs/btrfs/extent_io.c | 2 +- fs/btrfs/tree-mod-log.c | 4 ++-- 4 files changed, 28 insertions(+), 26 deletions(-)
fs/btrfs/ctree.c +14 -14
@@ -2495,8 +2495,8 @@ static int push_node_left(struct btrfs_trans_handle *trans,return ret; }copy_extent_buffer (dst, src, -btrfs_node_key_ptr_offset (dst_nritems), -btrfs_node_key_ptr_offset (0 ), +btrfs_node_key_ptr_offset (dst, dst_nritems), +btrfs_node_key_ptr_offset (src,0 ), push_items *sizeof (struct btrfs_key_ptr ));if (push_items < src_nritems) {
@@ -2504,8 +2504,8 @@ static int push_node_left(struct btrfs_trans_handle *trans,* Don't call btrfs_tree_mod_log_insert_move() here, key removal * was already fully logged by btrfs_tree_mod_log_eb_copy() above. */ -memmove_extent_buffer (src,btrfs_node_key_ptr_offset (0 ), -btrfs_node_key_ptr_offset (push_items), +memmove_extent_buffer (src,btrfs_node_key_ptr_offset (src,0 ), +btrfs_node_key_ptr_offset (src, push_items), (src_nritems - push_items) *sizeof (struct btrfs_key_ptr )); }
@@ -2565,8 +2565,8 @@ static int balance_node_right(struct btrfs_trans_handle *trans, } ret =btrfs_tree_mod_log_insert_move (dst, push_items,0 , dst_nritems);BUG_ON (ret <0 ); -memmove_extent_buffer (dst,btrfs_node_key_ptr_offset (push_items), -btrfs_node_key_ptr_offset (0 ), +memmove_extent_buffer (dst,btrfs_node_key_ptr_offset (dst, push_items), +btrfs_node_key_ptr_offset (dst,0 ), (dst_nritems) *sizeof (struct btrfs_key_ptr ));
@@ -2577,8 +2577,8 @@ static int balance_node_right(struct btrfs_trans_handle *trans,return ret; }copy_extent_buffer (dst, src, -btrfs_node_key_ptr_offset (0 ), -btrfs_node_key_ptr_offset (src_nritems - push_items), +btrfs_node_key_ptr_offset (dst,0 ), +btrfs_node_key_ptr_offset (src, src_nritems - push_items), push_items *sizeof (struct btrfs_key_ptr ));btrfs_set_header_nritems (src, src_nritems - push_items);
@@ -2681,8 +2681,8 @@ static void insert_ptr(struct btrfs_trans_handle *trans,BUG_ON (ret <0 ); }memmove_extent_buffer (lower, -btrfs_node_key_ptr_offset (slot +1 ), -btrfs_node_key_ptr_offset (slot), +btrfs_node_key_ptr_offset (lower, slot +1 ), +btrfs_node_key_ptr_offset (lower, slot), (nritems - slot) *sizeof (struct btrfs_key_ptr )); }if (level) {
@@ -2764,8 +2764,8 @@ static noinline int split_node(struct btrfs_trans_handle *trans,return ret; }copy_extent_buffer (split, c, -btrfs_node_key_ptr_offset (0 ), -btrfs_node_key_ptr_offset (mid), +btrfs_node_key_ptr_offset (split,0 ), +btrfs_node_key_ptr_offset (c, mid), (c_nritems - mid) *sizeof (struct btrfs_key_ptr ));btrfs_set_header_nritems (split, c_nritems - mid);btrfs_set_header_nritems (c, mid);
@@ -4106,8 +4106,8 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path,BUG_ON (ret <0 ); }memmove_extent_buffer (parent, -btrfs_node_key_ptr_offset (slot), -btrfs_node_key_ptr_offset (slot +1 ), +btrfs_node_key_ptr_offset (parent, slot), +btrfs_node_key_ptr_offset (parent, slot +1 ),sizeof (struct btrfs_key_ptr ) * (nritems - slot -1 )); }else if (level) {
fs/btrfs/ctree.h +11 -9
@@ -1961,50 +1961,52 @@ BTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr, BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr, generation,64 ); -static inline unsigned long btrfs_node_key_ptr_offset (int nr) +static inline unsigned long btrfs_node_key_ptr_offset (const struct extent_buffer *eb, +int nr) {return offsetof(struct btrfs_node , ptrs) +sizeof (struct btrfs_key_ptr ) * nr; } -static inline struct btrfs_key_ptr *btrfs_node_key_ptr (int nr) +static inline struct btrfs_key_ptr *btrfs_node_key_ptr (const struct extent_buffer *eb, +int nr) { -return (struct btrfs_key_ptr *)btrfs_node_key_ptr_offset (nr); +return (struct btrfs_key_ptr *)btrfs_node_key_ptr_offset (eb, nr); }static inline u64 btrfs_node_blockptr (const struct extent_buffer *eb,int nr) { -return btrfs_key_blockptr (eb,btrfs_node_key_ptr (nr)); +return btrfs_key_blockptr (eb,btrfs_node_key_ptr (eb, nr)); }static inline void btrfs_set_node_blockptr (const struct extent_buffer *eb,int nr,u64 val) { -btrfs_set_key_blockptr (eb,btrfs_node_key_ptr (nr), val); +btrfs_set_key_blockptr (eb,btrfs_node_key_ptr (eb, nr), val); }static inline u64 btrfs_node_ptr_generation (const struct extent_buffer *eb,int nr) { -return btrfs_key_generation (eb,btrfs_node_key_ptr (nr)); +return btrfs_key_generation (eb,btrfs_node_key_ptr (eb, nr)); }static inline void btrfs_set_node_ptr_generation (const struct extent_buffer *eb,int nr,u64 val) { -btrfs_set_key_generation (eb,btrfs_node_key_ptr (nr), val); +btrfs_set_key_generation (eb,btrfs_node_key_ptr (eb, nr), val); }static inline void btrfs_node_key (const struct extent_buffer *eb,struct btrfs_disk_key *disk_key,int nr) { - read_eb_member(eb, btrfs_node_key_ptr(nr), struct btrfs_key_ptr, key, + read_eb_member(eb, btrfs_node_key_ptr(eb, nr), struct btrfs_key_ptr, key, disk_key); }static inline void btrfs_set_node_key (const struct extent_buffer *eb,struct btrfs_disk_key *disk_key,int nr) { - write_eb_member(eb, btrfs_node_key_ptr(nr), struct btrfs_key_ptr, key, + write_eb_member(eb, btrfs_node_key_ptr(eb, nr), struct btrfs_key_ptr, key, disk_key); }
fs/btrfs/extent_io.c +1 -1
@@ -4500,7 +4500,7 @@ static void prepare_eb_write(struct extent_buffer *eb)/* Set btree blocks beyond nritems with 0 to avoid stale content */ nritems =btrfs_header_nritems (eb);if (btrfs_header_level (eb) >0 ) { - end =btrfs_node_key_ptr_offset (nritems); + end =btrfs_node_key_ptr_offset (eb, nritems);memzero_extent_buffer (eb, end, eb->len - end); }else {/*
fs/btrfs/tree-mod-log.c +2 -2
@@ -694,8 +694,8 @@ static void tree_mod_log_rewind(struct btrfs_fs_info *fs_info, n--;break ;case BTRFS_MOD_LOG_MOVE_KEYS : - o_dst =btrfs_node_key_ptr_offset (tm->slot); - o_src =btrfs_node_key_ptr_offset (tm->move.dst_slot); + o_dst =btrfs_node_key_ptr_offset (eb, tm->slot); + o_src =btrfs_node_key_ptr_offset (eb, tm->move.dst_slot);memmove_extent_buffer (eb, o_dst, o_src, tm->move.nr_items * p_size);break ;
Signature · 1 line
2.26.3
PATCH 6/12 btrfs: pass eb to the item_nr_offset helper
In reply to Josef BacikThis helper needs to know what version of the fs we're looking at to return the proper offset into the leaf where the item starts, so pass in the eb so we can get the proper offset.
--- fs/btrfs/ctree.c | 35 ++++++++++++++++++----------------- fs/btrfs/ctree.h | 20 +++++++++++--------- fs/btrfs/extent_io.c | 2 +- fs/btrfs/tree-checker.c | 4 ++-- 4 files changed, 32 insertions(+), 29 deletions(-)
fs/btrfs/ctree.c +18 -17
@@ -2912,13 +2912,13 @@ static noinline int __push_leaf_right(struct btrfs_path *path,copy_leaf_data (right, left,BTRFS_LEAF_DATA_SIZE (fs_info) - push_space,leaf_data_end (left), push_space); -memmove_extent_buffer (right,btrfs_item_nr_offset (push_items), -btrfs_item_nr_offset (0 ), +memmove_extent_buffer (right,btrfs_item_nr_offset (right, push_items), +btrfs_item_nr_offset (right,0 ), right_nritems *sizeof (struct btrfs_item ));/* copy the items from left to right */ -copy_extent_buffer (right, left,btrfs_item_nr_offset (0 ), -btrfs_item_nr_offset (left_nritems - push_items), +copy_extent_buffer (right, left,btrfs_item_nr_offset (right,0 ), +btrfs_item_nr_offset (left, left_nritems - push_items), push_items *sizeof (struct btrfs_item ));/* update the item pointers */
@@ -3112,8 +3112,8 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size,/* push data from right to left */ copy_extent_buffer (left, right, -btrfs_item_nr_offset (btrfs_header_nritems (left)), -btrfs_item_nr_offset (0 ), +btrfs_item_nr_offset (left,btrfs_header_nritems (left)), +btrfs_item_nr_offset (right,0 ), push_items *sizeof (struct btrfs_item )); push_space = BTRFS_LEAF_DATA_SIZE(fs_info) -
@@ -3147,8 +3147,8 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size,BTRFS_LEAF_DATA_SIZE (fs_info) - push_space, leaf_data_end(right), push_space); -memmove_extent_buffer (right,btrfs_item_nr_offset (0 ), -btrfs_item_nr_offset (push_items), +memmove_extent_buffer (right,btrfs_item_nr_offset (right,0 ), +btrfs_item_nr_offset (right, push_items), (btrfs_header_nritems (right) - push_items) *sizeof (struct btrfs_item )); }
@@ -3282,8 +3282,8 @@ static noinline void copy_for_split(struct btrfs_trans_handle *trans,btrfs_set_header_nritems (right, nritems); data_copy_size =btrfs_item_data_end (l, mid) -leaf_data_end (l); -copy_extent_buffer (right, l,btrfs_item_nr_offset (0 ), -btrfs_item_nr_offset (mid), +copy_extent_buffer (right, l,btrfs_item_nr_offset (right,0 ), +btrfs_item_nr_offset (l, mid), nritems *sizeof (struct btrfs_item )); copy_leaf_data(right, l, BTRFS_LEAF_DATA_SIZE(fs_info) - data_copy_size,
@@ -3657,8 +3657,8 @@ static noinline int split_item(struct btrfs_path *path, nritems =btrfs_header_nritems (leaf);if (slot != nritems) {/* shift the items */ -memmove_extent_buffer (leaf,btrfs_item_nr_offset (slot +1 ), -btrfs_item_nr_offset (slot), +memmove_extent_buffer (leaf,btrfs_item_nr_offset (leaf, slot +1 ), +btrfs_item_nr_offset (leaf, slot), (nritems - slot) *sizeof (struct btrfs_item )); }
@@ -3946,9 +3946,10 @@ static void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *p ioff - batch->total_data_size); }/* shift the items */ -memmove_extent_buffer (leaf,btrfs_item_nr_offset (slot + batch->nr), -btrfs_item_nr_offset (slot), - (nritems - slot) *sizeof (struct btrfs_item )); +memmove_extent_buffer (leaf, +btrfs_item_nr_offset (leaf, slot + batch->nr), +btrfs_item_nr_offset (leaf, slot), + (nritems - slot) *sizeof (struct btrfs_item ));/* shift the data */ memmove_leaf_data(leaf, data_end - batch->total_data_size,
@@ -4198,8 +4199,8 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,btrfs_set_token_item_offset (&token, i, ioff + dsize); } -memmove_extent_buffer (leaf,btrfs_item_nr_offset (slot), -btrfs_item_nr_offset (slot + nr), +memmove_extent_buffer (leaf,btrfs_item_nr_offset (leaf, slot), +btrfs_item_nr_offset (leaf, slot + nr),sizeof (struct btrfs_item ) * (nritems - slot - nr)); }
fs/btrfs/ctree.h +11 -9
@@ -2016,38 +2016,40 @@ BTRFS_SETGET_FUNCS(raw_item_size, struct btrfs_item, size, 32); BTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32); BTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32); -static inline unsigned long btrfs_item_nr_offset (int nr) +static inline unsigned long btrfs_item_nr_offset (const struct extent_buffer *eb, +int nr) {return offsetof(struct btrfs_leaf , items) +sizeof (struct btrfs_item ) * nr; } -static inline struct btrfs_item *btrfs_item_nr (int nr) +static inline struct btrfs_item *btrfs_item_nr (const struct extent_buffer *eb, +int nr) { -return (struct btrfs_item *)btrfs_item_nr_offset (nr); +return (struct btrfs_item *)btrfs_item_nr_offset (eb, nr); }#define BTRFS_ITEM_SETGET_FUNCS (member) \ static inline u32 btrfs_item_##member(const struct extent_buffer *eb, \ int slot) \ { \ - return btrfs_raw_item_##member(eb, btrfs_item_nr(slot)); \ + return btrfs_raw_item_##member(eb, btrfs_item_nr(eb, slot)); \ } \ static inline void btrfs_set_item_##member(const struct extent_buffer *eb, \ int slot, u32 val) \ { \ - btrfs_set_raw_item_##member(eb, btrfs_item_nr(slot), val); \ + btrfs_set_raw_item_##member(eb, btrfs_item_nr(eb, slot), val); \ } \ static inline u32 btrfs_token_item_##member(struct btrfs_map_token *token, \ int slot) \ { \ - struct btrfs_item *item = btrfs_item_nr(slot); \ + struct btrfs_item *item = btrfs_item_nr(token->eb, slot); \ return btrfs_token_raw_item_##member(token, item); \ } \ static inline void btrfs_set_token_item_##member(struct btrfs_map_token *token, \ int slot, u32 val) \ { \ - struct btrfs_item *item = btrfs_item_nr(slot); \ + struct btrfs_item *item = btrfs_item_nr(token->eb, slot); \ btrfs_set_token_raw_item_##member(token, item, val); \ }
@@ -2062,14 +2064,14 @@ static inline u32 btrfs_item_data_end(const struct extent_buffer *eb, int nr)static inline void btrfs_item_key (const struct extent_buffer *eb,struct btrfs_disk_key *disk_key,int nr) { -struct btrfs_item *item =btrfs_item_nr (nr); +struct btrfs_item *item =btrfs_item_nr (eb, nr); read_eb_member(eb, item, struct btrfs_item, key, disk_key); }static inline void btrfs_set_item_key (struct extent_buffer *eb,struct btrfs_disk_key *disk_key,int nr) { -struct btrfs_item *item =btrfs_item_nr (nr); +struct btrfs_item *item =btrfs_item_nr (eb, nr); write_eb_member(eb, item, struct btrfs_item, key, disk_key); }
fs/btrfs/extent_io.c +1 -1
@@ -4507,7 +4507,7 @@ static void prepare_eb_write(struct extent_buffer *eb)* Leaf: * header 0 1 2 .. N ... data_N .. data_2 data_1 data_0 */ - start =btrfs_item_nr_offset (nritems); + start =btrfs_item_nr_offset (eb, nritems); end =BTRFS_LEAF_DATA_OFFSET (eb) +leaf_data_end (eb);memzero_extent_buffer (eb, start, end - start); }
fs/btrfs/tree-checker.c +2 -2
@@ -1759,10 +1759,10 @@ static int check_leaf(struct extent_buffer *leaf, bool check_item_data)/* Also check if the item pointer overlaps with btrfs item. */ if (unlikely (btrfs_item_ptr_offset (leaf, slot) < -btrfs_item_nr_offset (slot) +sizeof (struct btrfs_item ))) { +btrfs_item_nr_offset (leaf, slot) +sizeof (struct btrfs_item ))) {generic_err (leaf, slot,"slot overlaps with its data, item end %lu data start %lu" , -btrfs_item_nr_offset (slot) + +btrfs_item_nr_offset (leaf, slot) +sizeof (struct btrfs_item ),btrfs_item_ptr_offset (leaf, slot));return -EUCLEAN ;
Signature · 1 line
2.26.3
Re: [PATCH 06/12] btrfs: pass eb to the item_nr_offset helper
Quoted 5 lines · Josef Bacik
This helper needs to know what version of the fs we're looking at to return the proper offset into the leaf where the item starts, so pass in the eb so we can get the proper offset.
Signed-off-by Josef Bacik <[email protected]>
Perhaps a patch can be included before this one which converts asll btrfs_item_nr_offset(, 0) into calls to BTRFS_LEAF_DATA_OFFSET as there seem to be a couple of those.
<snip>
PATCH 7/12 btrfs: add snapshot_id to the btrfs_header and related defs
In reply to Josef BacikThis adds the snapshot_id field to the btrfs_header, the HEADER_FLAG that we're going to use to indicate that we have the larger header, as well as the set/get helpers.
--- fs/btrfs/ctree.h | 19 +++++++++++++++++++ include/uapi/linux/btrfs_tree.h | 1 + 2 files changed, 20 insertions(+)
fs/btrfs/ctree.h +19 -0
@@ -179,6 +179,11 @@ struct btrfs_header {u8 level; } __attribute__ ((__packed__)); +struct btrfs_header_v2 { +struct btrfs_header header_v1; +__le64 snapshot_id; +} __attribute__ ((__packed__ )); +/* * this is a very generous portion of the super block, giving us * room to translate 14 chunks with 3 stripes each.
@@ -373,6 +378,11 @@ struct btrfs_leaf {struct btrfs_item items[]; } __attribute__ ((__packed__)); +struct btrfs_leaf_v2 { +struct btrfs_header_v2 header; +struct btrfs_item items[]; +} __attribute__ ((__packed__ )); +/* * all non-leaf blocks are nodes, they hold only keys and pointers to * other blocks
@@ -388,6 +398,11 @@ struct btrfs_node {struct btrfs_key_ptr ptrs[]; } __attribute__ ((__packed__)); +struct btrfs_node_v2 { +struct btrfs_header_v2 header; +struct btrfs_key_ptr ptrs[]; +} __attribute__ ((__packed__ )); +/* Read ahead values for struct btrfs_path.reada */ enum {READA_NONE ,
@@ -2235,12 +2250,16 @@ BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64); BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); +BTRFS_SETGET_HEADER_FUNCS(header_snapshot_id, struct btrfs_header_v2, + snapshot_id,64 ); BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header, generation,64 ); BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64); BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, nritems,32 ); BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64); +BTRFS_SETGET_STACK_FUNCS(stack_header_snapshot_id, struct btrfs_header_v2, + snapshot_id,64 );static inline int btrfs_header_flag (const struct extent_buffer *eb,u64 flag) {
include/uapi/linux/btrfs_tree.h +1 -0
@@ -496,6 +496,7 @@ struct btrfs_free_space_header {#define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)#define BTRFS_HEADER_FLAG_RELOC (1ULL << 1) +#define BTRFS_HEADER_FLAG_V2 (1ULL << 2)/* Super block flags */ /* Errors detected */
Signature · 1 line
2.26.3
PATCH 8/12 btrfs: move the header SETGET funcs
In reply to Josef BacikThese need to be above the item/key_ptr functions so we can read the header flags to determine which version of the header we have.
--- fs/btrfs/ctree.h | 103 +++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 52 deletions(-)
fs/btrfs/ctree.h +51 -52
@@ -1718,6 +1718,57 @@ static inline void btrfs_set_##name(type *s, u##bits val) \ put_unaligned_le##bits(val, &s->member); \ } +/* struct btrfs_header */ +BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); +BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, + generation,64 ); +BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); +BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); +BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64); +BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); +BTRFS_SETGET_HEADER_FUNCS(header_snapshot_id, struct btrfs_header_v2, + snapshot_id,64 ); +BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header, + generation,64 ); +BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64); +BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, + nritems,32 ); +BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64); +BTRFS_SETGET_STACK_FUNCS(stack_header_snapshot_id, struct btrfs_header_v2, + snapshot_id,64 ); + +static inline int btrfs_header_flag (const struct extent_buffer *eb,u64 flag) +{ +return (btrfs_header_flags (eb) & flag) == flag; +} + +static inline void btrfs_set_header_flag (struct extent_buffer *eb,u64 flag) +{ +u64 flags =btrfs_header_flags (eb); +btrfs_set_header_flags (eb, flags | flag); +} + +static inline void btrfs_clear_header_flag (struct extent_buffer *eb,u64 flag) +{ +u64 flags =btrfs_header_flags (eb); +btrfs_set_header_flags (eb, flags & ~flag); +} + +static inline int btrfs_header_backref_rev (const struct extent_buffer *eb) +{ +u64 flags =btrfs_header_flags (eb); +return flags >>BTRFS_BACKREF_REV_SHIFT ; +} + +static inline void btrfs_set_header_backref_rev (struct extent_buffer *eb, +int rev) +{ +u64 flags =btrfs_header_flags (eb); + flags &= ~BTRFS_BACKREF_REV_MASK ; + flags |= (u64 )rev <<BTRFS_BACKREF_REV_SHIFT ; +btrfs_set_header_flags (eb, flags); +} +static inline u64 btrfs_device_total_bytes (const struct extent_buffer *eb,struct btrfs_dev_item *s) {
@@ -1736,7 +1787,6 @@ static inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb,btrfs_set_64 (eb, s, offsetof(struct btrfs_dev_item , total_bytes), val); } - BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64); BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64); BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
@@ -2242,57 +2292,6 @@ static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb,#endif -/* struct btrfs_header */ -BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); -BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, - generation,64 ); -BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); -BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); -BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64); -BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); -BTRFS_SETGET_HEADER_FUNCS(header_snapshot_id, struct btrfs_header_v2, - snapshot_id,64 ); -BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header, - generation,64 ); -BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64); -BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, - nritems,32 ); -BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64); -BTRFS_SETGET_STACK_FUNCS(stack_header_snapshot_id, struct btrfs_header_v2, - snapshot_id,64 ); - -static inline int btrfs_header_flag (const struct extent_buffer *eb,u64 flag) -{ -return (btrfs_header_flags (eb) & flag) == flag; -} - -static inline void btrfs_set_header_flag (struct extent_buffer *eb,u64 flag) -{ -u64 flags =btrfs_header_flags (eb); -btrfs_set_header_flags (eb, flags | flag); -} - -static inline void btrfs_clear_header_flag (struct extent_buffer *eb,u64 flag) -{ -u64 flags =btrfs_header_flags (eb); -btrfs_set_header_flags (eb, flags & ~flag); -} - -static inline int btrfs_header_backref_rev (const struct extent_buffer *eb) -{ -u64 flags =btrfs_header_flags (eb); -return flags >>BTRFS_BACKREF_REV_SHIFT ; -} - -static inline void btrfs_set_header_backref_rev (struct extent_buffer *eb, -int rev) -{ -u64 flags =btrfs_header_flags (eb); - flags &= ~BTRFS_BACKREF_REV_MASK ; - flags |= (u64 )rev <<BTRFS_BACKREF_REV_SHIFT ; -btrfs_set_header_flags (eb, flags); -} -static inline int btrfs_is_leaf (const struct extent_buffer *eb) {return btrfs_header_level (eb) ==0 ;
Signature · 1 line
2.26.3
PATCH 9/12 btrfs: move the super SETGET funcs
In reply to Josef BacikSome of the helpers are going to need to check fs_incompat flags, so we need these helpers to be higher up in ctree.h.
--- fs/btrfs/ctree.h | 158 +++++++++++++++++++++++------------------------ 1 file changed, 79 insertions(+), 79 deletions(-)
fs/btrfs/ctree.h +79 -79
@@ -1769,6 +1769,85 @@ static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,btrfs_set_header_flags (eb, flags); } +/* struct btrfs_super_block */ +BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); +BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64); +BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, + generation,64 ); +BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); +BTRFS_SETGET_STACK_FUNCS (super_sys_array_size, + struct btrfs_super_block, sys_chunk_array_size, 32); +BTRFS_SETGET_STACK_FUNCS (super_chunk_root_generation, + struct btrfs_super_block, chunk_root_generation, 64); +BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block, + root_level,8 ); +BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block, + chunk_root,64 ); +BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block, + chunk_root_level,8 ); +BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block, + log_root,64 ); +BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block, + log_root_transid,64 ); +BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block, + log_root_level,8 ); +BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block, + total_bytes,64 ); +BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block, + bytes_used,64 ); +BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, + sectorsize,32 ); +BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, + nodesize,32 ); +BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, + stripesize,32 ); +BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, + root_dir_objectid,64 ); +BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block, + num_devices,64 ); +BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block, + compat_flags,64 ); +BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block, + compat_ro_flags,64 ); +BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, + incompat_flags,64 ); +BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, + csum_type,16 ); +BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block, + cache_generation,64 ); +BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64); +BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, + uuid_tree_generation,64 ); +BTRFS_SETGET_STACK_FUNCS(super_block_group_root, struct btrfs_super_block, + block_group_root,64 ); +BTRFS_SETGET_STACK_FUNCS (super_block_group_root_generation, + struct btrfs_super_block, + block_group_root_generation,64 ); +BTRFS_SETGET_STACK_FUNCS(super_block_group_root_level, struct btrfs_super_block, + block_group_root_level,8 ); +BTRFS_SETGET_STACK_FUNCS(super_nr_global_roots, struct btrfs_super_block, + nr_global_roots,64 ); + +#define btrfs_fs_incompat (fs_info, opt) \ + __btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##opt) + +static inline bool __btrfs_fs_incompat (struct btrfs_fs_info *fs_info,u64 flag) +{ +struct btrfs_super_block *disk_super; + disk_super = fs_info->super_copy; +return !!(btrfs_super_incompat_flags (disk_super) & flag); +} + +#define btrfs_fs_compat_ro (fs_info, opt) \ + __btrfs_fs_compat_ro((fs_info), BTRFS_FEATURE_COMPAT_RO_##opt) + +static inline int __btrfs_fs_compat_ro (struct btrfs_fs_info *fs_info,u64 flag) +{ +struct btrfs_super_block *disk_super; + disk_super = fs_info->super_copy; +return !!(btrfs_super_compat_ro_flags (disk_super) & flag); +} +static inline u64 btrfs_device_total_bytes (const struct extent_buffer *eb,struct btrfs_dev_item *s) {
@@ -2489,65 +2568,6 @@ btrfs_cpu_balance_args_to_disk(struct btrfs_disk_balance_args *disk, disk->stripes_max =cpu_to_le32 (cpu->stripes_max); } -/* struct btrfs_super_block */ -BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); -BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64); -BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, - generation,64 ); -BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); -BTRFS_SETGET_STACK_FUNCS (super_sys_array_size, - struct btrfs_super_block, sys_chunk_array_size, 32); -BTRFS_SETGET_STACK_FUNCS (super_chunk_root_generation, - struct btrfs_super_block, chunk_root_generation, 64); -BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block, - root_level,8 ); -BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block, - chunk_root,64 ); -BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block, - chunk_root_level,8 ); -BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block, - log_root,64 ); -BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block, - log_root_transid,64 ); -BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block, - log_root_level,8 ); -BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block, - total_bytes,64 ); -BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block, - bytes_used,64 ); -BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, - sectorsize,32 ); -BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, - nodesize,32 ); -BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, - stripesize,32 ); -BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, - root_dir_objectid,64 ); -BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block, - num_devices,64 ); -BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block, - compat_flags,64 ); -BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block, - compat_ro_flags,64 ); -BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, - incompat_flags,64 ); -BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, - csum_type,16 ); -BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block, - cache_generation,64 ); -BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64); -BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, - uuid_tree_generation,64 ); -BTRFS_SETGET_STACK_FUNCS(super_block_group_root, struct btrfs_super_block, - block_group_root,64 ); -BTRFS_SETGET_STACK_FUNCS (super_block_group_root_generation, - struct btrfs_super_block, - block_group_root_generation,64 ); -BTRFS_SETGET_STACK_FUNCS(super_block_group_root_level, struct btrfs_super_block, - block_group_root_level,8 ); -BTRFS_SETGET_STACK_FUNCS(super_nr_global_roots, struct btrfs_super_block, - nr_global_roots,64 ); -int btrfs_super_csum_size (const struct btrfs_super_block *s);const char *btrfs_super_csum_name (u16 csum_type);const char *btrfs_super_csum_driver (u16 csum_type);
@@ -3773,16 +3793,6 @@ static inline void __btrfs_clear_fs_incompat(struct btrfs_fs_info *fs_info, } } -#define btrfs_fs_incompat (fs_info, opt) \ - __btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##opt) - -static inline bool __btrfs_fs_incompat (struct btrfs_fs_info *fs_info,u64 flag) -{ -struct btrfs_super_block *disk_super; - disk_super = fs_info->super_copy; -return !!(btrfs_super_incompat_flags (disk_super) & flag); -} -#define btrfs_set_fs_compat_ro (__fs_info, opt) \ __btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \ #opt)
@@ -3835,16 +3845,6 @@ static inline void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, } } -#define btrfs_fs_compat_ro (fs_info, opt) \ - __btrfs_fs_compat_ro((fs_info), BTRFS_FEATURE_COMPAT_RO_##opt) - -static inline int __btrfs_fs_compat_ro (struct btrfs_fs_info *fs_info,u64 flag) -{ -struct btrfs_super_block *disk_super; - disk_super = fs_info->super_copy; -return !!(btrfs_super_compat_ro_flags (disk_super) & flag); -} -/* acl.c */ #ifdef CONFIG_BTRFS_FS_POSIX_ACL struct posix_acl *btrfs_get_acl (struct inode *inode,int type,bool rcu);
Signature · 1 line
2.26.3
PATCH 10/12 btrfs: move BTRFS_LEAF related definitions below super SETGET funcs
In reply to Josef BacikWe're going to need to do btrfs_fs_incompat(fs_info, EXTENT_TREE_V2), which requires reading the super flags, so move these helpers below the super SETGET funcs.
--- fs/btrfs/ctree.h | 69 ++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 35 deletions(-)
fs/btrfs/ctree.h +34 -35
@@ -1430,41 +1430,6 @@ struct btrfs_file_private {void *filldir_buf; }; - -static inline u32 BTRFS_LEAF_DATA_SIZE (const struct btrfs_fs_info *info) -{ - -return info->nodesize -sizeof (struct btrfs_header ); -} - -static inline unsigned long BTRFS_LEAF_DATA_OFFSET (const struct extent_buffer *leaf) -{ -return offsetof(struct btrfs_leaf , items); -} - -static inline u32 BTRFS_MAX_ITEM_SIZE (const struct btrfs_fs_info *info) -{ -return BTRFS_LEAF_DATA_SIZE (info) -sizeof (struct btrfs_item ); -} - -static inline u32 BTRFS_NODEPTRS_PER_BLOCK (const struct btrfs_fs_info *info) -{ -return BTRFS_LEAF_DATA_SIZE (info) /sizeof (struct btrfs_key_ptr ); -} - -#define BTRFS_FILE_EXTENT_INLINE_DATA_START \ - (offsetof(struct btrfs_file_extent_item, disk_bytenr)) -static inline u32 BTRFS_MAX_INLINE_DATA_SIZE (const struct btrfs_fs_info *info) -{ -return BTRFS_MAX_ITEM_SIZE (info) - -BTRFS_FILE_EXTENT_INLINE_DATA_START ; -} - -static inline u32 BTRFS_MAX_XATTR_SIZE (const struct btrfs_fs_info *info) -{ -return BTRFS_MAX_ITEM_SIZE (info) -sizeof (struct btrfs_dir_item ); -} -/* * Flags for mount options. *
@@ -2219,6 +2184,40 @@ static inline void btrfs_set_item_key(struct extent_buffer *eb, write_eb_member(eb, item, struct btrfs_item, key, disk_key); } +static inline u32 BTRFS_LEAF_DATA_SIZE (const struct btrfs_fs_info *info) +{ + +return info->nodesize -sizeof (struct btrfs_header ); +} + +static inline unsigned long BTRFS_LEAF_DATA_OFFSET (const struct extent_buffer *leaf) +{ +return offsetof(struct btrfs_leaf , items); +} + +static inline u32 BTRFS_MAX_ITEM_SIZE (const struct btrfs_fs_info *info) +{ +return BTRFS_LEAF_DATA_SIZE (info) -sizeof (struct btrfs_item ); +} + +static inline u32 BTRFS_NODEPTRS_PER_BLOCK (const struct btrfs_fs_info *info) +{ +return BTRFS_LEAF_DATA_SIZE (info) /sizeof (struct btrfs_key_ptr ); +} + +#define BTRFS_FILE_EXTENT_INLINE_DATA_START \ + (offsetof(struct btrfs_file_extent_item, disk_bytenr)) +static inline u32 BTRFS_MAX_INLINE_DATA_SIZE (const struct btrfs_fs_info *info) +{ +return BTRFS_MAX_ITEM_SIZE (info) - +BTRFS_FILE_EXTENT_INLINE_DATA_START ; +} + +static inline u32 BTRFS_MAX_XATTR_SIZE (const struct btrfs_fs_info *info) +{ +return BTRFS_MAX_ITEM_SIZE (info) -sizeof (struct btrfs_dir_item ); +} + BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64);/*
Signature · 1 line
2.26.3
PATCH 11/12 btrfs: const-ify fs_info for the compat flag handlers
In reply to Josef BacikWe don't modify fs_info here, use const.
--- fs/btrfs/ctree.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/ctree.h +2 -2
@@ -1796,7 +1796,7 @@ BTRFS_SETGET_STACK_FUNCS(super_nr_global_roots, struct btrfs_super_block,#define btrfs_fs_incompat (fs_info, opt) \ __btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##opt) -static inline bool __btrfs_fs_incompat (struct btrfs_fs_info *fs_info,u64 flag) +static inline bool __btrfs_fs_incompat (const struct btrfs_fs_info *fs_info,u64 flag) {struct btrfs_super_block *disk_super; disk_super = fs_info->super_copy;
@@ -1806,7 +1806,7 @@ static inline bool __btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag)#define btrfs_fs_compat_ro (fs_info, opt) \ __btrfs_fs_compat_ro((fs_info), BTRFS_FEATURE_COMPAT_RO_##opt) -static inline int __btrfs_fs_compat_ro (struct btrfs_fs_info *fs_info,u64 flag) +static inline int __btrfs_fs_compat_ro (const struct btrfs_fs_info *fs_info,u64 flag) {struct btrfs_super_block *disk_super; disk_super = fs_info->super_copy;
Signature · 1 line
2.26.3
PATCH 12/12 btrfs: use _offset helpers instead of offsetof in generic_bin_search
In reply to Josef BacikThe starting offset for the items/keys are going to be dependent on extent tree v2, use the helpers instead of offsetof directly.
--- fs/btrfs/ctree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/ctree.c +2 -2
@@ -781,10 +781,10 @@ static noinline int generic_bin_search(struct extent_buffer *eb, int low, }if (btrfs_header_level (eb) ==0 ) { - p = offsetof(struct btrfs_leaf , items); + p =btrfs_item_nr_offset (eb,0 ); item_size =sizeof (struct btrfs_item ); }else { - p = offsetof(struct btrfs_node , ptrs); + p =btrfs_node_key_ptr_offset (eb,0 ); item_size =sizeof (struct btrfs_key_ptr ); }
Signature · 1 line
2.26.3
Re: [PATCH 12/12] btrfs: use _offset helpers instead of offsetof in generic_bin_search
Quoted 13 lines · Josef Bacik
The starting offset for the items/keys are going to be dependent on extent tree v2, use the helpers instead of offsetof directly.
Signed-off-by Josef Bacik <[email protected]>--- fs/btrfs/ctree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/btrfs/ctree.c +0
-0
fs/btrfs/ctree.c static noinline int generic_bin_search(struct extent_buffer *eb, int low, · line 784
Quoted 5 lines
fs/btrfs/ctree.c +1
-1@@ -781,10 +781,10 @@ static noinline int generic_bin_search(struct extent_buffer *eb, int low, }if (btrfs_header_level (eb) ==0 ) { - p = offsetof(struct btrfs_leaf , items); + p =btrfs_item_nr_offset (eb,0 );
nit: This could be switched to BTRFS_LEAF_DATA_OFFSET.
Quoted 7 lines
fs/btrfs/ctree.c +1
-1item_size =sizeof (struct btrfs_item ); }else { - p = offsetof(struct btrfs_node , ptrs); + p =btrfs_node_key_ptr_offset (eb,0 ); item_size =sizeof (struct btrfs_key_ptr ); }
Quoted 24 lines · Josef Bacik
Hello,
I sent a bunch of patches previously to rework a lot of our helpers in preparation of adding the
snapshot_idto thebtrfs_header. I missed a few important areas with those patches, so here's the remaining work to make it easier to expand the size of thebtrfs_header. These are general fixups and cleanups that don't rely on the extent tree v2 work. Thanks,Josef
Josef Bacik (12):
btrfs: movebtrfs_node_keyintoctree.h
btrfs: add abtrfs_node_key_ptrhelper, convert the users
btrfs: introduce*_leaf_datahelpers
btrfs: makeBTRFS_LEAF_DATA_OFFSETtake an eb arg
btrfs: pass eb to thenode_key_ptrhelpers
btrfs: pass eb to theitem_nr_offsethelper
btrfs: addsnapshot_idto thebtrfs_headerand related defs
btrfs: move the header SETGET funcs
btrfs: move the super SETGET funcs
btrfs: moveBTRFS_LEAFrelated definitions below super SETGET funcs
btrfs: const-ifyfs_infofor the compat flag handlers
btrfs: use_offsethelpers instead of offsetof ingeneric_bin_search
Quoted 9 lines
fs/btrfs/ctree.c | 151 ++++++------ fs/btrfs/ctree.h | 411 +++++++++++++++++--------------- fs/btrfs/extent_io.c | 6 +- fs/btrfs/struct-funcs.c | 8 - fs/btrfs/tree-checker.c | 4 +- fs/btrfs/tree-mod-log.c | 4 +- include/uapi/linux/btrfs_tree.h | 1 + 7 files changed, 303 insertions(+), 282 deletions(-)
Overall LGTM:
Quoted 37 lines · Nikolay Borisov
Quoted 24 lines · Josef Bacik
Hello,
I sent a bunch of patches previously to rework a lot of our helpers in preparation of adding the
snapshot_idto the btrfs_header. I missed a few important areas with those patches, so here's the remaining work to make it easier to expand the size of the btrfs_header. These are general fixups and cleanups that don't rely on the extent tree v2 work. Thanks,Josef
Josef Bacik (12):
btrfs: movebtrfs_node_keyintoctree.h
btrfs: add abtrfs_node_key_ptrhelper, convert the users
btrfs: introduce*_leaf_datahelpers
btrfs: makeBTRFS_LEAF_DATA_OFFSETtake an eb arg
btrfs: pass eb to thenode_key_ptrhelpers
btrfs: pass eb to theitem_nr_offsethelper
btrfs: addsnapshot_idto thebtrfs_headerand related defs
btrfs: move the header SETGET funcs
btrfs: move the super SETGET funcs
btrfs: moveBTRFS_LEAFrelated definitions below super SETGET funcs
btrfs: const-ifyfs_infofor the compat flag handlers
btrfs: use_offsethelpers instead of offsetof ingeneric_bin_searchQuoted 9 lines
fs/btrfs/ctree.c | 151 ++++++------ fs/btrfs/ctree.h | 411 +++++++++++++++++--------------- fs/btrfs/extent_io.c | 6 +-
fs/btrfs/struct-funcs.c | 8 - fs/btrfs/tree-checker.c | 4 +- fs/btrfs/tree-mod-log.c | 4 +- include/uapi/linux/btrfs_tree.h | 1 + 7 files changed, 303 insertions(+), 282 deletions(-)
Quoted 3 lines
Overall LGTM:
Reviewed-by Nikolay Borisov <[email protected]>
Also Reviewed-by: Sweet Tea Dorminy <[email protected]>, for what it's worth.