]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/replicas.h
Update bcachefs sources to ef60854e99 bcachefs: More allocator startup improvements
[bcachefs-tools-debian] / libbcachefs / replicas.h
1 #ifndef _BCACHEFS_REPLICAS_H
2 #define _BCACHEFS_REPLICAS_H
3
4 #include "eytzinger.h"
5 #include "replicas_types.h"
6
7 int bch2_replicas_entry_idx(struct bch_fs *,
8                             struct bch_replicas_entry *);
9 bool bch2_replicas_marked(struct bch_fs *, enum bch_data_type,
10                           struct bch_devs_list, bool);
11 bool bch2_bkey_replicas_marked(struct bch_fs *,
12                                struct bkey_s_c, bool);
13 int bch2_mark_replicas(struct bch_fs *, enum bch_data_type,
14                        struct bch_devs_list);
15 int bch2_mark_bkey_replicas(struct bch_fs *, struct bkey_s_c);
16
17 void bch2_cpu_replicas_to_text(struct printbuf *, struct bch_replicas_cpu *);
18
19 struct replicas_status {
20         struct {
21                 int             redundancy;
22                 unsigned        nr_offline;
23         }                       replicas[BCH_DATA_NR];
24 };
25
26 struct replicas_status __bch2_replicas_status(struct bch_fs *,
27                                               struct bch_devs_mask);
28 struct replicas_status bch2_replicas_status(struct bch_fs *);
29 bool bch2_have_enough_devs(struct replicas_status, unsigned);
30
31 int bch2_replicas_online(struct bch_fs *, bool);
32 unsigned bch2_dev_has_data(struct bch_fs *, struct bch_dev *);
33
34 int bch2_replicas_gc_end(struct bch_fs *, int);
35 int bch2_replicas_gc_start(struct bch_fs *, unsigned);
36
37 /* iterate over superblock replicas - used by userspace tools: */
38
39 #define replicas_entry_bytes(_i)                                        \
40         (offsetof(typeof(*(_i)), devs) + (_i)->nr_devs)
41
42 #define replicas_entry_next(_i)                                         \
43         ((typeof(_i)) ((void *) (_i) + replicas_entry_bytes(_i)))
44
45 #define for_each_replicas_entry(_r, _i)                                 \
46         for (_i = (_r)->entries;                                        \
47              (void *) (_i) < vstruct_end(&(_r)->field) && (_i)->data_type;\
48              (_i) = replicas_entry_next(_i))
49
50 #define for_each_replicas_entry_v0(_r, _i)                              \
51         for (_i = (_r)->entries;                                        \
52              (void *) (_i) < vstruct_end(&(_r)->field) && (_i)->data_type;\
53              (_i) = replicas_entry_next(_i))
54
55 int bch2_sb_replicas_to_cpu_replicas(struct bch_fs *);
56
57 extern const struct bch_sb_field_ops bch_sb_field_ops_replicas;
58 extern const struct bch_sb_field_ops bch_sb_field_ops_replicas_v0;
59
60 #endif /* _BCACHEFS_REPLICAS_H */