1 // SPDX-License-Identifier: GPL-2.0
7 int bch2_keylist_realloc(struct keylist
*l
, u64
*inline_u64s
,
8 size_t nr_inline_u64s
, size_t new_u64s
)
10 size_t oldsize
= bch2_keylist_u64s(l
);
11 size_t newsize
= oldsize
+ new_u64s
;
12 u64
*old_buf
= l
->keys_p
== inline_u64s
? NULL
: l
->keys_p
;
15 newsize
= roundup_pow_of_two(newsize
);
17 if (newsize
<= nr_inline_u64s
||
18 (old_buf
&& roundup_pow_of_two(oldsize
) == newsize
))
21 new_keys
= krealloc(old_buf
, sizeof(u64
) * newsize
, GFP_NOFS
);
26 memcpy_u64s(new_keys
, inline_u64s
, oldsize
);
29 l
->top_p
= new_keys
+ oldsize
;
34 void bch2_keylist_pop_front(struct keylist
*l
)
36 l
->top_p
-= bch2_keylist_front(l
)->k
.u64s
;
38 memmove_u64s_down(l
->keys
,
40 bch2_keylist_u64s(l
));
43 #ifdef CONFIG_BCACHEFS_DEBUG
44 void bch2_verify_keylist_sorted(struct keylist
*l
)
46 for_each_keylist_key(l
, k
)
47 BUG_ON(bkey_next(k
) != l
->top
&&
48 bpos_ge(k
->k
.p
, bkey_next(k
)->k
.p
));