Skip to content

Commit cc4c13d

Browse files
committed
btrfs: drop eb parameter from set/get token helpers
Now that all set/get helpers use the eb from the token, we don't need to pass it to many btrfs_token_*/btrfs_set_token_* helpers, saving some stack space. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 4dae666 commit cc4c13d

File tree

5 files changed

+130
-158
lines changed

5 files changed

+130
-158
lines changed

fs/btrfs/ctree.c

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3517,9 +3517,9 @@ static int leaf_space_used(struct extent_buffer *l, int start, int nr)
35173517
btrfs_init_map_token(&token, l);
35183518
start_item = btrfs_item_nr(start);
35193519
end_item = btrfs_item_nr(end);
3520-
data_len = btrfs_token_item_offset(l, start_item, &token) +
3521-
btrfs_token_item_size(l, start_item, &token);
3522-
data_len = data_len - btrfs_token_item_offset(l, end_item, &token);
3520+
data_len = btrfs_token_item_offset(&token, start_item) +
3521+
btrfs_token_item_size(&token, start_item);
3522+
data_len = data_len - btrfs_token_item_offset(&token, end_item);
35233523
data_len += sizeof(struct btrfs_item) * nr;
35243524
WARN_ON(data_len < 0);
35253525
return data_len;
@@ -3650,8 +3650,8 @@ static noinline int __push_leaf_right(struct btrfs_path *path,
36503650
push_space = BTRFS_LEAF_DATA_SIZE(fs_info);
36513651
for (i = 0; i < right_nritems; i++) {
36523652
item = btrfs_item_nr(i);
3653-
push_space -= btrfs_token_item_size(right, item, &token);
3654-
btrfs_set_token_item_offset(right, item, push_space, &token);
3653+
push_space -= btrfs_token_item_size(&token, item);
3654+
btrfs_set_token_item_offset(&token, item, push_space);
36553655
}
36563656

36573657
left_nritems -= push_items;
@@ -3859,10 +3859,9 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size,
38593859

38603860
item = btrfs_item_nr(i);
38613861

3862-
ioff = btrfs_token_item_offset(left, item, &token);
3863-
btrfs_set_token_item_offset(left, item,
3864-
ioff - (BTRFS_LEAF_DATA_SIZE(fs_info) - old_left_item_size),
3865-
&token);
3862+
ioff = btrfs_token_item_offset(&token, item);
3863+
btrfs_set_token_item_offset(&token, item,
3864+
ioff - (BTRFS_LEAF_DATA_SIZE(fs_info) - old_left_item_size));
38663865
}
38673866
btrfs_set_header_nritems(left, old_left_nritems + push_items);
38683867

@@ -3892,9 +3891,8 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size,
38923891
for (i = 0; i < right_nritems; i++) {
38933892
item = btrfs_item_nr(i);
38943893

3895-
push_space = push_space - btrfs_token_item_size(right,
3896-
item, &token);
3897-
btrfs_set_token_item_offset(right, item, push_space, &token);
3894+
push_space = push_space - btrfs_token_item_size(&token, item);
3895+
btrfs_set_token_item_offset(&token, item, push_space);
38983896
}
38993897

39003898
btrfs_mark_buffer_dirty(left);
@@ -4036,9 +4034,8 @@ static noinline void copy_for_split(struct btrfs_trans_handle *trans,
40364034
struct btrfs_item *item = btrfs_item_nr(i);
40374035
u32 ioff;
40384036

4039-
ioff = btrfs_token_item_offset(right, item, &token);
4040-
btrfs_set_token_item_offset(right, item,
4041-
ioff + rt_data_off, &token);
4037+
ioff = btrfs_token_item_offset(&token, item);
4038+
btrfs_set_token_item_offset(&token, item, ioff + rt_data_off);
40424039
}
40434040

40444041
btrfs_set_header_nritems(l, mid);
@@ -4541,9 +4538,8 @@ void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end)
45414538
u32 ioff;
45424539
item = btrfs_item_nr(i);
45434540

