]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/super-io.h
Update bcachefs sources to 7250b2ee5574 bcachefs: Fix deleted inodes btree in snapsho...
[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 void bch2_sb_field_delete(struct bch_sb_handle *, enum bch_sb_field_type);
44
45 extern const char * const bch2_sb_fields[];
46
47 struct bch_sb_field_ops {
48         int     (*validate)(struct bch_sb *, struct bch_sb_field *, struct printbuf *);
49         void    (*to_text)(struct printbuf *, struct bch_sb *, struct bch_sb_field *);
50 };
51
52 static inline __le64 bch2_sb_magic(struct bch_fs *c)
53 {
54         __le64 ret;
55
56         memcpy(&ret, &c->sb.uuid, sizeof(ret));
57         return ret;
58 }
59
60 static inline __u64 jset_magic(struct bch_fs *c)
61 {
62         return __le64_to_cpu(bch2_sb_magic(c) ^ JSET_MAGIC);
63 }
64
65 static inline __u64 bset_magic(struct bch_fs *c)
66 {
67         return __le64_to_cpu(bch2_sb_magic(c) ^ BSET_MAGIC);
68 }
69
70 int bch2_sb_to_fs(struct bch_fs *, struct bch_sb *);
71 int bch2_sb_from_fs(struct bch_fs *, struct bch_dev *);
72
73 void bch2_free_super(struct bch_sb_handle *);
74 int bch2_sb_realloc(struct bch_sb_handle *, unsigned);
75
76 int bch2_read_super(const char *, struct bch_opts *, struct bch_sb_handle *);
77 int bch2_write_super(struct bch_fs *);
78 void __bch2_check_set_feature(struct bch_fs *, unsigned);
79
80 static inline void bch2_check_set_feature(struct bch_fs *c, unsigned feat)
81 {
82         if (!(c->sb.features & (1ULL << feat)))
83                 __bch2_check_set_feature(c, feat);
84 }
85
86 void bch2_sb_maybe_downgrade(struct bch_fs *);
87 void bch2_sb_upgrade(struct bch_fs *, unsigned);
88
89 void bch2_sb_field_to_text(struct printbuf *, struct bch_sb *,
90                            struct bch_sb_field *);
91 void bch2_sb_layout_to_text(struct printbuf *, struct bch_sb_layout *);
92 void bch2_sb_to_text(struct printbuf *, struct bch_sb *, bool, unsigned);
93
94 #endif /* _BCACHEFS_SUPER_IO_H */