1 #ifndef _BCACHE_ALLOC_H
2 #define _BCACHE_ALLOC_H
4 #include "alloc_types.h"
12 static inline size_t prios_per_bucket(const struct cache *ca)
14 return (bucket_bytes(ca) - sizeof(struct prio_set)) /
15 sizeof(struct bucket_disk);
18 static inline size_t prio_buckets(const struct cache *ca)
20 return DIV_ROUND_UP((size_t) (ca)->mi.nbuckets, prios_per_bucket(ca));
23 void bch_dev_group_remove(struct cache_group *, struct cache *);
24 void bch_dev_group_add(struct cache_group *, struct cache *);
26 int bch_prio_read(struct cache *);
28 void bch_recalc_min_prio(struct cache *, int);
30 void bch_open_bucket_put(struct cache_set *, struct open_bucket *);
32 struct open_bucket *bch_alloc_sectors_start(struct cache_set *,
34 unsigned, enum alloc_reserve,
37 void bch_alloc_sectors_append_ptrs(struct cache_set *, struct bkey_i_extent *,
38 unsigned, struct open_bucket *, unsigned);
39 void bch_alloc_sectors_done(struct cache_set *, struct write_point *,
40 struct open_bucket *);
42 struct open_bucket *bch_alloc_sectors(struct cache_set *, struct write_point *,
43 struct bkey_i_extent *, unsigned,
44 enum alloc_reserve, struct closure *);
46 static inline void bch_wake_allocator(struct cache *ca)
48 struct task_struct *p;
51 if ((p = ACCESS_ONCE(ca->alloc_thread)))
56 static inline struct cache *cache_group_next_rcu(struct cache_group *devs,
59 struct cache *ret = NULL;
61 while (*iter < devs->nr_devices &&
62 !(ret = rcu_dereference(devs->d[*iter].dev)))
68 #define group_for_each_cache_rcu(ca, devs, iter) \
70 ((ca) = cache_group_next_rcu((devs), &(iter))); \
73 static inline struct cache *cache_group_next(struct cache_group *devs,
79 if ((ret = cache_group_next_rcu(devs, iter)))
80 percpu_ref_get(&ret->ref);
86 #define group_for_each_cache(ca, devs, iter) \
88 (ca = cache_group_next(devs, &(iter))); \
89 percpu_ref_put(&ca->ref), (iter)++)
91 #define __open_bucket_next_online_device(_c, _ob, _ptr, _ca) \
95 while ((_ptr) < (_ob)->ptrs + (_ob)->nr_ptrs && \
96 !((_ca) = PTR_CACHE(_c, _ptr))) \
101 #define open_bucket_for_each_online_device(_c, _ob, _ptr, _ca) \
102 for ((_ptr) = (_ob)->ptrs; \
103 ((_ca) = __open_bucket_next_online_device(_c, _ob, _ptr, _ca));\
106 void bch_dev_allocator_stop(struct cache *);
107 int bch_dev_allocator_start(struct cache *);
108 void bch_open_buckets_init(struct cache_set *);
110 #endif /* _BCACHE_ALLOC_H */