Commit e23efd8e authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: add eb to btrfs_node_key_ptr_offset

This 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.
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 42c9419a
...@@ -168,7 +168,7 @@ DEFINE_BTRFS_SETGET_BITS(64) ...@@ -168,7 +168,7 @@ DEFINE_BTRFS_SETGET_BITS(64)
void btrfs_node_key(const struct extent_buffer *eb, void btrfs_node_key(const struct extent_buffer *eb,
struct btrfs_disk_key *disk_key, int nr) 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, read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
struct btrfs_key_ptr, key, disk_key); struct btrfs_key_ptr, key, disk_key);
} }
...@@ -392,7 +392,7 @@ static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb, ...@@ -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); 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) + return offsetof(struct btrfs_node, ptrs) +
sizeof(struct btrfs_key_ptr) * nr; sizeof(struct btrfs_key_ptr) * nr;
...@@ -406,7 +406,7 @@ static inline void btrfs_set_node_key(const struct extent_buffer *eb, ...@@ -406,7 +406,7 @@ static inline void btrfs_set_node_key(const struct extent_buffer *eb,
{ {
unsigned long ptr; 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, write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
struct btrfs_key_ptr, key, disk_key); struct btrfs_key_ptr, key, disk_key);
} }
......
...@@ -2612,8 +2612,8 @@ static int push_node_left(struct btrfs_trans_handle *trans, ...@@ -2612,8 +2612,8 @@ static int push_node_left(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
copy_extent_buffer(dst, src, copy_extent_buffer(dst, src,
btrfs_node_key_ptr_offset(dst_nritems), btrfs_node_key_ptr_offset(dst, dst_nritems),
btrfs_node_key_ptr_offset(0), btrfs_node_key_ptr_offset(src, 0),
push_items * sizeof(struct btrfs_key_ptr)); push_items * sizeof(struct btrfs_key_ptr));
if (push_items < src_nritems) { if (push_items < src_nritems) {
...@@ -2621,8 +2621,8 @@ static int push_node_left(struct btrfs_trans_handle *trans, ...@@ -2621,8 +2621,8 @@ static int push_node_left(struct btrfs_trans_handle *trans,
* Don't call btrfs_tree_mod_log_insert_move() here, key removal * Don't call btrfs_tree_mod_log_insert_move() here, key removal
* was already fully logged by btrfs_tree_mod_log_eb_copy() above. * was already fully logged by btrfs_tree_mod_log_eb_copy() above.
*/ */
memmove_extent_buffer(src, btrfs_node_key_ptr_offset(0), memmove_extent_buffer(src, btrfs_node_key_ptr_offset(src, 0),
btrfs_node_key_ptr_offset(push_items), btrfs_node_key_ptr_offset(src, push_items),
(src_nritems - push_items) * (src_nritems - push_items) *
sizeof(struct btrfs_key_ptr)); sizeof(struct btrfs_key_ptr));
} }
...@@ -2682,8 +2682,8 @@ static int balance_node_right(struct btrfs_trans_handle *trans, ...@@ -2682,8 +2682,8 @@ static int balance_node_right(struct btrfs_trans_handle *trans,
} }
ret = btrfs_tree_mod_log_insert_move(dst, push_items, 0, dst_nritems); ret = btrfs_tree_mod_log_insert_move(dst, push_items, 0, dst_nritems);
BUG_ON(ret < 0); BUG_ON(ret < 0);
memmove_extent_buffer(dst, btrfs_node_key_ptr_offset(push_items), memmove_extent_buffer(dst, btrfs_node_key_ptr_offset(dst, push_items),
btrfs_node_key_ptr_offset(0), btrfs_node_key_ptr_offset(dst, 0),
(dst_nritems) * (dst_nritems) *
sizeof(struct btrfs_key_ptr)); sizeof(struct btrfs_key_ptr));
...@@ -2694,8 +2694,8 @@ static int balance_node_right(struct btrfs_trans_handle *trans, ...@@ -2694,8 +2694,8 @@ static int balance_node_right(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
copy_extent_buffer(dst, src, copy_extent_buffer(dst, src,
btrfs_node_key_ptr_offset(0), btrfs_node_key_ptr_offset(dst, 0),
btrfs_node_key_ptr_offset(src_nritems - push_items), btrfs_node_key_ptr_offset(src, src_nritems - push_items),
push_items * sizeof(struct btrfs_key_ptr)); push_items * sizeof(struct btrfs_key_ptr));
btrfs_set_header_nritems(src, src_nritems - push_items); btrfs_set_header_nritems(src, src_nritems - push_items);
...@@ -2798,8 +2798,8 @@ static void insert_ptr(struct btrfs_trans_handle *trans, ...@@ -2798,8 +2798,8 @@ static void insert_ptr(struct btrfs_trans_handle *trans,
BUG_ON(ret < 0); BUG_ON(ret < 0);
} }
memmove_extent_buffer(lower, memmove_extent_buffer(lower,
btrfs_node_key_ptr_offset(slot + 1), btrfs_node_key_ptr_offset(lower, slot + 1),
btrfs_node_key_ptr_offset(slot), btrfs_node_key_ptr_offset(lower, slot),
(nritems - slot) * sizeof(struct btrfs_key_ptr)); (nritems - slot) * sizeof(struct btrfs_key_ptr));
} }
if (level) { if (level) {
...@@ -2881,8 +2881,8 @@ static noinline int split_node(struct btrfs_trans_handle *trans, ...@@ -2881,8 +2881,8 @@ static noinline int split_node(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
copy_extent_buffer(split, c, copy_extent_buffer(split, c,
btrfs_node_key_ptr_offset(0), btrfs_node_key_ptr_offset(split, 0),
btrfs_node_key_ptr_offset(mid), btrfs_node_key_ptr_offset(c, mid),
(c_nritems - mid) * sizeof(struct btrfs_key_ptr)); (c_nritems - mid) * sizeof(struct btrfs_key_ptr));
btrfs_set_header_nritems(split, c_nritems - mid); btrfs_set_header_nritems(split, c_nritems - mid);
btrfs_set_header_nritems(c, mid); btrfs_set_header_nritems(c, mid);
...@@ -4240,8 +4240,8 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path, ...@@ -4240,8 +4240,8 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path,
BUG_ON(ret < 0); BUG_ON(ret < 0);
} }
memmove_extent_buffer(parent, memmove_extent_buffer(parent,
btrfs_node_key_ptr_offset(slot), btrfs_node_key_ptr_offset(parent, slot),
btrfs_node_key_ptr_offset(slot + 1), btrfs_node_key_ptr_offset(parent, slot + 1),
sizeof(struct btrfs_key_ptr) * sizeof(struct btrfs_key_ptr) *
(nritems - slot - 1)); (nritems - slot - 1));
} else if (level) { } else if (level) {
......
...@@ -2529,7 +2529,7 @@ static void prepare_eb_write(struct extent_buffer *eb) ...@@ -2529,7 +2529,7 @@ static void prepare_eb_write(struct extent_buffer *eb)
/* Set btree blocks beyond nritems with 0 to avoid stale content */ /* Set btree blocks beyond nritems with 0 to avoid stale content */
nritems = btrfs_header_nritems(eb); nritems = btrfs_header_nritems(eb);
if (btrfs_header_level(eb) > 0) { 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); memzero_extent_buffer(eb, end, eb->len - end);
} else { } else {
/* /*
......
...@@ -697,8 +697,8 @@ static void tree_mod_log_rewind(struct btrfs_fs_info *fs_info, ...@@ -697,8 +697,8 @@ static void tree_mod_log_rewind(struct btrfs_fs_info *fs_info,
n--; n--;
break; break;
case BTRFS_MOD_LOG_MOVE_KEYS: case BTRFS_MOD_LOG_MOVE_KEYS:
o_dst = btrfs_node_key_ptr_offset(tm->slot); o_dst = btrfs_node_key_ptr_offset(eb, tm->slot);
o_src = btrfs_node_key_ptr_offset(tm->move.dst_slot); o_src = btrfs_node_key_ptr_offset(eb, tm->move.dst_slot);
memmove_extent_buffer(eb, o_dst, o_src, memmove_extent_buffer(eb, o_dst, o_src,
tm->move.nr_items * p_size); tm->move.nr_items * p_size);
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment