1 #ifndef _BCACHEFS_REPLICAS_H
2 #define _BCACHEFS_REPLICAS_H
5 #include "replicas_types.h"
7 void bch2_replicas_entry_to_text(struct printbuf *,
8 struct bch_replicas_entry *);
9 void bch2_cpu_replicas_to_text(struct printbuf *, struct bch_replicas_cpu *);
11 static inline struct bch_replicas_entry *
12 cpu_replicas_entry(struct bch_replicas_cpu *r, unsigned i)
14 return (void *) r->entries + r->entry_size * i;
17 int bch2_replicas_entry_idx(struct bch_fs *,
18 struct bch_replicas_entry *);
20 void bch2_devlist_to_replicas(struct bch_replicas_entry *,
22 struct bch_devs_list);
23 bool bch2_replicas_marked(struct bch_fs *,
24 struct bch_replicas_entry *, bool);
25 int bch2_mark_replicas(struct bch_fs *,
26 struct bch_replicas_entry *);
28 bool bch2_bkey_replicas_marked_locked(struct bch_fs *,
29 struct bkey_s_c, bool);
30 void bch2_bkey_to_replicas(struct bch_replicas_entry *, struct bkey_s_c);
31 bool bch2_bkey_replicas_marked(struct bch_fs *,
32 struct bkey_s_c, bool);
33 int bch2_mark_bkey_replicas(struct bch_fs *, struct bkey_s_c);
35 static inline void bch2_replicas_entry_cached(struct bch_replicas_entry *e,
38 e->data_type = BCH_DATA_CACHED;
44 struct replicas_status {
48 } replicas[BCH_DATA_NR];
51 struct replicas_status __bch2_replicas_status(struct bch_fs *,
52 struct bch_devs_mask);
53 struct replicas_status bch2_replicas_status(struct bch_fs *);
54 bool bch2_have_enough_devs(struct replicas_status, unsigned);
56 int bch2_replicas_online(struct bch_fs *, bool);
57 unsigned bch2_dev_has_data(struct bch_fs *, struct bch_dev *);
59 int bch2_replicas_gc_end(struct bch_fs *, int);
60 int bch2_replicas_gc_start(struct bch_fs *, unsigned);
62 int bch2_replicas_set_usage(struct bch_fs *,
63 struct bch_replicas_entry *,
66 #define for_each_cpu_replicas_entry(_r, _i) \
67 for (_i = (_r)->entries; \
68 (void *) (_i) < (void *) (_r)->entries + (_r)->nr * (_r)->entry_size;\
69 _i = (void *) (_i) + (_r)->entry_size)
71 /* iterate over superblock replicas - used by userspace tools: */
73 #define replicas_entry_bytes(_i) \
74 (offsetof(typeof(*(_i)), devs) + (_i)->nr_devs)
76 #define replicas_entry_next(_i) \
77 ((typeof(_i)) ((void *) (_i) + replicas_entry_bytes(_i)))
79 #define for_each_replicas_entry(_r, _i) \
80 for (_i = (_r)->entries; \
81 (void *) (_i) < vstruct_end(&(_r)->field) && (_i)->data_type;\
82 (_i) = replicas_entry_next(_i))
84 #define for_each_replicas_entry_v0(_r, _i) \
85 for (_i = (_r)->entries; \
86 (void *) (_i) < vstruct_end(&(_r)->field) && (_i)->data_type;\
87 (_i) = replicas_entry_next(_i))
89 int bch2_sb_replicas_to_cpu_replicas(struct bch_fs *);
91 extern const struct bch_sb_field_ops bch_sb_field_ops_replicas;
92 extern const struct bch_sb_field_ops bch_sb_field_ops_replicas_v0;
94 int bch2_fs_replicas_init(struct bch_fs *);
96 #endif /* _BCACHEFS_REPLICAS_H */