1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_BKEY_BUF_H
3 #define _BCACHEFS_BKEY_BUF_H
13 static inline void bch2_bkey_buf_realloc(struct bkey_buf
*s
,
14 struct bch_fs
*c
, unsigned u64s
)
16 if (s
->k
== (void *) s
->onstack
&&
17 u64s
> ARRAY_SIZE(s
->onstack
)) {
18 s
->k
= mempool_alloc(&c
->large_bkey_pool
, GFP_NOFS
);
19 memcpy(s
->k
, s
->onstack
, sizeof(s
->onstack
));
23 static inline void bch2_bkey_buf_reassemble(struct bkey_buf
*s
,
27 bch2_bkey_buf_realloc(s
, c
, k
.k
->u64s
);
28 bkey_reassemble(s
->k
, k
);
31 static inline void bch2_bkey_buf_copy(struct bkey_buf
*s
,
35 bch2_bkey_buf_realloc(s
, c
, src
->k
.u64s
);
39 static inline void bch2_bkey_buf_unpack(struct bkey_buf
*s
,
42 struct bkey_packed
*src
)
44 bch2_bkey_buf_realloc(s
, c
, BKEY_U64s
+
45 bkeyp_val_u64s(&b
->format
, src
));
46 bch2_bkey_unpack(b
, s
->k
, src
);
49 static inline void bch2_bkey_buf_init(struct bkey_buf
*s
)
51 s
->k
= (void *) s
->onstack
;
54 static inline void bch2_bkey_buf_exit(struct bkey_buf
*s
, struct bch_fs
*c
)
56 if (s
->k
!= (void *) s
->onstack
)
57 mempool_free(s
->k
, &c
->large_bkey_pool
);
61 #endif /* _BCACHEFS_BKEY_BUF_H */