1 #ifndef _BCACHEFS_SUPER_IO_H
2 #define _BCACHEFS_SUPER_IO_H
6 #include "super_types.h"
9 #include <asm/byteorder.h>
11 struct bch_sb_field *bch2_sb_field_get(struct bch_sb *, enum bch_sb_field_type);
12 struct bch_sb_field *bch2_sb_field_resize(struct bch_sb_handle *,
13 enum bch_sb_field_type, unsigned);
14 void bch2_sb_field_delete(struct bch_sb_handle *, enum bch_sb_field_type);
16 #define field_to_type(_f, _name) \
17 container_of_or_null(_f, struct bch_sb_field_##_name, field)
19 #define x(_name, _nr) \
20 static inline struct bch_sb_field_##_name * \
21 bch2_sb_get_##_name(struct bch_sb *sb) \
23 return field_to_type(bch2_sb_field_get(sb, \
24 BCH_SB_FIELD_##_name), _name); \
27 static inline struct bch_sb_field_##_name * \
28 bch2_sb_resize_##_name(struct bch_sb_handle *sb, unsigned u64s) \
30 return field_to_type(bch2_sb_field_resize(sb, \
31 BCH_SB_FIELD_##_name, u64s), _name); \
37 extern const char * const bch2_sb_fields[];
39 struct bch_sb_field_ops {
40 const char * (*validate)(struct bch_sb *, struct bch_sb_field *);
41 void (*to_text)(struct printbuf *, struct bch_sb *,
42 struct bch_sb_field *);
45 static inline bool bch2_sb_test_feature(struct bch_sb *sb,
46 enum bch_sb_features f)
51 return le64_to_cpu(sb->features[w]) & (1ULL << b);
54 static inline void bch2_sb_set_feature(struct bch_sb *sb,
55 enum bch_sb_features f)
57 if (!bch2_sb_test_feature(sb, f)) {
61 le64_add_cpu(&sb->features[w], 1ULL << b);
65 static inline __le64 bch2_sb_magic(struct bch_fs *c)
68 memcpy(&ret, &c->sb.uuid, sizeof(ret));
72 static inline __u64 jset_magic(struct bch_fs *c)
74 return __le64_to_cpu(bch2_sb_magic(c) ^ JSET_MAGIC);
77 static inline __u64 bset_magic(struct bch_fs *c)
79 return __le64_to_cpu(bch2_sb_magic(c) ^ BSET_MAGIC);
82 int bch2_sb_to_fs(struct bch_fs *, struct bch_sb *);
83 int bch2_sb_from_fs(struct bch_fs *, struct bch_dev *);
85 void bch2_free_super(struct bch_sb_handle *);
86 int bch2_sb_realloc(struct bch_sb_handle *, unsigned);
88 const char *bch2_sb_validate(struct bch_sb_handle *);
90 int bch2_read_super(const char *, struct bch_opts *, struct bch_sb_handle *);
91 void bch2_write_super(struct bch_fs *);
93 /* BCH_SB_FIELD_journal: */
95 static inline unsigned bch2_nr_journal_buckets(struct bch_sb_field_journal *j)
98 ? (__le64 *) vstruct_end(&j->field) - j->buckets
102 /* BCH_SB_FIELD_members: */
104 static inline bool bch2_member_exists(struct bch_member *m)
106 return !bch2_is_zero(m->uuid.b, sizeof(uuid_le));
109 static inline bool bch2_dev_exists(struct bch_sb *sb,
110 struct bch_sb_field_members *mi,
113 return dev < sb->nr_devices &&
114 bch2_member_exists(&mi->members[dev]);
117 static inline struct bch_member_cpu bch2_mi_to_cpu(struct bch_member *mi)
119 return (struct bch_member_cpu) {
120 .nbuckets = le64_to_cpu(mi->nbuckets),
121 .first_bucket = le16_to_cpu(mi->first_bucket),
122 .bucket_size = le16_to_cpu(mi->bucket_size),
123 .group = BCH_MEMBER_GROUP(mi),
124 .state = BCH_MEMBER_STATE(mi),
125 .replacement = BCH_MEMBER_REPLACEMENT(mi),
126 .discard = BCH_MEMBER_DISCARD(mi),
127 .data_allowed = BCH_MEMBER_DATA_ALLOWED(mi),
128 .durability = BCH_MEMBER_DURABILITY(mi)
129 ? BCH_MEMBER_DURABILITY(mi) - 1
131 .valid = !bch2_is_zero(mi->uuid.b, sizeof(uuid_le)),
135 /* BCH_SB_FIELD_clean: */
138 bch2_journal_super_entries_add_common(struct bch_fs *,
139 struct jset_entry *);
141 void bch2_sb_clean_renumber(struct bch_sb_field_clean *, int);
143 void bch2_fs_mark_clean(struct bch_fs *, bool);
145 void bch2_sb_field_to_text(struct printbuf *, struct bch_sb *,
146 struct bch_sb_field *);
148 #endif /* _BCACHEFS_SUPER_IO_H */