]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcache/alloc.h
update bcache sources
[bcachefs-tools-debian] / libbcache / alloc.h
1 #ifndef _BCACHE_ALLOC_H
2 #define _BCACHE_ALLOC_H
3
4 #include "alloc_types.h"
5
6 struct bkey;
7 struct bucket;
8 struct bch_dev;
9 struct bch_fs;
10 struct dev_group;
11
12 static inline size_t prios_per_bucket(const struct bch_dev *ca)
13 {
14         return (bucket_bytes(ca) - sizeof(struct prio_set)) /
15                 sizeof(struct bucket_disk);
16 }
17
18 static inline size_t prio_buckets(const struct bch_dev *ca)
19 {
20         return DIV_ROUND_UP((size_t) (ca)->mi.nbuckets, prios_per_bucket(ca));
21 }
22
23 void bch_dev_group_remove(struct dev_group *, struct bch_dev *);
24 void bch_dev_group_add(struct dev_group *, struct bch_dev *);
25
26 int bch_prio_read(struct bch_dev *);
27
28 size_t bch_bucket_alloc(struct bch_dev *, enum alloc_reserve);
29
30 void bch_open_bucket_put(struct bch_fs *, struct open_bucket *);
31
32 struct open_bucket *bch_alloc_sectors_start(struct bch_fs *,
33                                             struct write_point *,
34                                             unsigned, unsigned,
35                                             enum alloc_reserve,
36                                             struct closure *);
37
38 void bch_alloc_sectors_append_ptrs(struct bch_fs *, struct bkey_i_extent *,
39                                    unsigned, struct open_bucket *, unsigned);
40 void bch_alloc_sectors_done(struct bch_fs *, struct write_point *,
41                             struct open_bucket *);
42
43 struct open_bucket *bch_alloc_sectors(struct bch_fs *, struct write_point *,
44                                       struct bkey_i_extent *, unsigned, unsigned,
45                                       enum alloc_reserve, struct closure *);
46
47 static inline void bch_wake_allocator(struct bch_dev *ca)
48 {
49         struct task_struct *p;
50
51         rcu_read_lock();
52         if ((p = ACCESS_ONCE(ca->alloc_thread)))
53                 wake_up_process(p);
54         rcu_read_unlock();
55 }
56
57 static inline struct bch_dev *dev_group_next(struct dev_group *devs,
58                                              unsigned *iter)
59 {
60         struct bch_dev *ret = NULL;
61
62         while (*iter < devs->nr &&
63                !(ret = rcu_dereference_check(devs->d[*iter].dev,
64                                              lockdep_is_held(&devs->lock))))
65                 (*iter)++;
66
67         return ret;
68 }
69
70 #define group_for_each_dev(ca, devs, iter)                              \
71         for ((iter) = 0;                                                \
72              ((ca) = dev_group_next((devs), &(iter)));                  \
73              (iter)++)
74
75 #define open_bucket_for_each_ptr(_ob, _ptr)                             \
76         for ((_ptr) = (_ob)->ptrs;                                      \
77              (_ptr) < (_ob)->ptrs + (_ob)->nr_ptrs;                     \
78              (_ptr)++)
79
80 void bch_recalc_capacity(struct bch_fs *);
81 void bch_dev_allocator_stop(struct bch_dev *);
82 int bch_dev_allocator_start(struct bch_dev *);
83 void bch_fs_allocator_init(struct bch_fs *);
84
85 #endif /* _BCACHE_ALLOC_H */