Linux 6.13-rc4
[linux.git] / fs / bcachefs / keylist.h
blobe687e0e9aede1cb2f7bb7252d16d58ec2774ebd1
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)
18 kfree(l->keys_p);
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)
28 bkey_copy(l->top, k);
29 bch2_keylist_push(l);
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)
49 return l->keys;
52 #define for_each_keylist_key(_keylist, _k) \
53 for (struct bkey_i *_k = (_keylist)->keys; \
54 _k != (_keylist)->top; \
55 _k = bkey_next(_k))
57 static inline u64 keylist_sectors(struct keylist *keys)
59 u64 ret = 0;
61 for_each_keylist_key(keys, k)
62 ret += k->k.size;
63 return ret;
66 #ifdef CONFIG_BCACHEFS_DEBUG
67 void bch2_verify_keylist_sorted(struct keylist *);
68 #else
69 static inline void bch2_verify_keylist_sorted(struct keylist *l) {}
70 #endif
72 #endif /* _BCACHEFS_KEYLIST_H */