1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_KEYLIST_H
3 #define _BCACHEFS_KEYLIST_H
5 #include "keylist_types.h"
7 int bch2_keylist_realloc(struct keylist
*, u64
*, size_t, size_t);
8 void bch2_keylist_pop_front(struct keylist
*);
10 static inline void bch2_keylist_init(struct keylist
*l
, u64
*inline_keys
)
12 l
->top_p
= l
->keys_p
= inline_keys
;
15 static inline void bch2_keylist_free(struct keylist
*l
, u64
*inline_keys
)
17 if (l
->keys_p
!= inline_keys
)
21 static inline void bch2_keylist_push(struct keylist
*l
)
23 l
->top
= bkey_next(l
->top
);
26 static inline void bch2_keylist_add(struct keylist
*l
, const struct bkey_i
*k
)
32 static inline bool bch2_keylist_empty(struct keylist
*l
)
34 return l
->top
== l
->keys
;
37 static inline size_t bch2_keylist_u64s(struct keylist
*l
)
39 return l
->top_p
- l
->keys_p
;
42 static inline size_t bch2_keylist_bytes(struct keylist
*l
)
44 return bch2_keylist_u64s(l
) * sizeof(u64
);
47 static inline struct bkey_i
*bch2_keylist_front(struct keylist
*l
)
52 #define for_each_keylist_key(_keylist, _k) \
53 for (struct bkey_i *_k = (_keylist)->keys; \
54 _k != (_keylist)->top; \
57 static inline u64
keylist_sectors(struct keylist
*keys
)
61 for_each_keylist_key(keys
, k
)
66 #ifdef CONFIG_BCACHEFS_DEBUG
67 void bch2_verify_keylist_sorted(struct keylist
*);
69 static inline void bch2_verify_keylist_sorted(struct keylist
*l
) {}
72 #endif /* _BCACHEFS_KEYLIST_H */