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