1 #ifndef _BCACHE_SUPER_IO_H
2 #define _BCACHE_SUPER_IO_H
5 #include "super_types.h"
7 #include <asm/byteorder.h>
9 struct bch_sb_field *bch2_sb_field_get(struct bch_sb *, enum bch_sb_field_type);
10 struct bch_sb_field *bch2_sb_field_resize(struct bcache_superblock *,
11 enum bch_sb_field_type, unsigned);
12 struct bch_sb_field *bch2_fs_sb_field_resize(struct bch_fs *,
13 enum bch_sb_field_type, unsigned);
15 #define field_to_type(_f, _name) \
16 container_of_or_null(_f, struct bch_sb_field_##_name, field)
18 #define BCH_SB_FIELD_TYPE(_name) \
19 static inline struct bch_sb_field_##_name * \
20 bch2_sb_get_##_name(struct bch_sb *sb) \
22 return field_to_type(bch2_sb_field_get(sb, \
23 BCH_SB_FIELD_##_name), _name); \
26 static inline struct bch_sb_field_##_name * \
27 bch2_sb_resize_##_name(struct bcache_superblock *sb, unsigned u64s) \
29 return field_to_type(bch2_sb_field_resize(sb, \
30 BCH_SB_FIELD_##_name, u64s), _name); \
33 static inline struct bch_sb_field_##_name * \
34 bch2_fs_sb_resize_##_name(struct bch_fs *c, unsigned u64s) \
36 return field_to_type(bch2_fs_sb_field_resize(c, \
37 BCH_SB_FIELD_##_name, u64s), _name); \
40 BCH_SB_FIELD_TYPE(journal);
41 BCH_SB_FIELD_TYPE(members);
42 BCH_SB_FIELD_TYPE(crypt);
44 static inline bool bch2_sb_test_feature(struct bch_sb *sb,
45 enum bch_sb_features f)
50 return le64_to_cpu(sb->features[w]) & (1ULL << b);
53 static inline void bch2_sb_set_feature(struct bch_sb *sb,
54 enum bch_sb_features f)
56 if (!bch2_sb_test_feature(sb, f)) {
60 le64_add_cpu(&sb->features[w], 1ULL << b);
64 static inline __le64 bch2_sb_magic(struct bch_fs *c)
67 memcpy(&ret, &c->sb.uuid, sizeof(ret));
71 static inline __u64 jset_magic(struct bch_fs *c)
73 return __le64_to_cpu(bch2_sb_magic(c) ^ JSET_MAGIC);
76 static inline __u64 pset_magic(struct bch_fs *c)
78 return __le64_to_cpu(bch2_sb_magic(c) ^ PSET_MAGIC);
81 static inline __u64 bset_magic(struct bch_fs *c)
83 return __le64_to_cpu(bch2_sb_magic(c) ^ BSET_MAGIC);
86 static inline struct bch_member_cpu bch2_mi_to_cpu(struct bch_member *mi)
88 return (struct bch_member_cpu) {
89 .nbuckets = le64_to_cpu(mi->nbuckets),
90 .first_bucket = le16_to_cpu(mi->first_bucket),
91 .bucket_size = le16_to_cpu(mi->bucket_size),
92 .state = BCH_MEMBER_STATE(mi),
93 .tier = BCH_MEMBER_TIER(mi),
94 .has_metadata = BCH_MEMBER_HAS_METADATA(mi),
95 .has_data = BCH_MEMBER_HAS_DATA(mi),
96 .replacement = BCH_MEMBER_REPLACEMENT(mi),
97 .discard = BCH_MEMBER_DISCARD(mi),
98 .valid = !bch2_is_zero(mi->uuid.b, sizeof(uuid_le)),
102 int bch2_sb_to_fs(struct bch_fs *, struct bch_sb *);
103 int bch2_sb_from_fs(struct bch_fs *, struct bch_dev *);
105 void bch2_free_super(struct bcache_superblock *);
106 int bch2_super_realloc(struct bcache_superblock *, unsigned);
108 const char *bch2_validate_journal_layout(struct bch_sb *,
109 struct bch_member_cpu);
110 const char *bch2_validate_cache_super(struct bcache_superblock *);
112 const char *bch2_read_super(struct bcache_superblock *,
113 struct bch_opts, const char *);
114 void bch2_write_super(struct bch_fs *);
116 void bch2_check_mark_super_slowpath(struct bch_fs *,
117 const struct bkey_i *, bool);
119 static inline bool bch2_check_super_marked(struct bch_fs *c,
120 const struct bkey_i *k, bool meta)
122 struct bkey_s_c_extent e = bkey_i_to_s_c_extent(k);
123 const struct bch_extent_ptr *ptr;
124 unsigned nr_replicas = 0;
127 extent_for_each_ptr(e, ptr) {
128 struct bch_dev *ca = c->devs[ptr->dev];
134 ? ca->mi.has_metadata
135 : ca->mi.has_data)) {
144 (meta ? c->sb.meta_replicas_have : c->sb.data_replicas_have))
150 static inline void bch2_check_mark_super(struct bch_fs *c,
151 const struct bkey_i *k, bool meta)
153 if (bch2_check_super_marked(c, k, meta))
156 bch2_check_mark_super_slowpath(c, k, meta);
159 #endif /* _BCACHE_SUPER_IO_H */