4544-
ioff = btrfs_token_item_offset(leaf, item, &token);
4545-
btrfs_set_token_item_offset(leaf, item,
4546-
ioff + size_diff, &token);
4541+
ioff = btrfs_token_item_offset(&token, item);
4542+
btrfs_set_token_item_offset(&token, item, ioff + size_diff);
45474543
}
45484544

45494545
/* shift the data */
@@ -4640,9 +4636,8 @@ void btrfs_extend_item(struct btrfs_path *path, u32 data_size)
46404636
u32 ioff;
46414637
item = btrfs_item_nr(i);
46424638

4643-
ioff = btrfs_token_item_offset(leaf, item, &token);
4644-
btrfs_set_token_item_offset(leaf, item,
4645-
ioff - data_size, &token);
4639+
ioff = btrfs_token_item_offset(&token, item);
4640+
btrfs_set_token_item_offset(&token, item, ioff - data_size);
46464641
}
46474642

46484643
/* shift the data */
@@ -4718,9 +4713,9 @@ void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path,
47184713
u32 ioff;
47194714

47204715
item = btrfs_item_nr(i);
4721-
ioff = btrfs_token_item_offset(leaf, item, &token);
4722-
btrfs_set_token_item_offset(leaf, item,
4723-
ioff - total_data, &token);
4716+
ioff = btrfs_token_item_offset(&token, item);
4717+
btrfs_set_token_item_offset(&token, item,
4718+
ioff - total_data);
47244719
}
47254720
/* shift the items */
47264721
memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot + nr),
@@ -4739,10 +4734,9 @@ void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path,
47394734
btrfs_cpu_key_to_disk(&disk_key, cpu_key + i);
47404735
btrfs_set_item_key(leaf, &disk_key, slot + i);
47414736
item = btrfs_item_nr(slot + i);
4742-
btrfs_set_token_item_offset(leaf, item,
4743-
data_end - data_size[i], &token);
4737+
btrfs_set_token_item_offset(&token, item, data_end - data_size[i]);
47444738
data_end -= data_size[i];
4745-
btrfs_set_token_item_size(leaf, item, data_size[i], &token);
4739+
btrfs_set_token_item_size(&token, item, data_size[i]);
47464740
}
47474741

47484742
btrfs_set_header_nritems(leaf, nritems + nr);
@@ -4930,9 +4924,8 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
49304924
u32 ioff;
49314925

49324926
item = btrfs_item_nr(i);
4933-
ioff = btrfs_token_item_offset(leaf, item, &token);
4934-
btrfs_set_token_item_offset(leaf, item,
4935-
ioff + dsize, &token);
4927+
ioff = btrfs_token_item_offset(&token, item);
4928+
btrfs_set_token_item_offset(&token, item, ioff + dsize);
49364929
}
49374930

49384931
memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot),

fs/btrfs/ctree.h

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ do { \
13401340
BTRFS_INODE_ROOT_ITEM_INIT)
13411341

13421342
struct btrfs_map_token {
1343-
const struct extent_buffer *eb;
1343+
struct extent_buffer *eb;
13441344
char *kaddr;
13451345
unsigned long offset;
13461346
};
@@ -1376,12 +1376,11 @@ static inline void btrfs_init_map_token(struct btrfs_map_token *token,
13761376
sizeof(((type *)0)->member)))
13771377

