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