btrfs: a variety of header file cleanups
cover btrfs: a variety of header file cleanups
Hello,
While syncing accessors.[ch] I ran into a variety of oddities between what we do in the kernel vs what we do in btrfs-progs. Some of these things are just differently named helpers, some are helpers we need in progs but don't have in the kernel, and some of these are extent tree v2 stuff that was done in btrfs-progs but not yet merged into the kernel. I kept the v2 stuff very simple, it's mostly just updating helpers to take an extent_buffer.
Additionally I cleaned up how we do leaf manipulation, because those helpers are a little wonky and you have to understand how the leaves are laid out. I'm not in love with what I came up with, but it makes the code a little cleaner, and then it made the cleanups easier as there are only 4 sites that needed to be updated instead of 32.
I made these changes in tandem with the btrfs-progs sync of accessors.[ch], and then sync'ed the copy based on these changes. I can obviously update them both if there are changes required, but this is why the accessors.h looks different in my btrfs-progs patchset, because it's actually a copy of that file with these changes applied. Thanks,
Josef
Josef Bacik (11):
btrfs: move root helpers back into ctree.h
btrfs: move leaf_data_end into ctree.c
btrfs: move file_extent_item helpers into file-item.h
btrfs: move eb offset helpers into extent_io.h
btrfs: move the csum helpers into ctree.h
btrfs: pass the extent buffer for the btrfs_item_nr helpers
btrfs: add eb to btrfs_node_key_ptr_offset
btrfs: add helpers for manipulating leaf items and data
btrfs: remove BTRFS_LEAF_DATA_OFFSET
btrfs: add nr_global_roots to the super block definition
btrfs: add stack helpers for a few btrfs items
fs/btrfs/accessors.c | 2 +- fs/btrfs/accessors.h | 124 ++++++++---------- fs/btrfs/ctree.c | 218 ++++++++++++++++++++------------ fs/btrfs/ctree.h | 63 ++++----- fs/btrfs/extent_io.c | 10 +- fs/btrfs/extent_io.h | 33 +++++ fs/btrfs/file-item.h | 34 +++++ fs/btrfs/tree-checker.c | 5 +- fs/btrfs/tree-mod-log.c | 4 +- include/uapi/linux/btrfs_tree.h | 3 +- 10 files changed, 295 insertions(+), 201 deletions(-)
Signature · 1 line
2.26.3
PATCH 1/11 btrfs: move root helpers back into ctree.h
These accidentally got brought into accessors.h, but belong with the btrfs_root definitions which are currently in ctree.h. Move these to make it easier to sync accessors.[ch] into btrfs-progs.
--- fs/btrfs/accessors.h | 17 ----------------- fs/btrfs/ctree.h | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-)
fs/btrfs/accessors.h +0 -17
@@ -712,23 +712,6 @@ BTRFS_SETGET_STACK_FUNCS(root_otransid, struct btrfs_root_item, otransid, 64); BTRFS_SETGET_STACK_FUNCS(root_stransid, struct btrfs_root_item, stransid, 64); BTRFS_SETGET_STACK_FUNCS(root_rtransid, struct btrfs_root_item, rtransid, 64); -static inline bool btrfs_root_readonly (const struct btrfs_root *root) -{ -/* Byte-swap the constant at compile time, root_item::flags is LE */ -return (root->root_item.flags &cpu_to_le64 (BTRFS_ROOT_SUBVOL_RDONLY )) !=0 ; -} - -static inline bool btrfs_root_dead (const struct btrfs_root *root) -{ -/* Byte-swap the constant at compile time, root_item::flags is LE */ -return (root->root_item.flags &cpu_to_le64 (BTRFS_ROOT_SUBVOL_DEAD )) !=0 ; -} - -static inline u64 btrfs_root_id (const struct btrfs_root *root) -{ -return root->root_key.objectid; -} -/* struct btrfs_root_backup */ BTRFS_SETGET_STACK_FUNCS(backup_tree_root, struct btrfs_root_backup, tree_root,64 );
fs/btrfs/ctree.h +17 -0
@@ -335,6 +335,23 @@ struct btrfs_root {#endif }; +static inline bool btrfs_root_readonly (const struct btrfs_root *root) +{ +/* Byte-swap the constant at compile time, root_item::flags is LE */ +return (root->root_item.flags &cpu_to_le64 (BTRFS_ROOT_SUBVOL_RDONLY )) !=0 ; +} + +static inline bool btrfs_root_dead (const struct btrfs_root *root) +{ +/* Byte-swap the constant at compile time, root_item::flags is LE */ +return (root->root_item.flags &cpu_to_le64 (BTRFS_ROOT_SUBVOL_DEAD )) !=0 ; +} + +static inline u64 btrfs_root_id (const struct btrfs_root *root) +{ +return root->root_key.objectid; +} +/* * Structure that conveys information about an extent that is going to replace * all the extents in a file range.
Signature · 1 line
2.26.3
PATCH 2/11 btrfs: move leaf_data_end into ctree.c
In reply to Josef BacikThis is only used in ctree.c, with the exception of zero'ing out extent buffers we're getting ready to write out. In theory we shouldn't have an extent buffer with 0 items that we're writing out, however I'd rather be safe than sorry so open code it in extent_io.c, and then copy the helper into ctree.c. This will make it easier to sync accessors.[ch] into btrfs-progs, as this requires a helper that isn't defined in accessors.h.
--- fs/btrfs/accessors.h | 13 ------------- fs/btrfs/ctree.c | 13 +++++++++++++ fs/btrfs/extent_io.c | 6 +++++- 3 files changed, 18 insertions(+), 14 deletions(-)
fs/btrfs/accessors.h +0 -13
@@ -897,19 +897,6 @@ const char *btrfs_super_csum_name(u16 csum_type);const char *btrfs_super_csum_driver (u16 csum_type); size_t __attribute_const__ btrfs_get_num_csums(void); -/* -* The leaf data grows from end-to-front in the node. this returns the address -* of the start of the last item, which is the stop of the leaf data stack. -*/ -static inline unsigned int leaf_data_end (const struct extent_buffer *leaf) -{ -u32 nr =btrfs_header_nritems (leaf); - -if (nr ==0 ) -return BTRFS_LEAF_DATA_SIZE (leaf->fs_info); -return btrfs_item_offset (leaf, nr -1 ); -} -/* struct btrfs_file_extent_item */ BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item, type,8 );
fs/btrfs/ctree.c +13 -0
@@ -51,6 +51,19 @@ static const struct btrfs_csums { .driver = "blake2b-256" }, }; +/* +* The leaf data grows from end-to-front in the node. this returns the address +* of the start of the last item, which is the stop of the leaf data stack. +*/ +static inline unsigned int leaf_data_end (const struct extent_buffer *leaf) +{ +u32 nr =btrfs_header_nritems (leaf); + +if (nr ==0 ) +return BTRFS_LEAF_DATA_SIZE (leaf->fs_info); +return btrfs_item_offset (leaf, nr -1 ); +} +int btrfs_super_csum_size (const struct btrfs_super_block *s) {u16 t =btrfs_super_csum_type (s);
fs/btrfs/extent_io.c +5 -1
@@ -2664,7 +2664,11 @@ 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 ; +if (nritems ==0 ) + end +=BTRFS_LEAF_DATA_SIZE (eb->fs_info); +else + end +=btrfs_item_offset (eb, nritems -1 );memzero_extent_buffer (eb, start, end - start); } }
Signature · 1 line
2.26.3
PATCH 4/11 btrfs: move eb offset helpers into extent_io.h
In reply to Josef BacikThese are very specific to how the extent buffer is defined, so this differs between btrfs-progs and the kernel. Make things easier by moving these helpers into extent_io.h so we don't have to worry about this when syncing ctree.h.
--- fs/btrfs/ctree.h | 33 --------------------------------- fs/btrfs/extent_io.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 33 deletions(-)
fs/btrfs/ctree.h +0 -33
@@ -685,39 +685,6 @@ static inline int btrfs_next_item(struct btrfs_root *root, struct btrfs_path *p) }int btrfs_leaf_free_space (struct extent_buffer *leaf); -/* -* Get the correct offset inside the page of extent buffer. -* -* @eb: target extent buffer -* @start: offset inside the extent buffer -* -* Will handle both sectorsize == PAGE_SIZE and sectorsize < PAGE_SIZE cases. -*/ -static inline size_t get_eb_offset_in_page (const struct extent_buffer *eb, -unsigned long offset) -{ -/* -* For sectorsize == PAGE_SIZE case, eb->start will always be aligned -* to PAGE_SIZE, thus adding it won't cause any difference. -* -* For sectorsize < PAGE_SIZE, we must only read the data that belongs -* to the eb, thus we have to take the eb->start into consideration. -*/ -return offset_in_page (offset + eb->start); -} - -static inline unsigned long get_eb_page_index (unsigned long offset) -{ -/* -* For sectorsize == PAGE_SIZE case, plain >> PAGE_SHIFT is enough. -* -* For sectorsize < PAGE_SIZE case, we only support 64K PAGE_SIZE, -* and have ensured that all tree blocks are contained in one page, -* thus we always get index == 0. -*/ -return offset >>PAGE_SHIFT ; -} -static inline int is_fstree (u64 rootid) { if (rootid == BTRFS_FS_TREE_OBJECTID ||
fs/btrfs/extent_io.h +33 -0
@@ -94,6 +94,39 @@ struct extent_buffer {#endif }; +/* +* Get the correct offset inside the page of extent buffer. +* +* @eb: target extent buffer +* @start: offset inside the extent buffer +* +* Will handle both sectorsize == PAGE_SIZE and sectorsize < PAGE_SIZE cases. +*/ +static inline size_t get_eb_offset_in_page (const struct extent_buffer *eb, +unsigned long offset) +{ +/* +* For sectorsize == PAGE_SIZE case, eb->start will always be aligned +* to PAGE_SIZE, thus adding it won't cause any difference. +* +* For sectorsize < PAGE_SIZE, we must only read the data that belongs +* to the eb, thus we have to take the eb->start into consideration. +*/ +return offset_in_page (offset + eb->start); +} + +static inline unsigned long get_eb_page_index (unsigned long offset) +{ +/* +* For sectorsize == PAGE_SIZE case, plain >> PAGE_SHIFT is enough. +* +* For sectorsize < PAGE_SIZE case, we only support 64K PAGE_SIZE, +* and have ensured that all tree blocks are contained in one page, +* thus we always get index == 0. +*/ +return offset >>PAGE_SHIFT ; +} +/* * Structure to record how many bytes and which ranges are set/cleared */
Signature · 1 line
2.26.3
PATCH 3/11 btrfs: move file_extent_item helpers into file-item.h
In reply to Josef BacikThese helpers use functions that are in multiple places, which makes it tricky to sync them into btrfs-progs. Move them to file-item.h and then include file-item.h in places that use these helpers.
--- fs/btrfs/accessors.h | 22 ---------------------- fs/btrfs/ctree.c | 1 + fs/btrfs/ctree.h | 8 -------- fs/btrfs/file-item.h | 34 ++++++++++++++++++++++++++++++++++ fs/btrfs/tree-checker.c | 1 + 5 files changed, 36 insertions(+), 30 deletions(-)
fs/btrfs/accessors.h +0 -22
@@ -915,16 +915,6 @@ BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes,BTRFS_SETGET_STACK_FUNCS (stack_file_extent_compression, struct btrfs_file_extent_item, compression, 8); -static inline unsigned long btrfs_file_extent_inline_start ( -const struct btrfs_file_extent_item *e) -{ -return (unsigned long )e +BTRFS_FILE_EXTENT_INLINE_DATA_START ; -} - -static inline u32 btrfs_file_extent_calc_inline_size (u32 datasize) -{ -return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize; -} BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
@@ -946,18 +936,6 @@ BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item, BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item, other_encoding,16 ); -/* -* Returns the number of bytes used by the item on disk, minus the size of any -* extent headers. If a file is compressed on disk, this is the compressed -* size. -*/ -static inline u32 btrfs_file_extent_inline_item_len ( -const struct extent_buffer *eb, -int nr) -{ -return btrfs_item_size (eb, nr) -BTRFS_FILE_EXTENT_INLINE_DATA_START ; -} -/* btrfs_qgroup_status_item */ BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item, generation,64 );
fs/btrfs/ctree.c +1 -0
@@ -22,6 +22,7 @@#include "accessors.h" #include "extent-tree.h" #include "relocation.h" +#include "file-item.h" static struct kmem_cache *btrfs_path_cachep;
fs/btrfs/ctree.h +0 -8
@@ -460,14 +460,6 @@ 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 );
fs/btrfs/file-item.h +34 -0
@@ -3,6 +3,40 @@#ifndef BTRFS_FILE_ITEM_H #define BTRFS_FILE_ITEM_H +#include "accessors.h" + +#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 ; +} + +/* +* Returns the number of bytes used by the item on disk, minus the size of any +* extent headers. If a file is compressed on disk, this is the compressed +* size. +*/ +static inline u32 btrfs_file_extent_inline_item_len ( +const struct extent_buffer *eb, +int nr) +{ +return btrfs_item_size (eb, nr) -BTRFS_FILE_EXTENT_INLINE_DATA_START ; +} + +static inline unsigned long btrfs_file_extent_inline_start ( +const struct btrfs_file_extent_item *e) +{ +return (unsigned long )e +BTRFS_FILE_EXTENT_INLINE_DATA_START ; +} + +static inline u32 btrfs_file_extent_calc_inline_size (u32 datasize) +{ +return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize; +} +int btrfs_del_csums (struct btrfs_trans_handle *trans,struct btrfs_root *root,u64 bytenr,u64 len);blk_status_t btrfs_lookup_bio_sums (struct inode *inode,struct bio *bio,u8 *dst);
fs/btrfs/tree-checker.c +1 -0
@@ -28,6 +28,7 @@#include "btrfs_inode.h" #include "fs.h" #include "accessors.h" +#include "file-item.h" /* * Error message should follow the following format:
Signature · 1 line
2.26.3
PATCH 5/11 btrfs: move the csum helpers into ctree.h
In reply to Josef BacikThese got moved because of copy+paste, but this code exists in ctree.c, so move the declarations back into ctree.h.
--- fs/btrfs/accessors.h | 5 ----- fs/btrfs/ctree.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-)
fs/btrfs/accessors.h +0 -5
@@ -892,11 +892,6 @@ 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 ); -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); -size_t __attribute_const__ btrfs_get_num_csums(void); -/* struct btrfs_file_extent_item */ BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item, type,8 );
fs/btrfs/ctree.h +5 -0
@@ -699,6 +699,11 @@ static inline bool btrfs_is_data_reloc_root(const struct btrfs_root *root)return root->root_key.objectid ==BTRFS_DATA_RELOC_TREE_OBJECTID ; } +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); +size_t __attribute_const__ btrfs_get_num_csums(void); +/* * We use page status Private2 to indicate there is an ordered extent with * unfinished IO.
Signature · 1 line
2.26.3
PATCH 6/11 btrfs: pass the extent buffer for the btrfs_item_nr helpers
In reply to Josef BacikThis is actually a change for extent tree v2, but it exists in btrfs-progs but not in the kernel. This makes it annoying to sync accessors.h with btrfs-progs, and since this is the way I need it for extent-tree v2 simply update these helpers to take the extent buffer in order to make syncing possible now, and make the extent tree v2 stuff easier moving forward.
--- fs/btrfs/accessors.h | 18 +++++++++--------- fs/btrfs/ctree.c | 35 ++++++++++++++++++----------------- fs/btrfs/extent_io.c | 2 +- fs/btrfs/tree-checker.c | 4 ++-- 4 files changed, 30 insertions(+), 29 deletions(-)
fs/btrfs/accessors.h +9 -9
@@ -417,37 +417,37 @@ 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); \ }
@@ -462,7 +462,7 @@ 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); }
@@ -470,7 +470,7 @@ static inline void btrfs_item_key(const struct extent_buffer *eb,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/ctree.c +18 -17
@@ -3011,13 +3011,13 @@ static noinline int __push_leaf_right(struct btrfs_path *path,BTRFS_LEAF_DATA_OFFSET +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 */
@@ -3211,8 +3211,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) -
@@ -3250,8 +3250,8 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size,BTRFS_LEAF_DATA_OFFSET + 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 (left, push_items), (btrfs_header_nritems (right) - push_items) *sizeof (struct btrfs_item )); }
@@ -3385,8 +3385,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_extent_buffer(right, l,
@@ -3762,8 +3762,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 )); }
@@ -4055,9 +4055,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_extent_buffer(leaf, BTRFS_LEAF_DATA_OFFSET +
@@ -4311,8 +4312,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/extent_io.c +1 -1
@@ -2663,7 +2663,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 ;if (nritems ==0 ) end +=BTRFS_LEAF_DATA_SIZE (eb->fs_info);
fs/btrfs/tree-checker.c +2 -2
@@ -1784,10 +1784,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
PATCH 7/11 btrfs: add eb to btrfs_node_key_ptr_offset
In reply to Josef BacikThis is a change needed for extent tree v2, as we will be growing the header size. This exists in btrfs-progs currently, and not having it makes syncing accessors.[ch] more problematic. So make this change to set us up for extent tree v2 and match what btrfs-progs does to make syncing easier.
--- fs/btrfs/accessors.c | 2 +- fs/btrfs/accessors.h | 4 ++-- fs/btrfs/ctree.c | 28 ++++++++++++++-------------- fs/btrfs/extent_io.c | 2 +- fs/btrfs/tree-mod-log.c | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-)
fs/btrfs/accessors.c +1 -1
@@ -168,7 +168,7 @@ 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); +unsigned long ptr =btrfs_node_key_ptr_offset (eb, nr);read_eb_member (eb, (struct btrfs_key_ptr *)ptr, struct btrfs_key_ptr, key, disk_key); }
fs/btrfs/accessors.h +2 -2
@@ -392,7 +392,7 @@ static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb,btrfs_set_key_generation (eb, (struct btrfs_key_ptr *)ptr, val); } -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;
@@ -406,7 +406,7 @@ static inline void btrfs_set_node_key(const struct extent_buffer *eb, {unsigned long ptr; - ptr =btrfs_node_key_ptr_offset (nr); + ptr =btrfs_node_key_ptr_offset (eb, nr);write_eb_member (eb, (struct btrfs_key_ptr *)ptr, struct btrfs_key_ptr, key, disk_key); }
fs/btrfs/ctree.c +14 -14
@@ -2590,8 +2590,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) {
@@ -2599,8 +2599,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 )); }
@@ -2660,8 +2660,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 ));
@@ -2672,8 +2672,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);
@@ -2776,8 +2776,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) {
@@ -2859,8 +2859,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);
@@ -4218,8 +4218,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/extent_io.c +1 -1
@@ -2656,7 +2656,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
@@ -696,8 +696,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 9/11 btrfs: remove BTRFS_LEAF_DATA_OFFSET
In reply to Josef BacikThis is simply the same thing as btrfs_item_nr_offset(leaf, 0), so remove this helper and replace it's usage with the above statement.
--- fs/btrfs/accessors.h | 6 ++---- fs/btrfs/ctree.c | 8 ++++---- fs/btrfs/extent_io.c | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-)
fs/btrfs/accessors.h +2 -4
@@ -9,8 +9,6 @@ struct btrfs_map_token {unsigned long offset; }; -#define BTRFS_LEAF_DATA_OFFSET offsetof(struct btrfs_leaf, items) -void btrfs_init_map_token (struct btrfs_map_token *token,struct extent_buffer *eb);/*
@@ -1028,9 +1026,9 @@ BTRFS_SETGET_STACK_FUNCS(stack_verity_descriptor_size,/* Cast into the data area of the leaf. */ #define btrfs_item_ptr (leaf, slot, type) \ - ((type *)(BTRFS_LEAF_DATA_OFFSET + btrfs_item_offset(leaf, slot))) + ((type *)(btrfs_item_nr_offset(leaf, 0) + btrfs_item_offset(leaf, slot)))#define btrfs_item_ptr_offset (leaf, slot) \ - ((unsigned long)(BTRFS_LEAF_DATA_OFFSET + btrfs_item_offset(leaf, slot))) + ((unsigned long)(btrfs_item_nr_offset(leaf, 0) + btrfs_item_offset(leaf, slot)))#endif
fs/btrfs/ctree.c +4 -4
@@ -82,8 +82,8 @@ static inline void memmove_leaf_data(const struct extent_buffer *leaf, unsigned long src_offset, unsigned long len) { - memmove_extent_buffer(leaf, BTRFS_LEAF_DATA_OFFSET + dst_offset, - BTRFS_LEAF_DATA_OFFSET + src_offset, len); + memmove_extent_buffer(leaf, btrfs_item_nr_offset(leaf, 0) + dst_offset, + btrfs_item_nr_offset(leaf, 0) + src_offset, len); }/*
@@ -104,8 +104,8 @@ static inline void copy_leaf_data(const struct extent_buffer *dst,unsigned long dst_offset, unsigned long src_offset, unsigned long len) { - copy_extent_buffer(dst, src, BTRFS_LEAF_DATA_OFFSET + dst_offset, - BTRFS_LEAF_DATA_OFFSET + src_offset, len); + copy_extent_buffer(dst, src, btrfs_item_nr_offset(dst, 0) + dst_offset, + btrfs_item_nr_offset(src, 0) + src_offset, len); }/*
fs/btrfs/extent_io.c +1 -1
@@ -2664,7 +2664,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 (eb, nritems); - end =BTRFS_LEAF_DATA_OFFSET ; + end =btrfs_item_nr_offset (eb,0 );if (nritems ==0 ) end +=BTRFS_LEAF_DATA_SIZE (eb->fs_info);else
Signature · 1 line
2.26.3
PATCH 8/11 btrfs: add helpers for manipulating leaf items and data
In reply to Josef BacikWe have some gnarly memmove and copy_extent_buffer calls for leaf manipulation. This is because our item offsets aren't absolute, they're based on 0 being where the items start in the leaf, which is after the btrfs_header. This means any manipulation of the data requires adding sizeof(struct btrfs_header) to the offsets we pull from the items. Moving the items themselves is easier as the helpers are absolute offsets, however we of course have to call the helpers to get the offsets for the item numbers. This makes for copy_extent_buffer/memmove_extent_buffer calls that are kind of hard to reason about what's happening.
Fix this by pushing this logic into helpers. For data we'll only use the item provided offsets, and the helpers will use the BTRFS_LEAF_DATA_OFFSET addition for the offsets. Additionally for the item manipulation simply pass in the item numbers, and then the helpers will call the offset helper to get the actual offset into the leaf.
The diffstat makes this look like more code, but that's simply because I added comments for the helpers, it's net negative for the amount of code, and is easier to reason.
--- fs/btrfs/ctree.c | 177 +++++++++++++++++++++++++++++------------------ 1 file changed, 111 insertions(+), 66 deletions(-)
fs/btrfs/ctree.c +111 -66
@@ -65,6 +65,87 @@ static inline unsigned int leaf_data_end(const struct extent_buffer *leaf)return btrfs_item_offset (leaf, nr -1 ); } +/* +* memmove_leaf_data - memmove item data in a leaf +* @leaf: leaf that we're doing a memmove on +* @dst_offset: item data offset we're moving to +* @src_offset: item data offset were' moving from +* @len: length of the data we're moving +* +* This is just a wrapper around memmove_extent_buffer() that takes into account +* the header on the leaf. The btrfs_item offset's start directly after the +* header, so we have to adjust any offsets to account for the header in the +* leaf. This handles that math to simplify the callers. +*/ +static inline void memmove_leaf_data (const struct extent_buffer *leaf, +unsigned long dst_offset, +unsigned long src_offset, +unsigned long len) +{ +memmove_extent_buffer (leaf,BTRFS_LEAF_DATA_OFFSET + dst_offset, +BTRFS_LEAF_DATA_OFFSET + src_offset, len); +} + +/* +* copy_leaf_data - copy item data from src into dst at the given offset +* @dst: destination leaf that we're copying into +* @src: source leaf that we're copying from +* @dst_offset: item data offset we're copying to +* @src_offset: item data offset were' copying from +* @len: length of the data we're copying +* +* This is just a wrapper around copy_extent_buffer() that takes into account +* the header on the leaf. The btrfs_item offset's start directly after the +* header, so we have to adjust any offsets to account for the header in the +* leaf. This handles that math to simplify the callers. +*/ +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) +{ +copy_extent_buffer (dst, src,BTRFS_LEAF_DATA_OFFSET + dst_offset, +BTRFS_LEAF_DATA_OFFSET + src_offset, len); +} + +/* +* memmove_leaf_items - memmove items in a leaf +* @dst: destination leaf for the items +* @dst_item: the item nr we're copying into +* @src_item: the item nr we're copying from +* @nr_items: the number of items to copy +* +* This is just a wrapper around memmove_extent_buffer() that does the math to +* get the appropriate offsets into the leaf from the item numbers. +*/ +static inline void memmove_leaf_items (const struct extent_buffer *leaf, +int dst_item,int src_item,int nr_items) +{ +memmove_extent_buffer (leaf,btrfs_item_nr_offset (leaf, dst_item), +btrfs_item_nr_offset (leaf, src_item), + nr_items *sizeof (struct btrfs_item )); +} + +/* +* copy_leaf_items - copy items from src into dst at the given offset +* @dst: destination leaf for the items +* @src: source leaf for the items +* @dst_item: the item nr we're copying into +* @src_item: the item nr we're copying from +* @nr_items: the number of items to copy +* +* This is just a wrapper around copy_extent_buffer() that does the math to get +* the appropriate offsets into the leaf from the item numbers. +*/ +static inline void copy_leaf_items (const struct extent_buffer *dst, +const struct extent_buffer *src, +int dst_item,int src_item,int nr_items) +{ +copy_extent_buffer (dst, src,btrfs_item_nr_offset (dst, dst_item), +btrfs_item_nr_offset (src, src_item), + nr_items *sizeof (struct btrfs_item )); +} +int btrfs_super_csum_size (const struct btrfs_super_block *s) {u16 t =btrfs_super_csum_type (s);
@@ -3000,25 +3081,17 @@ 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 (right, push_items), -btrfs_item_nr_offset (right,0 ), - right_nritems *sizeof (struct btrfs_item )); +memmove_leaf_items (right, push_items,0 , right_nritems);/* copy the items from left to right */ -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 )); +copy_leaf_items (right, left,0 , left_nritems - push_items, push_items);/* update the item pointers */ btrfs_init_map_token (&token, right);
@@ -3210,19 +3283,13 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size,WARN_ON (!empty && push_items ==btrfs_header_nritems (right));/* push data from right to left */ -copy_extent_buffer (left, right, -btrfs_item_nr_offset (left,btrfs_header_nritems (left)), -btrfs_item_nr_offset (right,0 ), - push_items *sizeof (struct btrfs_item )); +copy_leaf_items (left, right,btrfs_header_nritems (left),0 , push_items); 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 );
@@ -3245,15 +3312,12 @@ 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 (right,0 ), -btrfs_item_nr_offset (left, push_items), - (btrfs_header_nritems (right) - push_items) * -sizeof (struct btrfs_item )); +memmove_leaf_items (right,0 , push_items, +btrfs_header_nritems (right) - push_items); }btrfs_init_map_token (&token, right);
@@ -3385,14 +3449,10 @@ 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 (right,0 ), -btrfs_item_nr_offset (l, mid), - nritems *sizeof (struct btrfs_item )); +copy_leaf_items (right, l,0 , mid, nritems); -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);
@@ -3762,9 +3822,7 @@ 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 (leaf, slot +1 ), -btrfs_item_nr_offset (leaf, slot), - (nritems - slot) *sizeof (struct btrfs_item )); +memmove_leaf_items (leaf, slot +1 , slot, nritems - slot); }btrfs_cpu_key_to_disk (&disk_key, new_key);
@@ -3875,9 +3933,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;
@@ -3902,9 +3959,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);
@@ -3969,9 +4025,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);
@@ -4055,16 +4110,11 @@ 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 (leaf, slot + batch->nr), -btrfs_item_nr_offset (leaf, slot), - (nritems - slot) *sizeof (struct btrfs_item )); +memmove_leaf_items (leaf, slot + batch->nr, slot, nritems - slot);/* 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; }
@@ -4299,10 +4349,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++) {
@@ -4312,10 +4360,7 @@ 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 (leaf, slot), -btrfs_item_nr_offset (leaf, slot + nr), -sizeof (struct btrfs_item ) * - (nritems - slot - nr)); +memmove_leaf_items (leaf, slot, slot + nr, nritems - slot - nr); }btrfs_set_header_nritems (leaf, nritems - nr); nritems -= nr;
Signature · 1 line
2.26.3
PATCH 10/11 btrfs: add nr_global_roots to the super block definition
In reply to Josef BacikWe already have this defined in btrfs-progs, add it to the kernel to make it easier to sync these files into btrfs-progs.
--- fs/btrfs/accessors.h | 2 ++ include/uapi/linux/btrfs_tree.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-)
fs/btrfs/accessors.h +2 -0
@@ -889,6 +889,8 @@ BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block, 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_nr_global_roots, struct btrfs_super_block, + nr_global_roots,64 );/* struct btrfs_file_extent_item */ BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item,
include/uapi/linux/btrfs_tree.h +2 -1
@@ -688,8 +688,9 @@ struct btrfs_super_block {/* The UUID written into btree blocks */ __u8 metadata_uuid[BTRFS_FSID_SIZE ]; +__u64 nr_global_roots; +/* Future expansion */ -__u8 reserved8[8 ];__le64 reserved[27 ];__u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE ];struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS ];
Signature · 1 line
2.26.3
PATCH 11/11 btrfs: add stack helpers for a few btrfs items
In reply to Josef BacikWe don't have these defined in the kernel because we don't have any users of these helpers. However we do use them in btrfs-progs, so define them to make keeping accessors.h in sync between progs and the kernel easier.
--- fs/btrfs/accessors.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
fs/btrfs/accessors.h +37 -0
@@ -221,12 +221,26 @@ static inline u64 btrfs_stripe_offset_nr(const struct extent_buffer *eb,return btrfs_stripe_offset (eb,btrfs_stripe_nr (c, nr)); } +static inline void btrfs_set_stripe_offset_nr (struct extent_buffer *eb, +struct btrfs_chunk *c,int nr, +u64 val) +{ +btrfs_set_stripe_offset (eb,btrfs_stripe_nr (c, nr), val); +} +static inline u64 btrfs_stripe_devid_nr (const struct extent_buffer *eb,struct btrfs_chunk *c,int nr) {return btrfs_stripe_devid (eb,btrfs_stripe_nr (c, nr)); } +static inline void btrfs_set_stripe_devid_nr (struct extent_buffer *eb, +struct btrfs_chunk *c,int nr, +u64 val) +{ +btrfs_set_stripe_devid (eb,btrfs_stripe_nr (c, nr), val); +} +/* struct btrfs_block_group_item */ BTRFS_SETGET_STACK_FUNCS(stack_block_group_used, struct btrfs_block_group_item, used,64 );
@@ -248,6 +262,8 @@ BTRFS_SETGET_FUNCS(free_space_flags, struct btrfs_free_space_info, flags, 32);/* struct btrfs_inode_ref */ BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); BTRFS_SETGET_FUNCS(inode_ref_index, struct btrfs_inode_ref, index, 64); +BTRFS_SETGET_STACK_FUNCS(stack_inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); +BTRFS_SETGET_STACK_FUNCS(stack_inode_ref_index, struct btrfs_inode_ref, index, 64);/* struct btrfs_inode_extref */ BTRFS_SETGET_FUNCS(inode_extref_parent, struct btrfs_inode_extref,
@@ -297,6 +313,14 @@ BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent, BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent, chunk_offset,64 ); BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64); +BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_tree, struct btrfs_dev_extent, + chunk_tree,64 ); +BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_objectid, struct btrfs_dev_extent, + chunk_objectid,64 ); +BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_chunk_offset, struct btrfs_dev_extent, + chunk_offset,64 ); +BTRFS_SETGET_STACK_FUNCS(stack_dev_extent_length, struct btrfs_dev_extent, length, 64); + BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64); BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item, generation, 64); BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64);
@@ -479,6 +503,9 @@ BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64); BTRFS_SETGET_FUNCS(root_ref_dirid, struct btrfs_root_ref, dirid, 64); BTRFS_SETGET_FUNCS(root_ref_sequence, struct btrfs_root_ref, sequence, 64); BTRFS_SETGET_FUNCS(root_ref_name_len, struct btrfs_root_ref, name_len, 16); +BTRFS_SETGET_STACK_FUNCS(stack_root_ref_dirid, struct btrfs_root_ref, dirid, 64); +BTRFS_SETGET_STACK_FUNCS(stack_root_ref_sequence, struct btrfs_root_ref, sequence, 64); +BTRFS_SETGET_STACK_FUNCS(stack_root_ref_name_len, struct btrfs_root_ref, name_len, 16);/* struct btrfs_dir_item */ BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
@@ -972,6 +999,16 @@ BTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item, rsv_rfer, 64); BTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item, rsv_excl,64 ); +BTRFS_SETGET_STACK_FUNCS (stack_qgroup_limit_flags, + struct btrfs_qgroup_limit_item, flags, 64); +BTRFS_SETGET_STACK_FUNCS (stack_qgroup_limit_max_rfer, + struct btrfs_qgroup_limit_item, max_rfer, 64); +BTRFS_SETGET_STACK_FUNCS (stack_qgroup_limit_max_excl, + struct btrfs_qgroup_limit_item, max_excl, 64); +BTRFS_SETGET_STACK_FUNCS (stack_qgroup_limit_rsv_rfer, + struct btrfs_qgroup_limit_item, rsv_rfer, 64); +BTRFS_SETGET_STACK_FUNCS (stack_qgroup_limit_rsv_excl, + struct btrfs_qgroup_limit_item, rsv_excl, 64);/* btrfs_dev_replace_item */ BTRFS_SETGET_FUNCS(dev_replace_src_devid,
Signature · 1 line
2.26.3
Quoted 23 lines · Josef Bacik
Hello,
While syncing accessors.[ch] I ran into a variety of oddities between what we do in the kernel vs what we do in btrfs-progs. Some of these things are just differently named helpers, some are helpers we need in progs but don't have in the kernel, and some of these are extent tree v2 stuff that was done in btrfs-progs but not yet merged into the kernel. I kept the v2 stuff very simple, it's mostly just updating helpers to take an
extent_buffer.Additionally I cleaned up how we do leaf manipulation, because those helpers are a little wonky and you have to understand how the leaves are laid out. I'm not in love with what I came up with, but it makes the code a little cleaner, and then it made the cleanups easier as there are only 4 sites that needed to be updated instead of 32.
I made these changes in tandem with the btrfs-progs sync of accessors.[ch], and then sync'ed the copy based on these changes. I can obviously update them both if there are changes required, but this is why the
accessors.hlooks different in my btrfs-progs patchset, because it's actually a copy of that file with these changes applied. Thanks,Josef
Quoted 12 lines
Josef Bacik (11):
btrfs: move root helpers back intoctree.h
btrfs: moveleaf_data_endintoctree.c
btrfs: movefile_extent_itemhelpers intofile-item.h
btrfs: move eb offset helpers intoextent_io.h
btrfs: move the csum helpers intoctree.h
btrfs: pass the extent buffer for thebtrfs_item_nrhelpers
btrfs: add eb tobtrfs_node_key_ptr_offset
btrfs: add helpers for manipulating leaf items and data
btrfs: removeBTRFS_LEAF_DATA_OFFSET
btrfs: addnr_global_rootsto the super block definition
btrfs: add stack helpers for a few btrfs items
Added to misc-next, thanks.