1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_REPLICAS_H
3 #define _BCACHEFS_REPLICAS_H
5 #include "replicas_types.h"
7 bool bch2_replicas_marked(struct bch_fs *, enum bch_data_type,
8 struct bch_devs_list, bool);
9 bool bch2_bkey_replicas_marked(struct bch_fs *,
10 struct bkey_s_c, bool);
11 int bch2_mark_replicas(struct bch_fs *, enum bch_data_type,
12 struct bch_devs_list);
13 int bch2_mark_bkey_replicas(struct bch_fs *, struct bkey_s_c);
15 void bch2_cpu_replicas_to_text(struct printbuf *, struct bch_replicas_cpu *);
17 struct replicas_status {
21 } replicas[BCH_DATA_NR];
24 struct replicas_status __bch2_replicas_status(struct bch_fs *,
25 struct bch_devs_mask);
26 struct replicas_status bch2_replicas_status(struct bch_fs *);
27 bool bch2_have_enough_devs(struct replicas_status, unsigned);
29 int bch2_replicas_online(struct bch_fs *, bool);
30 unsigned bch2_dev_has_data(struct bch_fs *, struct bch_dev *);
32 int bch2_replicas_gc_end(struct bch_fs *, int);
33 int bch2_replicas_gc_start(struct bch_fs *, unsigned);
35 /* iterate over superblock replicas - used by userspace tools: */
37 #define replicas_entry_bytes(_i) \
38 (offsetof(typeof(*(_i)), devs) + (_i)->nr_devs)
40 #define replicas_entry_next(_i) \
41 ((typeof(_i)) ((void *) (_i) + replicas_entry_bytes(_i)))
43 #define for_each_replicas_entry(_r, _i) \
44 for (_i = (_r)->entries; \
45 (void *) (_i) < vstruct_end(&(_r)->field) && (_i)->data_type;\
46 (_i) = replicas_entry_next(_i))
48 #define for_each_replicas_entry_v0(_r, _i) \
49 for (_i = (_r)->entries; \
50 (void *) (_i) < vstruct_end(&(_r)->field) && (_i)->data_type;\
51 (_i) = replicas_entry_next(_i))
53 int bch2_sb_replicas_to_cpu_replicas(struct bch_fs *);
55 extern const struct bch_sb_field_ops bch_sb_field_ops_replicas;
56 extern const struct bch_sb_field_ops bch_sb_field_ops_replicas_v0;
58 #endif /* _BCACHEFS_REPLICAS_H */