1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_DISK_GROUPS_H
3 #define _BCACHEFS_DISK_GROUPS_H
5 extern const struct bch_sb_field_ops bch_sb_field_ops_disk_groups;
7 static inline unsigned disk_groups_nr(struct bch_sb_field_disk_groups *groups)
10 ? (vstruct_end(&groups->field) -
11 (void *) &groups->entries[0]) / sizeof(struct bch_disk_group)
27 #define TARGET_DEV_START 1
28 #define TARGET_GROUP_START (256 + TARGET_DEV_START)
30 static inline u16 dev_to_target(unsigned dev)
32 return TARGET_DEV_START + dev;
35 static inline u16 group_to_target(unsigned group)
37 return TARGET_GROUP_START + group;
40 static inline struct target target_decode(unsigned target)
42 if (target >= TARGET_GROUP_START)
43 return (struct target) {
45 .group = target - TARGET_GROUP_START
48 if (target >= TARGET_DEV_START)
49 return (struct target) {
51 .group = target - TARGET_DEV_START
54 return (struct target) { .type = TARGET_NULL };
57 const struct bch_devs_mask *bch2_target_to_mask(struct bch_fs *, unsigned);
59 static inline struct bch_devs_mask target_rw_devs(struct bch_fs *c,
60 enum bch_data_type data_type,
63 struct bch_devs_mask devs = c->rw_devs[data_type];
64 const struct bch_devs_mask *t = bch2_target_to_mask(c, target);
67 bitmap_and(devs.d, devs.d, t->d, BCH_SB_MEMBERS_MAX);
71 bool bch2_dev_in_target(struct bch_fs *, unsigned, unsigned);
73 int bch2_disk_path_find(struct bch_sb_handle *, const char *);
75 /* Exported for userspace bcachefs-tools: */
76 int bch2_disk_path_find_or_create(struct bch_sb_handle *, const char *);
78 void bch2_disk_path_to_text(struct printbuf *, struct bch_sb_handle *,
81 int bch2_opt_target_parse(struct bch_fs *, const char *, u64 *);
82 void bch2_opt_target_to_text(struct printbuf *, struct bch_fs *, u64);
84 int bch2_sb_disk_groups_to_cpu(struct bch_fs *);
86 int bch2_dev_group_set(struct bch_fs *, struct bch_dev *, const char *);
88 const char *bch2_sb_validate_disk_groups(struct bch_sb *,
89 struct bch_sb_field *);
91 #endif /* _BCACHEFS_DISK_GROUPS_H */