1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_DISK_GROUPS_H
3 #define _BCACHEFS_DISK_GROUPS_H
5 #include "disk_groups_types.h"
7 extern const struct bch_sb_field_ops bch_sb_field_ops_disk_groups
;
9 static inline unsigned disk_groups_nr(struct bch_sb_field_disk_groups
*groups
)
12 ? (vstruct_end(&groups
->field
) -
13 (void *) &groups
->entries
[0]) / sizeof(struct bch_disk_group
)
29 #define TARGET_DEV_START 1
30 #define TARGET_GROUP_START (256 + TARGET_DEV_START)
32 static inline u16
dev_to_target(unsigned dev
)
34 return TARGET_DEV_START
+ dev
;
37 static inline u16
group_to_target(unsigned group
)
39 return TARGET_GROUP_START
+ group
;
42 static inline struct target
target_decode(unsigned target
)
44 if (target
>= TARGET_GROUP_START
)
45 return (struct target
) {
47 .group
= target
- TARGET_GROUP_START
50 if (target
>= TARGET_DEV_START
)
51 return (struct target
) {
53 .group
= target
- TARGET_DEV_START
56 return (struct target
) { .type
= TARGET_NULL
};
59 const struct bch_devs_mask
*bch2_target_to_mask(struct bch_fs
*, unsigned);
61 static inline struct bch_devs_mask
target_rw_devs(struct bch_fs
*c
,
62 enum bch_data_type data_type
,
65 struct bch_devs_mask devs
= c
->rw_devs
[data_type
];
66 const struct bch_devs_mask
*t
= bch2_target_to_mask(c
, target
);
69 bitmap_and(devs
.d
, devs
.d
, t
->d
, BCH_SB_MEMBERS_MAX
);
73 static inline bool bch2_target_accepts_data(struct bch_fs
*c
,
74 enum bch_data_type data_type
,
77 struct bch_devs_mask rw_devs
= target_rw_devs(c
, data_type
, target
);
78 return !bitmap_empty(rw_devs
.d
, BCH_SB_MEMBERS_MAX
);
81 bool bch2_dev_in_target(struct bch_fs
*, unsigned, unsigned);
83 int bch2_disk_path_find(struct bch_sb_handle
*, const char *);
85 /* Exported for userspace bcachefs-tools: */
86 int bch2_disk_path_find_or_create(struct bch_sb_handle
*, const char *);
88 void bch2_disk_path_to_text(struct printbuf
*, struct bch_fs
*, unsigned);
89 void bch2_disk_path_to_text_sb(struct printbuf
*, struct bch_sb
*, unsigned);
91 void bch2_target_to_text(struct printbuf
*out
, struct bch_fs
*, unsigned);
93 int bch2_opt_target_parse(struct bch_fs
*, const char *, u64
*, struct printbuf
*);
94 void bch2_opt_target_to_text(struct printbuf
*, struct bch_fs
*, struct bch_sb
*, u64
);
96 #define bch2_opt_target (struct bch_opt_fn) { \
97 .parse = bch2_opt_target_parse, \
98 .to_text = bch2_opt_target_to_text, \
101 int bch2_sb_disk_groups_to_cpu(struct bch_fs
*);
103 int __bch2_dev_group_set(struct bch_fs
*, struct bch_dev
*, const char *);
104 int bch2_dev_group_set(struct bch_fs
*, struct bch_dev
*, const char *);
106 const char *bch2_sb_validate_disk_groups(struct bch_sb
*,
107 struct bch_sb_field
*);
109 void bch2_disk_groups_to_text(struct printbuf
*, struct bch_fs
*);
111 #endif /* _BCACHEFS_DISK_GROUPS_H */