]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/alloc_background.h
Update bcachefs sources to 62de7539dc bcachefs: Make bkey types globally unique
[bcachefs-tools-debian] / libbcachefs / alloc_background.h
1 #ifndef _BCACHEFS_ALLOC_BACKGROUND_H
2 #define _BCACHEFS_ALLOC_BACKGROUND_H
3
4 #include "bcachefs.h"
5 #include "alloc_types.h"
6 #include "debug.h"
7
8 #define ALLOC_SCAN_BATCH(ca)            max_t(size_t, 1, (ca)->mi.nbuckets >> 9)
9
10 const char *bch2_alloc_invalid(const struct bch_fs *, struct bkey_s_c);
11 void bch2_alloc_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
12
13 #define bch2_bkey_ops_alloc (struct bkey_ops) {         \
14         .key_invalid    = bch2_alloc_invalid,           \
15         .val_to_text    = bch2_alloc_to_text,           \
16 }
17
18 int bch2_alloc_read(struct bch_fs *, struct list_head *);
19 int bch2_alloc_replay_key(struct bch_fs *, struct bkey_i *);
20
21 static inline void bch2_wake_allocator(struct bch_dev *ca)
22 {
23         struct task_struct *p;
24
25         rcu_read_lock();
26         p = rcu_dereference(ca->alloc_thread);
27         if (p)
28                 wake_up_process(p);
29         rcu_read_unlock();
30 }
31
32 static inline void verify_not_on_freelist(struct bch_fs *c, struct bch_dev *ca,
33                                           size_t bucket)
34 {
35         if (expensive_debug_checks(c) &&
36             test_bit(BCH_FS_ALLOCATOR_STARTED, &c->flags)) {
37                 size_t iter;
38                 long i;
39                 unsigned j;
40
41                 for (j = 0; j < RESERVE_NR; j++)
42                         fifo_for_each_entry(i, &ca->free[j], iter)
43                                 BUG_ON(i == bucket);
44                 fifo_for_each_entry(i, &ca->free_inc, iter)
45                         BUG_ON(i == bucket);
46         }
47 }
48
49 void bch2_recalc_capacity(struct bch_fs *);
50
51 void bch2_dev_allocator_remove(struct bch_fs *, struct bch_dev *);
52 void bch2_dev_allocator_add(struct bch_fs *, struct bch_dev *);
53
54 void bch2_dev_allocator_stop(struct bch_dev *);
55 int bch2_dev_allocator_start(struct bch_dev *);
56
57 int bch2_alloc_write(struct bch_fs *);
58 int bch2_fs_allocator_start(struct bch_fs *);
59 void bch2_fs_allocator_background_init(struct bch_fs *);
60
61 #endif /* _BCACHEFS_ALLOC_BACKGROUND_H */