xref: /linux/fs/bcachefs/sb-members_format.h (revision 2a6b6c9a226279b4f6668450ddb21ae655558087)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_SB_MEMBERS_FORMAT_H
3 #define _BCACHEFS_SB_MEMBERS_FORMAT_H
4 
5 /*
6  * We refer to members with bitmasks in various places - but we need to get rid
7  * of this limit:
8  */
9 #define BCH_SB_MEMBERS_MAX		64
10 
11 #define BCH_MIN_NR_NBUCKETS	(1 << 6)
12 
13 #define BCH_IOPS_MEASUREMENTS()			\
14 	x(seqread,	0)			\
15 	x(seqwrite,	1)			\
16 	x(randread,	2)			\
17 	x(randwrite,	3)
18 
19 enum bch_iops_measurement {
20 #define x(t, n) BCH_IOPS_##t = n,
21 	BCH_IOPS_MEASUREMENTS()
22 #undef x
23 	BCH_IOPS_NR
24 };
25 
26 #define BCH_MEMBER_ERROR_TYPES()		\
27 	x(read,		0)			\
28 	x(write,	1)			\
29 	x(checksum,	2)
30 
31 enum bch_member_error_type {
32 #define x(t, n) BCH_MEMBER_ERROR_##t = n,
33 	BCH_MEMBER_ERROR_TYPES()
34 #undef x
35 	BCH_MEMBER_ERROR_NR
36 };
37 
38 struct bch_member {
39 	__uuid_t		uuid;
40 	__le64			nbuckets;	/* device size */
41 	__le16			first_bucket;   /* index of first bucket used */
42 	__le16			bucket_size;	/* sectors */
43 	__u8			btree_bitmap_shift;
44 	__u8			pad[3];
45 	__le64			last_mount;	/* time_t */
46 
47 	__le64			flags;
48 	__le32			iops[4];
49 	__le64			errors[BCH_MEMBER_ERROR_NR];
50 	__le64			errors_at_reset[BCH_MEMBER_ERROR_NR];
51 	__le64			errors_reset_time;
52 	__le64			seq;
53 	__le64			btree_allocated_bitmap;
54 	/*
55 	 * On recovery from a clean shutdown we don't normally read the journal,
56 	 * but we still want to resume writing from where we left off so we
57 	 * don't overwrite more than is necessary, for list journal debugging:
58 	 */
59 	__le32			last_journal_bucket;
60 	__le32			last_journal_bucket_offset;
61 };
62 
63 /*
64  * This limit comes from the bucket_gens array - it's a single allocation, and
65  * kernel allocation are limited to INT_MAX
66  */
67 #define BCH_MEMBER_NBUCKETS_MAX	(INT_MAX - 64)
68 
69 #define BCH_MEMBER_V1_BYTES	56
70 
71 LE64_BITMASK(BCH_MEMBER_STATE,		struct bch_member, flags,  0,  4)
72 /* 4-14 unused, was TIER, HAS_(META)DATA, REPLACEMENT */
73 LE64_BITMASK(BCH_MEMBER_DISCARD,	struct bch_member, flags, 14, 15)
74 LE64_BITMASK(BCH_MEMBER_DATA_ALLOWED,	struct bch_member, flags, 15, 20)
75 LE64_BITMASK(BCH_MEMBER_GROUP,		struct bch_member, flags, 20, 28)
76 LE64_BITMASK(BCH_MEMBER_DURABILITY,	struct bch_member, flags, 28, 30)
77 LE64_BITMASK(BCH_MEMBER_FREESPACE_INITIALIZED,
78 					struct bch_member, flags, 30, 31)
79 
80 #if 0
81 LE64_BITMASK(BCH_MEMBER_NR_READ_ERRORS,	struct bch_member, flags[1], 0,  20);
82 LE64_BITMASK(BCH_MEMBER_NR_WRITE_ERRORS,struct bch_member, flags[1], 20, 40);
83 #endif
84 
85 #define BCH_MEMBER_STATES()			\
86 	x(rw,		0)			\
87 	x(ro,		1)			\
88 	x(failed,	2)			\
89 	x(spare,	3)
90 
91 enum bch_member_state {
92 #define x(t, n) BCH_MEMBER_STATE_##t = n,
93 	BCH_MEMBER_STATES()
94 #undef x
95 	BCH_MEMBER_STATE_NR
96 };
97 
98 struct bch_sb_field_members_v1 {
99 	struct bch_sb_field	field;
100 	struct bch_member	_members[]; //Members are now variable size
101 };
102 
103 struct bch_sb_field_members_v2 {
104 	struct bch_sb_field	field;
105 	__le16			member_bytes; //size of single member entry
106 	u8			pad[6];
107 	struct bch_member	_members[];
108 };
109 
110 #endif /* _BCACHEFS_SB_MEMBERS_FORMAT_H */
111