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