13781378
#define DECLARE_BTRFS_SETGET_BITS(bits) \
1379-
u##bits btrfs_get_token_##bits(const struct extent_buffer *eb, \
1380-
const void *ptr, unsigned long off, \
1381-
struct btrfs_map_token *token); \
1382-
void btrfs_set_token_##bits(struct extent_buffer *eb, const void *ptr, \
1383-
unsigned long off, u##bits val, \
1384-
struct btrfs_map_token *token); \
1379+
u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
1380+
const void *ptr, unsigned long off); \
1381+
void btrfs_set_token_##bits(struct btrfs_map_token *token, \
1382+
const void *ptr, unsigned long off, \
1383+
u##bits val); \
13851384
u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
13861385
const void *ptr, unsigned long off); \
13871386
void btrfs_set_##bits(struct extent_buffer *eb, void *ptr, \
@@ -1405,19 +1404,17 @@ static inline void btrfs_set_##name(struct extent_buffer *eb, type *s, \
14051404
BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
14061405
btrfs_set_##bits(eb, s, offsetof(type, member), val); \
14071406
} \
1408-
static inline u##bits btrfs_token_##name(const struct extent_buffer *eb,\
1409-
const type *s, \
1410-
struct btrfs_map_token *token) \
1407+
static inline u##bits btrfs_token_##name(struct btrfs_map_token *token, \
1408+
const type *s) \
14111409
{ \
14121410
BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
1413-
return btrfs_get_token_##bits(eb, s, offsetof(type, member), token); \
1411+
return btrfs_get_token_##bits(token, s, offsetof(type, member));\
14141412
} \
1415-
static inline void btrfs_set_token_##name(struct extent_buffer *eb, \
1416-
type *s, u##bits val, \
1417-
struct btrfs_map_token *token) \
1413+
static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\
1414+
type *s, u##bits val) \
14181415
{ \
14191416
BUILD_BUG_ON(sizeof(u##bits) != sizeof(((type *)0))->member); \
1420-
btrfs_set_token_##bits(eb, s, offsetof(type, member), val, token); \
1417+
btrfs_set_token_##bits(token, s, offsetof(type, member), val); \
14211418
}
14221419

14231420
#define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \

fs/btrfs/inode.c

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,43 +3352,40 @@ static void fill_inode_item(struct btrfs_trans_handle *trans,
33523352

33533353
btrfs_init_map_token(&token, leaf);
33543354

3355-
btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
3356-
btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
3357-
btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
3358-
&token);
3359-
btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
3360-
btrfs_set_token_inode_nlink(leaf, item, inode->i_nlink, &token);
3361-
3362-
btrfs_set_token_timespec_sec(leaf, &item->atime,
3363-
inode->i_atime.tv_sec, &token);
3364-
btrfs_set_token_timespec_nsec(leaf, &item->atime,
3365-
inode->i_atime.tv_nsec, &token);
3366-
3367-
btrfs_set_token_timespec_sec(leaf, &item->mtime,
3368-
inode->i_mtime.tv_sec, &token);
3369-
btrfs_set_token_timespec_nsec(leaf, &item->mtime,
3370-
inode->i_mtime.tv_nsec, &token);
3371-
3372-
btrfs_set_token_timespec_sec(leaf, &item->ctime,
3373-
inode->i_ctime.tv_sec, &token);
3374-
btrfs_set_token_timespec_nsec(leaf, &item->ctime,
3375-
inode->i_ctime.tv_nsec, &token);
3376-
3377-
btrfs_set_token_timespec_sec(leaf, &item->otime,
3378-
BTRFS_I(inode)->i_otime.tv_sec, &token);
3379-
btrfs_set_token_timespec_nsec(leaf, &item->otime,
3380-
BTRFS_I(inode)->i_otime.tv_nsec, &token);
3381-
3382-
btrfs_set_token_inode_nbytes(leaf, item, inode_get_bytes(inode),
3383-
&token);
3384-
btrfs_set_token_inode_generation(leaf, item, BTRFS_I(inode)->generation,
3385-
&token);
3386-
btrfs_set_token_inode_sequence(leaf, item, inode_peek_iversion(inode),
3387-
&token);
3388-
btrfs_set_token_inode_transid(leaf, item, trans->transid, &token);
3389-
btrfs_set_token_inode_rdev(leaf, item, inode->i_rdev, &token);
3390-
btrfs_set_token_inode_flags(leaf, item, BTRFS_I(inode)->flags, &token);
3391-
btrfs_set_token_inode_block_group(leaf, item, 0, &token);
3355+
btrfs_set_token_inode_uid(&token, item, i_uid_read(inode));
3356+
btrfs_set_token_inode_gid(&token, item, i_gid_read(inode));
3357+
btrfs_set_token_inode_size(&token, item, BTRFS_I(inode)->disk_i_size);
3358+
btrfs_set_token_inode_mode(&token, item, inode->i_mode);
3359+
btrfs_set_token_inode_nlink(&token, item, inode->i_nlink);
3360+
3361+
btrfs_set_token_timespec_sec(&token, &item->atime,
3362+
inode->i_atime.tv_sec);
3363+
btrfs_set_token_timespec_nsec(&token, &item->atime,
3364+
inode->i_atime.tv_nsec);
3365+
3366+
btrfs_set_token_timespec_sec(&token, &item->mtime,
3367+
inode->i_mtime.tv_sec);
3368+
btrfs_set_token_timespec_nsec(&token, &item->mtime,
3369+
inode->i_mtime.tv_nsec);
3370+
3371+
btrfs_set_token_timespec_sec(&token, &item->ctime,
3372+
inode->i_ctime.tv_sec);
3373+
btrfs_set_token_timespec_nsec(&token, &item->ctime,
3374+
inode->i_ctime.tv_nsec);
3375+
3376+
btrfs_set_token_timespec_sec(&token, &item->otime,
3377+
BTRFS_I(inode)->i_otime.tv_sec);
3378+
btrfs_set_token_timespec_nsec(&token, &item->otime,
3379+
BTRFS_I(inode)->i_otime.tv_nsec);
3380+
3381+
btrfs_set_token_inode_nbytes(&token, item, inode_get_bytes(inode));
3382+
btrfs_set_token_inode_generation(&token, item,
3383+
BTRFS_I(inode)->generation);
3384+
btrfs_set_token_inode_sequence(&token, item, inode_peek_iversion(inode));
3385+
btrfs_set_token_inode_transid(&token, item, trans->transid);
3386+
btrfs_set_token_inode_rdev(&token, item, inode->i_rdev);
3387+
btrfs_set_token_inode_flags(&token, item, BTRFS_I(inode)->flags);
3388+
btrfs_set_token_inode_block_group(&token, item, 0);
33923389
}
33933390

33943391
/*

fs/btrfs/struct-funcs.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ static inline void put_unaligned_le8(u8 val, void *p)
3838
*/
3939

4040
#define DEFINE_BTRFS_SETGET_BITS(bits) \
41-
u##bits btrfs_get_token_##bits(const struct extent_buffer *eb, \
42-
const void *ptr, unsigned long off, \
43-
struct btrfs_map_token *token) \
41+
u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
42+
const void *ptr, unsigned long off) \
4443
{ \
4544
unsigned long part_offset = (unsigned long)ptr; \
4645
unsigned long offset = part_offset + off; \
@@ -53,7 +52,6 @@ u##bits btrfs_get_token_##bits(const struct extent_buffer *eb, \
5352
u##bits res; \
5453
\
5554
ASSERT(token); \
56-
ASSERT(token->eb == eb); \
5755
\
5856
if (token->kaddr && token->offset <= offset && \
5957
(token->offset + PAGE_SIZE >= offset + size)) { \
@@ -101,10 +99,9 @@ u##bits btrfs_get_##bits(const struct extent_buffer *eb, \
10199
res = get_unaligned_le##bits(p + off); \
102100
return res; \
103101
} \
104-
void btrfs_set_token_##bits(struct extent_buffer *eb, \
102+
void btrfs_set_token_##bits(struct btrfs_map_token *token, \
105103
const void *ptr, unsigned long off, \
106-
u##bits val, \
107-
struct btrfs_map_token *token) \
104+
u##bits val) \
108105
{ \
109106
unsigned long part_offset = (unsigned long)ptr; \
110107
unsigned long offset = part_offset + off; \
@@ -116,7 +113,6 @@ void btrfs_set_token_##bits(struct extent_buffer *eb, \
116113
int size = sizeof(u##bits); \
117114
\
118115
ASSERT(token); \
119-
ASSERT(token->eb == eb); \
120116
\
121117
if (token->kaddr && token->offset <= offset && \
122118
(token->offset + PAGE_SIZE >= offset + size)) { \

0 commit comments

Comments
 (0)