summaryrefslogtreecommitdiff
path: root/libbcachefs/super-io.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-02-07 08:08:24 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2018-02-08 15:33:42 -0500
commit6976570d670e4053f026d380cfe5397a0a8ed139 (patch)
tree29abbf0f904cf1a12e7299b270cf59f1e22c3be3 /libbcachefs/super-io.h
parenta9f5937a9764003f3c88ccff4f92da259f025674 (diff)
Update bcachefs sources to d5e561b3cc bcachefs: BCH_DATA ioctl
Diffstat (limited to 'libbcachefs/super-io.h')
-rw-r--r--libbcachefs/super-io.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/libbcachefs/super-io.h b/libbcachefs/super-io.h
index 59a8b816..eb85410c 100644
--- a/libbcachefs/super-io.h
+++ b/libbcachefs/super-io.h
@@ -127,6 +127,7 @@ static inline struct bch_member_cpu bch2_mi_to_cpu(struct bch_member *mi)
.nbuckets = le64_to_cpu(mi->nbuckets),
.first_bucket = le16_to_cpu(mi->first_bucket),
.bucket_size = le16_to_cpu(mi->bucket_size),
+ .group = BCH_MEMBER_GROUP(mi),
.state = BCH_MEMBER_STATE(mi),
.tier = BCH_MEMBER_TIER(mi),
.replacement = BCH_MEMBER_REPLACEMENT(mi),
@@ -177,4 +178,65 @@ replicas_entry_next(struct bch_replicas_entry *i)
(void *) (_i) < vstruct_end(&(_r)->field) && (_i)->data_type;\
(_i) = replicas_entry_next(_i))
+/* disk groups: */
+
+static inline unsigned disk_groups_nr(struct bch_sb_field_disk_groups *groups)
+{
+ return groups
+ ? (vstruct_end(&groups->field) -
+ (void *) &groups->entries[0]) / sizeof(struct bch_disk_group)
+ : 0;
+}
+
+struct target {
+ enum {
+ TARGET_NULL,
+ TARGET_DEV,
+ TARGET_GROUP,
+ } type;
+ union {
+ unsigned dev;
+ unsigned group;
+ };
+};
+
+static inline u16 dev_to_target(unsigned dev)
+{
+ return 1 + dev;
+}
+
+static inline u16 group_to_target(unsigned group)
+{
+ return 1 + U8_MAX + group;
+}
+
+static inline struct target target_decode(unsigned target)
+{
+ if (!target)
+ return (struct target) { .type = TARGET_NULL };
+
+ --target;
+ if (target <= U8_MAX)
+ return (struct target) { .type = TARGET_DEV, .dev = target };
+
+ target -= U8_MAX;
+ return (struct target) { .type = TARGET_GROUP, .group = target };
+}
+
+static inline bool dev_in_target(struct bch_dev *ca, unsigned target)
+{
+ struct target t = target_decode(target);
+
+ switch (t.type) {
+ case TARGET_DEV:
+ return ca->dev_idx == t.dev;
+ case TARGET_GROUP:
+ return ca->mi.group && ca->mi.group == t.group;
+ default:
+ BUG();
+ }
+}
+
+const struct bch_devs_mask *bch2_target_to_mask(struct bch_fs *, unsigned);
+
#endif /* _BCACHEFS_SUPER_IO_H */