]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/disk_groups.h
Update bcachefs sources to 0906b1fb49 bcachefs: fixes for 32 bit/big endian machines
[bcachefs-tools-debian] / libbcachefs / disk_groups.h
1 #ifndef _BCACHEFS_DISK_GROUPS_H
2 #define _BCACHEFS_DISK_GROUPS_H
3
4 extern const struct bch_sb_field_ops bch_sb_field_ops_disk_groups;
5
6 static inline unsigned disk_groups_nr(struct bch_sb_field_disk_groups *groups)
7 {
8         return groups
9                 ? (vstruct_end(&groups->field) -
10                    (void *) &groups->entries[0]) / sizeof(struct bch_disk_group)
11                 : 0;
12 }
13
14 struct target {
15         enum {
16                 TARGET_NULL,
17                 TARGET_DEV,
18                 TARGET_GROUP,
19         }                       type;
20         union {
21                 unsigned        dev;
22                 unsigned        group;
23         };
24 };
25
26 #define TARGET_DEV_START        1
27 #define TARGET_GROUP_START      (256 + TARGET_DEV_START)
28
29 static inline u16 dev_to_target(unsigned dev)
30 {
31         return TARGET_DEV_START + dev;
32 }
33
34 static inline u16 group_to_target(unsigned group)
35 {
36         return TARGET_GROUP_START + group;
37 }
38
39 static inline struct target target_decode(unsigned target)
40 {
41         if (target >= TARGET_GROUP_START)
42                 return (struct target) {
43                         .type   = TARGET_GROUP,
44                         .group  = target - TARGET_GROUP_START
45                 };
46
47         if (target >= TARGET_DEV_START)
48                 return (struct target) {
49                         .type   = TARGET_DEV,
50                         .group  = target - TARGET_DEV_START
51                 };
52
53         return (struct target) { .type = TARGET_NULL };
54 }
55
56 const struct bch_devs_mask *bch2_target_to_mask(struct bch_fs *, unsigned);
57 bool bch2_dev_in_target(struct bch_fs *, unsigned, unsigned);
58
59 int bch2_disk_path_find(struct bch_sb_handle *, const char *);
60 int bch2_disk_path_find_or_create(struct bch_sb_handle *, const char *);
61 int bch2_disk_path_print(struct bch_sb_handle *, char *, size_t, unsigned);
62
63 int bch2_opt_target_parse(struct bch_fs *, const char *, u64 *);
64 int bch2_opt_target_print(struct bch_fs *, char *, size_t, u64);
65
66 int bch2_sb_disk_groups_to_cpu(struct bch_fs *);
67
68 int bch2_dev_group_set(struct bch_fs *, struct bch_dev *, const char *);
69
70 const char *bch2_sb_validate_disk_groups(struct bch_sb *,
71                                          struct bch_sb_field *);
72
73 #endif /* _BCACHEFS_DISK_GROUPS_H */