btrfs: tie extent buffer and it's token together
Further simplifaction of the get/set helpers is possible when the token
is uniquely tied to an extent buffer. A condition and an assignment can
be avoided.
The initializations are moved closer to the first use when the extent
buffer is valid. There's one exception in __push_leaf_left where the
token is reused.
Signed-off-by: David Sterba <dsterba@suse.com>
diff --git a/fs/btrfs/struct-funcs.c b/fs/btrfs/struct-funcs.c
index 3a29b91..73f7987 100644
--- a/fs/btrfs/struct-funcs.c
+++ b/fs/btrfs/struct-funcs.c
@@ -53,9 +53,9 @@ u##bits btrfs_get_token_##bits(const struct extent_buffer *eb, \
u##bits res; \
\
ASSERT(token); \
+ ASSERT(token->eb == eb); \
\
if (token->kaddr && token->offset <= offset && \
- token->eb == eb && \
(token->offset + PAGE_SIZE >= offset + size)) { \
kaddr = token->kaddr; \
p = kaddr + part_offset - token->offset; \
@@ -74,7 +74,6 @@ u##bits btrfs_get_token_##bits(const struct extent_buffer *eb, \
res = get_unaligned_le##bits(p + off); \
token->kaddr = kaddr; \
token->offset = map_start; \
- token->eb = eb; \
return res; \
} \
u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
@@ -117,9 +116,9 @@ void btrfs_set_token_##bits(struct extent_buffer *eb, \
int size = sizeof(u##bits); \
\
ASSERT(token); \
+ ASSERT(token->eb == eb); \
\
if (token->kaddr && token->offset <= offset && \
- token->eb == eb && \
(token->offset + PAGE_SIZE >= offset + size)) { \
kaddr = token->kaddr; \
p = kaddr + part_offset - token->offset; \
@@ -139,7 +138,6 @@ void btrfs_set_token_##bits(struct extent_buffer *eb, \
put_unaligned_le##bits(val, p + off); \
token->kaddr = kaddr; \
token->offset = map_start; \
- token->eb = eb; \
} \
void btrfs_set_##bits(struct extent_buffer *eb, void *ptr, \
unsigned long off, u##bits val) \