mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-24 04:34:08 +08:00
btrfs: pass the extent buffer for the btrfs_item_nr helpers
This 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. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
0e6c40ebbb
commit
42c9419a4c
@ -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);
|
||||
}
|
||||
|
@ -3033,13 +3033,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 */
|
||||
@ -3233,8 +3233,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) -
|
||||
@ -3272,8 +3272,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));
|
||||
}
|
||||
@ -3407,8 +3407,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,
|
||||
@ -3784,8 +3784,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));
|
||||
}
|
||||
|
||||
@ -4077,9 +4077,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 +
|
||||
@ -4333,8 +4334,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));
|
||||
}
|
||||
|
@ -2536,7 +2536,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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user