2019-07-10 23:12:15 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2017-10-06 01:41:44 +03:00
|
|
|
#ifndef _BCACHEFS_KEYLIST_H
|
|
|
|
#define _BCACHEFS_KEYLIST_H
|
2017-01-08 12:13:18 +03:00
|
|
|
|
|
|
|
#include "keylist_types.h"
|
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
int bch2_keylist_realloc(struct keylist *, u64 *, size_t, size_t);
|
|
|
|
void bch2_keylist_pop_front(struct keylist *);
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2017-12-14 00:01:18 +03:00
|
|
|
static inline void bch2_keylist_init(struct keylist *l, u64 *inline_keys)
|
2017-01-08 12:13:18 +03:00
|
|
|
{
|
|
|
|
l->top_p = l->keys_p = inline_keys;
|
|
|
|
}
|
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
static inline void bch2_keylist_free(struct keylist *l, u64 *inline_keys)
|
2017-01-08 12:13:18 +03:00
|
|
|
{
|
|
|
|
if (l->keys_p != inline_keys)
|
|
|
|
kfree(l->keys_p);
|
|
|
|
}
|
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
static inline void bch2_keylist_push(struct keylist *l)
|
2017-01-08 12:13:18 +03:00
|
|
|
{
|
|
|
|
l->top = bkey_next(l->top);
|
|
|
|
}
|
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
static inline void bch2_keylist_add(struct keylist *l, const struct bkey_i *k)
|
2017-01-08 12:13:18 +03:00
|
|
|
{
|
|
|
|
bkey_copy(l->top, k);
|
2017-03-20 02:56:34 +03:00
|
|
|
bch2_keylist_push(l);
|
2017-01-08 12:13:18 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
static inline bool bch2_keylist_empty(struct keylist *l)
|
2017-01-08 12:13:18 +03:00
|
|
|
{
|
|
|
|
return l->top == l->keys;
|
|
|
|
}
|
|
|
|
|
2020-06-03 23:21:35 +03:00
|
|
|
static inline size_t bch2_keylist_u64s(struct keylist *l)
|
2017-01-08 12:13:18 +03:00
|
|
|
{
|
|
|
|
return l->top_p - l->keys_p;
|
|
|
|
}
|
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
static inline size_t bch2_keylist_bytes(struct keylist *l)
|
2017-01-08 12:13:18 +03:00
|
|
|
{
|
2020-06-03 23:21:35 +03:00
|
|
|
return bch2_keylist_u64s(l) * sizeof(u64);
|
2017-01-08 12:13:18 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
static inline struct bkey_i *bch2_keylist_front(struct keylist *l)
|
2017-01-08 12:13:18 +03:00
|
|
|
{
|
|
|
|
return l->keys;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define for_each_keylist_key(_keylist, _k) \
|
2023-12-23 05:21:14 +03:00
|
|
|
for (struct bkey_i *_k = (_keylist)->keys; \
|
2017-01-08 12:13:18 +03:00
|
|
|
_k != (_keylist)->top; \
|
|
|
|
_k = bkey_next(_k))
|
|
|
|
|
2018-02-16 23:36:33 +03:00
|
|
|
static inline u64 keylist_sectors(struct keylist *keys)
|
|
|
|
{
|
|
|
|
u64 ret = 0;
|
|
|
|
|
|
|
|
for_each_keylist_key(keys, k)
|
|
|
|
ret += k->k.size;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-06-14 04:06:05 +03:00
|
|
|
#ifdef CONFIG_BCACHEFS_DEBUG
|
|
|
|
void bch2_verify_keylist_sorted(struct keylist *);
|
|
|
|
#else
|
|
|
|
static inline void bch2_verify_keylist_sorted(struct keylist *l) {}
|
|
|
|
#endif
|
|
|
|
|
2017-10-06 01:41:44 +03:00
|
|
|
#endif /* _BCACHEFS_KEYLIST_H */
|