]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/super-io.h
Update bcachefs sources to 2a6125decb43 bcachefs: bch_sb_field_downgrade
[bcachefs-tools-debian] / libbcachefs / super-io.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_SUPER_IO_H
3 #define _BCACHEFS_SUPER_IO_H
4
5 #include "extents.h"
6 #include "eytzinger.h"
7 #include "super_types.h"
8 #include "super.h"
9 #include "sb-members.h"
10
11 #include <asm/byteorder.h>
12
13 static inline bool bch2_version_compatible(u16 version)
14 {
15         return BCH_VERSION_MAJOR(version) <= BCH_VERSION_MAJOR(bcachefs_metadata_version_current) &&
16                 version >= bcachefs_metadata_version_min;
17 }
18
19 void bch2_version_to_text(struct printbuf *, unsigned);
20 unsigned bch2_latest_compatible_version(unsigned);
21
22 u64 bch2_upgrade_recovery_passes(struct bch_fs *c,
23                                  unsigned,
24                                  unsigned);
25
26 static inline size_t bch2_sb_field_bytes(struct bch_sb_field *f)
27 {
28         return le32_to_cpu(f->u64s) * sizeof(u64);
29 }
30
31 #define field_to_type(_f, _name)                                        \
32         container_of_or_null(_f, struct bch_sb_field_##_name, field)
33
34 struct bch_sb_field *bch2_sb_field_get_id(struct bch_sb *, enum bch_sb_field_type);
35 #define bch2_sb_field_get(_sb, _name)                                   \
36         field_to_type(bch2_sb_field_get_id(_sb, BCH_SB_FIELD_##_name), _name)
37
38 struct bch_sb_field *bch2_sb_field_resize_id(struct bch_sb_handle *,
39                                              enum bch_sb_field_type, unsigned);
40 #define bch2_sb_field_resize(_sb, _name, _u64s)                         \
41         field_to_type(bch2_sb_field_resize_id(_sb, BCH_SB_FIELD_##_name, _u64s), _name)
42
43 struct bch_sb_field *bch2_sb_field_get_minsize_id(struct bch_sb_handle *,
44                                         enum bch_sb_field_type, unsigned);
45 #define bch2_sb_field_get_minsize(_sb, _name, _u64s)                            \
46         field_to_type(bch2_sb_field_get_minsize_id(_sb, BCH_SB_FIELD_##_name, _u64s), _name)
47
48 #define bch2_sb_field_nr_entries(_f)                                    \
49         (_f ? ((bch2_sb_field_bytes(&_f->field) - sizeof(*_f)) /        \
50                sizeof(_f->entries[0]))                                  \
51             : 0)
52
53 void bch2_sb_field_delete(struct bch_sb_handle *, enum bch_sb_field_type);
54
55 extern const char * const bch2_sb_fields[];
56
57 struct bch_sb_field_ops {
58         int     (*validate)(struct bch_sb *, struct bch_sb_field *, struct printbuf *);
59         void    (*to_text)(struct printbuf *, struct bch_sb *, struct bch_sb_field *);
60 };
61
62 static inline __le64 bch2_sb_magic(struct bch_fs *c)
63 {
64         __le64 ret;
65
66         memcpy(&ret, &c->sb.uuid, sizeof(ret));
67         return ret;
68 }
69
70 static inline __u64 jset_magic(struct bch_fs *c)
71 {
72         return __le64_to_cpu(bch2_sb_magic(c) ^ JSET_MAGIC);
73 }
74
75 static inline __u64 bset_magic(struct bch_fs *c)
76 {
77         return __le64_to_cpu(bch2_sb_magic(c) ^ BSET_MAGIC);
78 }
79
80 int bch2_sb_to_fs(struct bch_fs *, struct bch_sb *);
81 int bch2_sb_from_fs(struct bch_fs *, struct bch_dev *);
82
83 void bch2_free_super(struct bch_sb_handle *);
84 int bch2_sb_realloc(struct bch_sb_handle *, unsigned);
85
86 int bch2_read_super(const char *, struct bch_opts *, struct bch_sb_handle *);
87 int bch2_read_super_silent(const char *, struct bch_opts *, struct bch_sb_handle *);
88 int bch2_write_super(struct bch_fs *);
89 void __bch2_check_set_feature(struct bch_fs *, unsigned);
90
91 static inline void bch2_check_set_feature(struct bch_fs *c, unsigned feat)
92 {
93         if (!(c->sb.features & (1ULL << feat)))
94                 __bch2_check_set_feature(c, feat);
95 }
96
97 void bch2_sb_maybe_downgrade(struct bch_fs *);
98 void bch2_sb_upgrade(struct bch_fs *, unsigned);
99
100 void bch2_sb_field_to_text(struct printbuf *, struct bch_sb *,
101                            struct bch_sb_field *);
102 void bch2_sb_layout_to_text(struct printbuf *, struct bch_sb_layout *);
103 void bch2_sb_to_text(struct printbuf *, struct bch_sb *, bool, unsigned);
104
105 #endif /* _BCACHEFS_SUPER_IO_H */