1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_BKEY_ON_STACK_H
3 #define _BCACHEFS_BKEY_ON_STACK_H
12 static inline void bkey_on_stack_realloc(struct bkey_on_stack *s,
13 struct bch_fs *c, unsigned u64s)
15 if (s->k == (void *) s->onstack &&
16 u64s > ARRAY_SIZE(s->onstack)) {
17 s->k = mempool_alloc(&c->large_bkey_pool, GFP_NOFS);
18 memcpy(s->k, s->onstack, sizeof(s->onstack));
22 static inline void bkey_on_stack_reassemble(struct bkey_on_stack *s,
26 bkey_on_stack_realloc(s, c, k.k->u64s);
27 bkey_reassemble(s->k, k);
30 static inline void bkey_on_stack_init(struct bkey_on_stack *s)
32 s->k = (void *) s->onstack;
35 static inline void bkey_on_stack_exit(struct bkey_on_stack *s,
38 if (s->k != (void *) s->onstack)
39 mempool_free(s->k, &c->large_bkey_pool);
43 #endif /* _BCACHEFS_BKEY_ON_STACK_H */