1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _BCACHEFS_KEYLIST_H 3 #define _BCACHEFS_KEYLIST_H 4 5 #include "keylist_types.h" 6 7 int bch2_keylist_realloc(struct keylist *, u64 *, size_t, size_t); 8 void bch2_keylist_pop_front(struct keylist *); 9 10 static inline void bch2_keylist_init(struct keylist *l, u64 *inline_keys) 11 { 12 l->top_p = l->keys_p = inline_keys; 13 } 14 15 static inline void bch2_keylist_free(struct keylist *l, u64 *inline_keys) 16 { 17 if (l->keys_p != inline_keys) 18 kfree(l->keys_p); 19 } 20 21 static inline void bch2_keylist_push(struct keylist *l) 22 { 23 l->top = bkey_next(l->top); 24 } 25 26 static inline void bch2_keylist_add(struct keylist *l, const struct bkey_i *k) 27 { 28 bkey_copy(l->top, k); 29 bch2_keylist_push(l); 30 } 31 32 static inline bool bch2_keylist_empty(struct keylist *l) 33 { 34 return l->top == l->keys; 35 } 36 37 static inline size_t bch2_keylist_u64s(struct keylist *l) 38 { 39 return l->top_p - l->keys_p; 40 } 41 42 static inline size_t bch2_keylist_bytes(struct keylist *l) 43 { 44 return bch2_keylist_u64s(l) * sizeof(u64); 45 } 46 47 static inline struct bkey_i *bch2_keylist_front(struct keylist *l) 48 { 49 return l->keys; 50 } 51 52 #define for_each_keylist_key(_keylist, _k) \ 53 for (_k = (_keylist)->keys; \ 54 _k != (_keylist)->top; \ 55 _k = bkey_next(_k)) 56 57 static inline u64 keylist_sectors(struct keylist *keys) 58 { 59 struct bkey_i *k; 60 u64 ret = 0; 61 62 for_each_keylist_key(keys, k) 63 ret += k->k.size; 64 65 return ret; 66 } 67 68 #ifdef CONFIG_BCACHEFS_DEBUG 69 void bch2_verify_keylist_sorted(struct keylist *); 70 #else 71 static inline void bch2_verify_keylist_sorted(struct keylist *l) {} 72 #endif 73 74 #endif /* _BCACHEFS_KEYLIST_H */ 75