]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/bcachefs_format.h
Update bcachefs sources to 9ceb982d77 bcachefs: Store bucket gens in a btree
[bcachefs-tools-debian] / libbcachefs / bcachefs_format.h
1 #ifndef _BCACHEFS_FORMAT_H
2 #define _BCACHEFS_FORMAT_H
3
4 /*
5  * bcachefs on disk data structures
6  */
7
8 #include <asm/types.h>
9 #include <asm/byteorder.h>
10 #include <linux/uuid.h>
11
12 #define LE32_BITMASK(name, type, field, offset, end)                    \
13 static const unsigned   name##_OFFSET = offset;                         \
14 static const unsigned   name##_BITS = (end - offset);                   \
15 static const __u64      name##_MAX = (1ULL << (end - offset)) - 1;      \
16                                                                         \
17 static inline __u64 name(const type *k)                                 \
18 {                                                                       \
19         return (__le32_to_cpu(k->field) >> offset) &                    \
20                 ~(~0ULL << (end - offset));                             \
21 }                                                                       \
22                                                                         \
23 static inline void SET_##name(type *k, __u64 v)                         \
24 {                                                                       \
25         __u64 new = __le32_to_cpu(k->field);                            \
26                                                                         \
27         new &= ~(~(~0ULL << (end - offset)) << offset);                 \
28         new |= (v & ~(~0ULL << (end - offset))) << offset;              \
29         k->field = __cpu_to_le32(new);                                  \
30 }
31
32 #define LE64_BITMASK(name, type, field, offset, end)                    \
33 static const unsigned   name##_OFFSET = offset;                         \
34 static const unsigned   name##_BITS = (end - offset);                   \
35 static const __u64      name##_MAX = (1ULL << (end - offset)) - 1;      \
36                                                                         \
37 static inline __u64 name(const type *k)                                 \
38 {                                                                       \
39         return (__le64_to_cpu(k->field) >> offset) &                    \
40                 ~(~0ULL << (end - offset));                             \
41 }                                                                       \
42                                                                         \
43 static inline void SET_##name(type *k, __u64 v)                         \
44 {                                                                       \
45         __u64 new = __le64_to_cpu(k->field);                            \
46                                                                         \
47         new &= ~(~(~0ULL << (end - offset)) << offset);                 \
48         new |= (v & ~(~0ULL << (end - offset))) << offset;              \
49         k->field = __cpu_to_le64(new);                                  \
50 }
51
52 struct bkey_format {
53         __u8            key_u64s;
54         __u8            nr_fields;
55         /* One unused slot for now: */
56         __u8            bits_per_field[6];
57         __le64          field_offset[6];
58 };
59
60 /* Btree keys - all units are in sectors */
61
62 struct bpos {
63         /* Word order matches machine byte order */
64 #if defined(__LITTLE_ENDIAN)
65         __u32           snapshot;
66         __u64           offset;
67         __u64           inode;
68 #elif defined(__BIG_ENDIAN)
69         __u64           inode;
70         __u64           offset;         /* Points to end of extent - sectors */
71         __u32           snapshot;
72 #else
73 #error edit for your odd byteorder.
74 #endif
75 } __attribute__((packed, aligned(4)));
76
77 #define KEY_INODE_MAX                   ((__u64)~0ULL)
78 #define KEY_OFFSET_MAX                  ((__u64)~0ULL)
79 #define KEY_SNAPSHOT_MAX                ((__u32)~0U)
80
81 static inline struct bpos POS(__u64 inode, __u64 offset)
82 {
83         struct bpos ret;
84
85         ret.inode       = inode;
86         ret.offset      = offset;
87         ret.snapshot    = 0;
88
89         return ret;
90 }
91
92 #define POS_MIN                         POS(0, 0)
93 #define POS_MAX                         POS(KEY_INODE_MAX, KEY_OFFSET_MAX)
94
95 /* Empty placeholder struct, for container_of() */
96 struct bch_val {
97         __u64           __nothing[0];
98 };
99
100 struct bversion {
101 #if defined(__LITTLE_ENDIAN)
102         __u64           lo;
103         __u32           hi;
104 #elif defined(__BIG_ENDIAN)
105         __u32           hi;
106         __u64           lo;
107 #endif
108 } __attribute__((packed, aligned(4)));
109
110 struct bkey {
111         /* Size of combined key and value, in u64s */
112         __u8            u64s;
113
114         /* Format of key (0 for format local to btree node) */
115 #if defined(__LITTLE_ENDIAN_BITFIELD)
116         __u8            format:7,
117                         needs_whiteout:1;
118 #elif defined (__BIG_ENDIAN_BITFIELD)
119         __u8            needs_whiteout:1,
120                         format:7;
121 #else
122 #error edit for your odd byteorder.
123 #endif
124
125         /* Type of the value */
126         __u8            type;
127
128 #if defined(__LITTLE_ENDIAN)
129         __u8            pad[1];
130
131         struct bversion version;
132         __u32           size;           /* extent size, in sectors */
133         struct bpos     p;
134 #elif defined(__BIG_ENDIAN)
135         struct bpos     p;
136         __u32           size;           /* extent size, in sectors */
137         struct bversion version;
138
139         __u8            pad[1];
140 #endif
141 } __attribute__((packed, aligned(8)));
142
143 struct bkey_packed {
144         __u64           _data[0];
145
146         /* Size of combined key and value, in u64s */
147         __u8            u64s;
148
149         /* Format of key (0 for format local to btree node) */
150
151         /*
152          * XXX: next incompat on disk format change, switch format and
153          * needs_whiteout - bkey_packed() will be cheaper if format is the high
154          * bits of the bitfield
155          */
156 #if defined(__LITTLE_ENDIAN_BITFIELD)
157         __u8            format:7,
158                         needs_whiteout:1;
159 #elif defined (__BIG_ENDIAN_BITFIELD)
160         __u8            needs_whiteout:1,
161                         format:7;
162 #endif
163
164         /* Type of the value */
165         __u8            type;
166         __u8            key_start[0];
167
168         /*
169          * We copy bkeys with struct assignment in various places, and while
170          * that shouldn't be done with packed bkeys we can't disallow it in C,
171          * and it's legal to cast a bkey to a bkey_packed  - so padding it out
172          * to the same size as struct bkey should hopefully be safest.
173          */
174         __u8            pad[sizeof(struct bkey) - 3];
175 } __attribute__((packed, aligned(8)));
176
177 #define BKEY_U64s                       (sizeof(struct bkey) / sizeof(__u64))
178 #define KEY_PACKED_BITS_START           24
179
180 #define KEY_SIZE_MAX                    ((__u32)~0U)
181
182 #define KEY_FORMAT_LOCAL_BTREE          0
183 #define KEY_FORMAT_CURRENT              1
184
185 enum bch_bkey_fields {
186         BKEY_FIELD_INODE,
187         BKEY_FIELD_OFFSET,
188         BKEY_FIELD_SNAPSHOT,
189         BKEY_FIELD_SIZE,
190         BKEY_FIELD_VERSION_HI,
191         BKEY_FIELD_VERSION_LO,
192         BKEY_NR_FIELDS,
193 };
194
195 #define bkey_format_field(name, field)                                  \
196         [BKEY_FIELD_##name] = (sizeof(((struct bkey *) NULL)->field) * 8)
197
198 #define BKEY_FORMAT_CURRENT                                             \
199 ((struct bkey_format) {                                                 \
200         .key_u64s       = BKEY_U64s,                                    \
201         .nr_fields      = BKEY_NR_FIELDS,                               \
202         .bits_per_field = {                                             \
203                 bkey_format_field(INODE,        p.inode),               \
204                 bkey_format_field(OFFSET,       p.offset),              \
205                 bkey_format_field(SNAPSHOT,     p.snapshot),            \
206                 bkey_format_field(SIZE,         size),                  \
207                 bkey_format_field(VERSION_HI,   version.hi),            \
208                 bkey_format_field(VERSION_LO,   version.lo),            \
209         },                                                              \
210 })
211
212 /* bkey with inline value */
213 struct bkey_i {
214         __u64                   _data[0];
215
216         union {
217         struct {
218                 /* Size of combined key and value, in u64s */
219                 __u8            u64s;
220         };
221         struct {
222                 struct bkey     k;
223                 struct bch_val  v;
224         };
225         };
226 };
227
228 #define KEY(_inode, _offset, _size)                                     \
229 ((struct bkey) {                                                        \
230         .u64s           = BKEY_U64s,                                    \
231         .format         = KEY_FORMAT_CURRENT,                           \
232         .p              = POS(_inode, _offset),                         \
233         .size           = _size,                                        \
234 })
235
236 static inline void bkey_init(struct bkey *k)
237 {
238         *k = KEY(0, 0, 0);
239 }
240
241 #define bkey_bytes(_k)          ((_k)->u64s * sizeof(__u64))
242
243 #define __BKEY_PADDED(key, pad)                                 \
244         struct { struct bkey_i key; __u64 key ## _pad[pad]; }
245
246 #define BKEY_VAL_TYPE(name, nr)                                         \
247 struct bkey_i_##name {                                                  \
248         union {                                                         \
249                 struct bkey             k;                              \
250                 struct bkey_i           k_i;                            \
251         };                                                              \
252         struct bch_##name               v;                              \
253 }
254
255 /*
256  * - DELETED keys are used internally to mark keys that should be ignored but
257  *   override keys in composition order.  Their version number is ignored.
258  *
259  * - DISCARDED keys indicate that the data is all 0s because it has been
260  *   discarded. DISCARDs may have a version; if the version is nonzero the key
261  *   will be persistent, otherwise the key will be dropped whenever the btree
262  *   node is rewritten (like DELETED keys).
263  *
264  * - ERROR: any read of the data returns a read error, as the data was lost due
265  *   to a failing device. Like DISCARDED keys, they can be removed (overridden)
266  *   by new writes or cluster-wide GC. Node repair can also overwrite them with
267  *   the same or a more recent version number, but not with an older version
268  *   number.
269 */
270 #define KEY_TYPE_DELETED                0
271 #define KEY_TYPE_DISCARD                1
272 #define KEY_TYPE_ERROR                  2
273 #define KEY_TYPE_COOKIE                 3
274 #define KEY_TYPE_PERSISTENT_DISCARD     4
275 #define KEY_TYPE_GENERIC_NR             128
276
277 struct bch_cookie {
278         struct bch_val          v;
279         __le64                  cookie;
280 };
281 BKEY_VAL_TYPE(cookie,           KEY_TYPE_COOKIE);
282
283 /* Extents */
284
285 /*
286  * In extent bkeys, the value is a list of pointers (bch_extent_ptr), optionally
287  * preceded by checksum/compression information (bch_extent_crc32 or
288  * bch_extent_crc64).
289  *
290  * One major determining factor in the format of extents is how we handle and
291  * represent extents that have been partially overwritten and thus trimmed:
292  *
293  * If an extent is not checksummed or compressed, when the extent is trimmed we
294  * don't have to remember the extent we originally allocated and wrote: we can
295  * merely adjust ptr->offset to point to the start of the start of the data that
296  * is currently live. The size field in struct bkey records the current (live)
297  * size of the extent, and is also used to mean "size of region on disk that we
298  * point to" in this case.
299  *
300  * Thus an extent that is not checksummed or compressed will consist only of a
301  * list of bch_extent_ptrs, with none of the fields in
302  * bch_extent_crc32/bch_extent_crc64.
303  *
304  * When an extent is checksummed or compressed, it's not possible to read only
305  * the data that is currently live: we have to read the entire extent that was
306  * originally written, and then return only the part of the extent that is
307  * currently live.
308  *
309  * Thus, in addition to the current size of the extent in struct bkey, we need
310  * to store the size of the originally allocated space - this is the
311  * compressed_size and uncompressed_size fields in bch_extent_crc32/64. Also,
312  * when the extent is trimmed, instead of modifying the offset field of the
313  * pointer, we keep a second smaller offset field - "offset into the original
314  * extent of the currently live region".
315  *
316  * The other major determining factor is replication and data migration:
317  *
318  * Each pointer may have its own bch_extent_crc32/64. When doing a replicated
319  * write, we will initially write all the replicas in the same format, with the
320  * same checksum type and compression format - however, when copygc runs later (or
321  * tiering/cache promotion, anything that moves data), it is not in general
322  * going to rewrite all the pointers at once - one of the replicas may be in a
323  * bucket on one device that has very little fragmentation while another lives
324  * in a bucket that has become heavily fragmented, and thus is being rewritten
325  * sooner than the rest.
326  *
327  * Thus it will only move a subset of the pointers (or in the case of
328  * tiering/cache promotion perhaps add a single pointer without dropping any
329  * current pointers), and if the extent has been partially overwritten it must
330  * write only the currently live portion (or copygc would not be able to reduce
331  * fragmentation!) - which necessitates a different bch_extent_crc format for
332  * the new pointer.
333  *
334  * But in the interests of space efficiency, we don't want to store one
335  * bch_extent_crc for each pointer if we don't have to.
336  *
337  * Thus, a bch_extent consists of bch_extent_crc32s, bch_extent_crc64s, and
338  * bch_extent_ptrs appended arbitrarily one after the other. We determine the
339  * type of a given entry with a scheme similar to utf8 (except we're encoding a
340  * type, not a size), encoding the type in the position of the first set bit:
341  *
342  * bch_extent_crc32     - 0b1
343  * bch_extent_ptr       - 0b10
344  * bch_extent_crc64     - 0b100
345  *
346  * We do it this way because bch_extent_crc32 is _very_ constrained on bits (and
347  * bch_extent_crc64 is the least constrained).
348  *
349  * Then, each bch_extent_crc32/64 applies to the pointers that follow after it,
350  * until the next bch_extent_crc32/64.
351  *
352  * If there are no bch_extent_crcs preceding a bch_extent_ptr, then that pointer
353  * is neither checksummed nor compressed.
354  */
355
356 /* 128 bits, sufficient for cryptographic MACs: */
357 struct bch_csum {
358         __le64                  lo;
359         __le64                  hi;
360 } __attribute__((packed, aligned(8)));
361
362 #define BCH_CSUM_NONE                   0U
363 #define BCH_CSUM_CRC32C                 1U
364 #define BCH_CSUM_CRC64                  2U
365 #define BCH_CSUM_CHACHA20_POLY1305_80   3U
366 #define BCH_CSUM_CHACHA20_POLY1305_128  4U
367 #define BCH_CSUM_NR                     5U
368
369 static inline _Bool bch2_csum_type_is_encryption(unsigned type)
370 {
371         switch (type) {
372         case BCH_CSUM_CHACHA20_POLY1305_80:
373         case BCH_CSUM_CHACHA20_POLY1305_128:
374                 return true;
375         default:
376                 return false;
377         }
378 }
379
380 enum bch_extent_entry_type {
381         BCH_EXTENT_ENTRY_ptr            = 0,
382         BCH_EXTENT_ENTRY_crc32          = 1,
383         BCH_EXTENT_ENTRY_crc64          = 2,
384         BCH_EXTENT_ENTRY_crc128         = 3,
385 };
386
387 #define BCH_EXTENT_ENTRY_MAX            4
388
389 /* Compressed/uncompressed size are stored biased by 1: */
390 struct bch_extent_crc32 {
391 #if defined(__LITTLE_ENDIAN_BITFIELD)
392         __u32                   type:2,
393                                 _compressed_size:7,
394                                 _uncompressed_size:7,
395                                 offset:7,
396                                 _unused:1,
397                                 csum_type:4,
398                                 compression_type:4;
399         __u32                   csum;
400 #elif defined (__BIG_ENDIAN_BITFIELD)
401         __u32                   csum;
402         __u32                   compression_type:4,
403                                 csum_type:4,
404                                 _unused:1,
405                                 offset:7,
406                                 _uncompressed_size:7,
407                                 _compressed_size:7,
408                                 type:2;
409 #endif
410 } __attribute__((packed, aligned(8)));
411
412 #define CRC32_SIZE_MAX          (1U << 7)
413 #define CRC32_NONCE_MAX         0
414
415 struct bch_extent_crc64 {
416 #if defined(__LITTLE_ENDIAN_BITFIELD)
417         __u64                   type:3,
418                                 _compressed_size:9,
419                                 _uncompressed_size:9,
420                                 offset:9,
421                                 nonce:10,
422                                 csum_type:4,
423                                 compression_type:4,
424                                 csum_hi:16;
425 #elif defined (__BIG_ENDIAN_BITFIELD)
426         __u64                   csum_hi:16,
427                                 compression_type:4,
428                                 csum_type:4,
429                                 nonce:10,
430                                 offset:9,
431                                 _uncompressed_size:9,
432                                 _compressed_size:9,
433                                 type:3;
434 #endif
435         __u64                   csum_lo;
436 } __attribute__((packed, aligned(8)));
437
438 #define CRC64_SIZE_MAX          (1U << 9)
439 #define CRC64_NONCE_MAX         ((1U << 10) - 1)
440
441 struct bch_extent_crc128 {
442 #if defined(__LITTLE_ENDIAN_BITFIELD)
443         __u64                   type:4,
444                                 _compressed_size:13,
445                                 _uncompressed_size:13,
446                                 offset:13,
447                                 nonce:13,
448                                 csum_type:4,
449                                 compression_type:4;
450 #elif defined (__BIG_ENDIAN_BITFIELD)
451         __u64                   compression_type:4,
452                                 csum_type:4,
453                                 nonce:14,
454                                 offset:13,
455                                 _uncompressed_size:13,
456                                 _compressed_size:13,
457                                 type:3;
458 #endif
459         struct bch_csum         csum;
460 } __attribute__((packed, aligned(8)));
461
462 #define CRC128_SIZE_MAX         (1U << 13)
463 #define CRC128_NONCE_MAX        ((1U << 13) - 1)
464
465 /*
466  * Max size of an extent that may require bouncing to read or write
467  * (checksummed, compressed): 64k
468  */
469 #define BCH_ENCODED_EXTENT_MAX  128U
470
471 /*
472  * @reservation - pointer hasn't been written to, just reserved
473  */
474 struct bch_extent_ptr {
475 #if defined(__LITTLE_ENDIAN_BITFIELD)
476         __u64                   type:1,
477                                 cached:1,
478                                 erasure_coded:1,
479                                 reservation:1,
480                                 offset:44, /* 8 petabytes */
481                                 dev:8,
482                                 gen:8;
483 #elif defined (__BIG_ENDIAN_BITFIELD)
484         __u64                   gen:8,
485                                 dev:8,
486                                 offset:44,
487                                 reservation:1,
488                                 erasure_coded:1,
489                                 cached:1,
490                                 type:1;
491 #endif
492 } __attribute__((packed, aligned(8)));
493
494 struct bch_extent_reservation {
495 #if defined(__LITTLE_ENDIAN_BITFIELD)
496         __u64                   type:5,
497                                 unused:23,
498                                 replicas:4,
499                                 generation:32;
500 #elif defined (__BIG_ENDIAN_BITFIELD)
501         __u64                   generation:32,
502                                 replicas:4,
503                                 unused:23,
504                                 type:5;
505 #endif
506 };
507
508 union bch_extent_entry {
509 #if defined(__LITTLE_ENDIAN) ||  __BITS_PER_LONG == 64
510         unsigned long                   type;
511 #elif __BITS_PER_LONG == 32
512         struct {
513                 unsigned long           pad;
514                 unsigned long           type;
515         };
516 #else
517 #error edit for your odd byteorder.
518 #endif
519         struct bch_extent_crc32         crc32;
520         struct bch_extent_crc64         crc64;
521         struct bch_extent_crc128        crc128;
522         struct bch_extent_ptr           ptr;
523 };
524
525 enum {
526         BCH_EXTENT              = 128,
527
528         /*
529          * This is kind of a hack, we're overloading the type for a boolean that
530          * really should be part of the value - BCH_EXTENT and BCH_EXTENT_CACHED
531          * have the same value type:
532          */
533         BCH_EXTENT_CACHED       = 129,
534
535         /*
536          * Persistent reservation:
537          */
538         BCH_RESERVATION         = 130,
539 };
540
541 struct bch_extent {
542         struct bch_val          v;
543
544         union bch_extent_entry  start[0];
545         __u64                   _data[0];
546 } __attribute__((packed, aligned(8)));
547 BKEY_VAL_TYPE(extent,           BCH_EXTENT);
548
549 struct bch_reservation {
550         struct bch_val          v;
551
552         __le32                  generation;
553         __u8                    nr_replicas;
554         __u8                    pad[3];
555 } __attribute__((packed, aligned(8)));
556 BKEY_VAL_TYPE(reservation,      BCH_RESERVATION);
557
558 /* Maximum size (in u64s) a single pointer could be: */
559 #define BKEY_EXTENT_PTR_U64s_MAX\
560         ((sizeof(struct bch_extent_crc128) +                    \
561           sizeof(struct bch_extent_ptr)) / sizeof(u64))
562
563 /* Maximum possible size of an entire extent value: */
564 /* There's a hack in the keylist code that needs to be fixed.. */
565 #define BKEY_EXTENT_VAL_U64s_MAX                                \
566         (BKEY_EXTENT_PTR_U64s_MAX * BCH_REPLICAS_MAX)
567
568 /* * Maximum possible size of an entire extent, key + value: */
569 #define BKEY_EXTENT_U64s_MAX            (BKEY_U64s + BKEY_EXTENT_VAL_U64s_MAX)
570
571 /* Btree pointers don't carry around checksums: */
572 #define BKEY_BTREE_PTR_VAL_U64s_MAX                             \
573         ((sizeof(struct bch_extent_ptr)) / sizeof(u64) * BCH_REPLICAS_MAX)
574 #define BKEY_BTREE_PTR_U64s_MAX                                 \
575         (BKEY_U64s + BKEY_BTREE_PTR_VAL_U64s_MAX)
576
577 /* Inodes */
578
579 #define BLOCKDEV_INODE_MAX      4096
580
581 #define BCACHE_ROOT_INO         4096
582
583 enum bch_inode_types {
584         BCH_INODE_FS            = 128,
585         BCH_INODE_BLOCKDEV      = 129,
586 };
587
588 struct bch_inode {
589         struct bch_val          v;
590
591         __le64                  i_hash_seed;
592         __le32                  i_flags;
593         __le16                  i_mode;
594         __u8                    fields[0];
595 } __attribute__((packed, aligned(8)));
596 BKEY_VAL_TYPE(inode,            BCH_INODE_FS);
597
598 #define BCH_INODE_FIELDS()                              \
599         BCH_INODE_FIELD(i_atime,        64)             \
600         BCH_INODE_FIELD(i_ctime,        64)             \
601         BCH_INODE_FIELD(i_mtime,        64)             \
602         BCH_INODE_FIELD(i_otime,        64)             \
603         BCH_INODE_FIELD(i_size,         64)             \
604         BCH_INODE_FIELD(i_sectors,      64)             \
605         BCH_INODE_FIELD(i_uid,          32)             \
606         BCH_INODE_FIELD(i_gid,          32)             \
607         BCH_INODE_FIELD(i_nlink,        32)             \
608         BCH_INODE_FIELD(i_generation,   32)             \
609         BCH_INODE_FIELD(i_dev,          32)
610
611 enum {
612         /*
613          * User flags (get/settable with FS_IOC_*FLAGS, correspond to FS_*_FL
614          * flags)
615          */
616         __BCH_INODE_SYNC        = 0,
617         __BCH_INODE_IMMUTABLE   = 1,
618         __BCH_INODE_APPEND      = 2,
619         __BCH_INODE_NODUMP      = 3,
620         __BCH_INODE_NOATIME     = 4,
621
622         __BCH_INODE_I_SIZE_DIRTY= 5,
623         __BCH_INODE_I_SECTORS_DIRTY= 6,
624
625         /* not implemented yet: */
626         __BCH_INODE_HAS_XATTRS  = 7, /* has xattrs in xattr btree */
627
628         /* bits 20+ reserved for packed fields below: */
629 };
630
631 #define BCH_INODE_SYNC          (1 << __BCH_INODE_SYNC)
632 #define BCH_INODE_IMMUTABLE     (1 << __BCH_INODE_IMMUTABLE)
633 #define BCH_INODE_APPEND        (1 << __BCH_INODE_APPEND)
634 #define BCH_INODE_NODUMP        (1 << __BCH_INODE_NODUMP)
635 #define BCH_INODE_NOATIME       (1 << __BCH_INODE_NOATIME)
636 #define BCH_INODE_I_SIZE_DIRTY  (1 << __BCH_INODE_I_SIZE_DIRTY)
637 #define BCH_INODE_I_SECTORS_DIRTY (1 << __BCH_INODE_I_SECTORS_DIRTY)
638 #define BCH_INODE_HAS_XATTRS    (1 << __BCH_INODE_HAS_XATTRS)
639
640 LE32_BITMASK(INODE_STR_HASH,    struct bch_inode, i_flags, 20, 24);
641 LE32_BITMASK(INODE_NR_FIELDS,   struct bch_inode, i_flags, 24, 32);
642
643 struct bch_inode_blockdev {
644         struct bch_val          v;
645
646         __le64                  i_size;
647         __le64                  i_flags;
648
649         /* Seconds: */
650         __le64                  i_ctime;
651         __le64                  i_mtime;
652
653         uuid_le                 i_uuid;
654         __u8                    i_label[32];
655 } __attribute__((packed, aligned(8)));
656 BKEY_VAL_TYPE(inode_blockdev,   BCH_INODE_BLOCKDEV);
657
658 /* Thin provisioned volume, or cache for another block device? */
659 LE64_BITMASK(CACHED_DEV,        struct bch_inode_blockdev, i_flags, 0,  1)
660
661 /* Dirents */
662
663 /*
664  * Dirents (and xattrs) have to implement string lookups; since our b-tree
665  * doesn't support arbitrary length strings for the key, we instead index by a
666  * 64 bit hash (currently truncated sha1) of the string, stored in the offset
667  * field of the key - using linear probing to resolve hash collisions. This also
668  * provides us with the readdir cookie posix requires.
669  *
670  * Linear probing requires us to use whiteouts for deletions, in the event of a
671  * collision:
672  */
673
674 enum {
675         BCH_DIRENT              = 128,
676         BCH_DIRENT_WHITEOUT     = 129,
677 };
678
679 struct bch_dirent {
680         struct bch_val          v;
681
682         /* Target inode number: */
683         __le64                  d_inum;
684
685         /*
686          * Copy of mode bits 12-15 from the target inode - so userspace can get
687          * the filetype without having to do a stat()
688          */
689         __u8                    d_type;
690
691         __u8                    d_name[];
692 } __attribute__((packed, aligned(8)));
693 BKEY_VAL_TYPE(dirent,           BCH_DIRENT);
694
695 /* Xattrs */
696
697 enum {
698         BCH_XATTR               = 128,
699         BCH_XATTR_WHITEOUT      = 129,
700 };
701
702 #define BCH_XATTR_INDEX_USER                    0
703 #define BCH_XATTR_INDEX_POSIX_ACL_ACCESS        1
704 #define BCH_XATTR_INDEX_POSIX_ACL_DEFAULT       2
705 #define BCH_XATTR_INDEX_TRUSTED                 3
706 #define BCH_XATTR_INDEX_SECURITY                4
707
708 struct bch_xattr {
709         struct bch_val          v;
710         __u8                    x_type;
711         __u8                    x_name_len;
712         __le16                  x_val_len;
713         __u8                    x_name[];
714 } __attribute__((packed, aligned(8)));
715 BKEY_VAL_TYPE(xattr,            BCH_XATTR);
716
717 /* Bucket/allocation information: */
718
719 enum {
720         BCH_ALLOC               = 128,
721 };
722
723 enum {
724         BCH_ALLOC_FIELD_READ_TIME       = 0,
725         BCH_ALLOC_FIELD_WRITE_TIME      = 1,
726 };
727
728 struct bch_alloc {
729         struct bch_val          v;
730         __u8                    fields;
731         __u8                    gen;
732         __u8                    data[];
733 } __attribute__((packed, aligned(8)));
734 BKEY_VAL_TYPE(alloc,    BCH_ALLOC);
735
736 /* Superblock */
737
738 /* Version 0: Cache device
739  * Version 1: Backing device
740  * Version 2: Seed pointer into btree node checksum
741  * Version 3: Cache device with new UUID format
742  * Version 4: Backing device with data offset
743  * Version 5: All the incompat changes
744  * Version 6: Cache device UUIDs all in superblock, another incompat bset change
745  * Version 7: Encryption (expanded checksum fields), other random things
746  */
747 #define BCACHE_SB_VERSION_CDEV_V0       0
748 #define BCACHE_SB_VERSION_BDEV          1
749 #define BCACHE_SB_VERSION_CDEV_WITH_UUID 3
750 #define BCACHE_SB_VERSION_BDEV_WITH_OFFSET 4
751 #define BCACHE_SB_VERSION_CDEV_V2       5
752 #define BCACHE_SB_VERSION_CDEV_V3       6
753 #define BCACHE_SB_VERSION_CDEV_V4       7
754 #define BCACHE_SB_VERSION_CDEV          7
755 #define BCACHE_SB_MAX_VERSION           7
756
757 #define BCH_SB_SECTOR                   8
758 #define BCH_SB_LABEL_SIZE               32
759 #define BCH_SB_MEMBERS_MAX              64 /* XXX kill */
760
761 struct bch_member {
762         uuid_le                 uuid;
763         __le64                  nbuckets;       /* device size */
764         __le16                  first_bucket;   /* index of first bucket used */
765         __le16                  bucket_size;    /* sectors */
766         __le32                  pad;
767         __le64                  last_mount;     /* time_t */
768
769         __le64                  flags[2];
770 };
771
772 LE64_BITMASK(BCH_MEMBER_STATE,          struct bch_member, flags[0],  0,  4)
773 LE64_BITMASK(BCH_MEMBER_TIER,           struct bch_member, flags[0],  4,  8)
774 /* 8-10 unused, was HAS_(META)DATA */
775 LE64_BITMASK(BCH_MEMBER_REPLACEMENT,    struct bch_member, flags[0], 10, 14)
776 LE64_BITMASK(BCH_MEMBER_DISCARD,        struct bch_member, flags[0], 14, 15);
777
778 #if 0
779 LE64_BITMASK(BCH_MEMBER_NR_READ_ERRORS, struct bch_member, flags[1], 0,  20);
780 LE64_BITMASK(BCH_MEMBER_NR_WRITE_ERRORS,struct bch_member, flags[1], 20, 40);
781 #endif
782
783 enum bch_member_state {
784         BCH_MEMBER_STATE_RW             = 0,
785         BCH_MEMBER_STATE_RO             = 1,
786         BCH_MEMBER_STATE_FAILED         = 2,
787         BCH_MEMBER_STATE_SPARE          = 3,
788         BCH_MEMBER_STATE_NR             = 4,
789 };
790
791 #define BCH_TIER_MAX                    4U
792
793 enum cache_replacement {
794         CACHE_REPLACEMENT_LRU           = 0,
795         CACHE_REPLACEMENT_FIFO          = 1,
796         CACHE_REPLACEMENT_RANDOM        = 2,
797         CACHE_REPLACEMENT_NR            = 3,
798 };
799
800 struct bch_sb_layout {
801         uuid_le                 magic;  /* bcachefs superblock UUID */
802         __u8                    layout_type;
803         __u8                    sb_max_size_bits; /* base 2 of 512 byte sectors */
804         __u8                    nr_superblocks;
805         __u8                    pad[5];
806         __u64                   sb_offset[61];
807 } __attribute__((packed, aligned(8)));
808
809 #define BCH_SB_LAYOUT_SECTOR    7
810
811 struct bch_sb_field {
812         __u64                   _data[0];
813         __le32                  u64s;
814         __le32                  type;
815 };
816
817 enum bch_sb_field_type {
818         BCH_SB_FIELD_journal    = 0,
819         BCH_SB_FIELD_members    = 1,
820         BCH_SB_FIELD_crypt      = 2,
821         BCH_SB_FIELD_replicas   = 3,
822         BCH_SB_FIELD_NR         = 4,
823 };
824
825 struct bch_sb_field_journal {
826         struct bch_sb_field     field;
827         __le64                  buckets[0];
828 };
829
830 struct bch_sb_field_members {
831         struct bch_sb_field     field;
832         struct bch_member       members[0];
833 };
834
835 /* Crypto: */
836
837 struct nonce {
838         __le32                  d[4];
839 };
840
841 struct bch_key {
842         __le64                  key[4];
843 };
844
845 #define BCH_KEY_MAGIC                                   \
846         (((u64) 'b' <<  0)|((u64) 'c' <<  8)|           \
847          ((u64) 'h' << 16)|((u64) '*' << 24)|           \
848          ((u64) '*' << 32)|((u64) 'k' << 40)|           \
849          ((u64) 'e' << 48)|((u64) 'y' << 56))
850
851 struct bch_encrypted_key {
852         __le64                  magic;
853         struct bch_key          key;
854 };
855
856 /*
857  * If this field is present in the superblock, it stores an encryption key which
858  * is used encrypt all other data/metadata. The key will normally be encrypted
859  * with the key userspace provides, but if encryption has been turned off we'll
860  * just store the master key unencrypted in the superblock so we can access the
861  * previously encrypted data.
862  */
863 struct bch_sb_field_crypt {
864         struct bch_sb_field     field;
865
866         __le64                  flags;
867         __le64                  kdf_flags;
868         struct bch_encrypted_key key;
869 };
870
871 LE64_BITMASK(BCH_CRYPT_KDF_TYPE,        struct bch_sb_field_crypt, flags, 0, 4);
872
873 enum bch_kdf_types {
874         BCH_KDF_SCRYPT          = 0,
875         BCH_KDF_NR              = 1,
876 };
877
878 /* stored as base 2 log of scrypt params: */
879 LE64_BITMASK(BCH_KDF_SCRYPT_N,  struct bch_sb_field_crypt, kdf_flags,  0, 16);
880 LE64_BITMASK(BCH_KDF_SCRYPT_R,  struct bch_sb_field_crypt, kdf_flags, 16, 32);
881 LE64_BITMASK(BCH_KDF_SCRYPT_P,  struct bch_sb_field_crypt, kdf_flags, 32, 48);
882
883 enum bch_data_types {
884         BCH_DATA_NONE           = 0,
885         BCH_DATA_SB             = 1,
886         BCH_DATA_JOURNAL        = 2,
887         BCH_DATA_BTREE          = 3,
888         BCH_DATA_USER           = 4,
889         BCH_DATA_NR             = 5,
890 };
891
892 struct bch_replicas_entry {
893         u8                      data_type;
894         u8                      nr;
895         u8                      devs[0];
896 };
897
898 struct bch_sb_field_replicas {
899         struct bch_sb_field     field;
900         struct bch_replicas_entry entries[0];
901 };
902
903 /*
904  * @offset      - sector where this sb was written
905  * @version     - on disk format version
906  * @magic       - identifies as a bcachefs superblock (BCACHE_MAGIC)
907  * @seq         - incremented each time superblock is written
908  * @uuid        - used for generating various magic numbers and identifying
909  *                member devices, never changes
910  * @user_uuid   - user visible UUID, may be changed
911  * @label       - filesystem label
912  * @seq         - identifies most recent superblock, incremented each time
913  *                superblock is written
914  * @features    - enabled incompatible features
915  */
916 struct bch_sb {
917         struct bch_csum         csum;
918         __le64                  version;
919         uuid_le                 magic;
920         uuid_le                 uuid;
921         uuid_le                 user_uuid;
922         __u8                    label[BCH_SB_LABEL_SIZE];
923         __le64                  offset;
924         __le64                  seq;
925
926         __le16                  block_size;
927         __u8                    dev_idx;
928         __u8                    nr_devices;
929         __le32                  u64s;
930
931         __le64                  time_base_lo;
932         __le32                  time_base_hi;
933         __le32                  time_precision;
934
935         __le64                  flags[8];
936         __le64                  features[2];
937         __le64                  compat[2];
938
939         struct bch_sb_layout    layout;
940
941         union {
942                 struct bch_sb_field start[0];
943                 __le64          _data[0];
944         };
945 } __attribute__((packed, aligned(8)));
946
947 /*
948  * Flags:
949  * BCH_SB_INITALIZED    - set on first mount
950  * BCH_SB_CLEAN         - did we shut down cleanly? Just a hint, doesn't affect
951  *                        behaviour of mount/recovery path:
952  * BCH_SB_INODE_32BIT   - limit inode numbers to 32 bits
953  * BCH_SB_128_BIT_MACS  - 128 bit macs instead of 80
954  * BCH_SB_ENCRYPTION_TYPE - if nonzero encryption is enabled; overrides
955  *                         DATA/META_CSUM_TYPE. Also indicates encryption
956  *                         algorithm in use, if/when we get more than one
957  */
958
959 LE64_BITMASK(BCH_SB_INITIALIZED,        struct bch_sb, flags[0],  0,  1);
960 LE64_BITMASK(BCH_SB_CLEAN,              struct bch_sb, flags[0],  1,  2);
961 LE64_BITMASK(BCH_SB_CSUM_TYPE,          struct bch_sb, flags[0],  2,  8);
962 LE64_BITMASK(BCH_SB_ERROR_ACTION,       struct bch_sb, flags[0],  8, 12);
963
964 LE64_BITMASK(BCH_SB_BTREE_NODE_SIZE,    struct bch_sb, flags[0], 12, 28);
965
966 LE64_BITMASK(BCH_SB_GC_RESERVE,         struct bch_sb, flags[0], 28, 33);
967 LE64_BITMASK(BCH_SB_ROOT_RESERVE,       struct bch_sb, flags[0], 33, 40);
968
969 LE64_BITMASK(BCH_SB_META_CSUM_TYPE,     struct bch_sb, flags[0], 40, 44);
970 LE64_BITMASK(BCH_SB_DATA_CSUM_TYPE,     struct bch_sb, flags[0], 44, 48);
971
972 LE64_BITMASK(BCH_SB_META_REPLICAS_WANT, struct bch_sb, flags[0], 48, 52);
973 LE64_BITMASK(BCH_SB_DATA_REPLICAS_WANT, struct bch_sb, flags[0], 52, 56);
974
975 /* 56-64 unused, was REPLICAS_HAVE */
976
977 LE64_BITMASK(BCH_SB_STR_HASH_TYPE,      struct bch_sb, flags[1],  0,  4);
978 LE64_BITMASK(BCH_SB_COMPRESSION_TYPE,   struct bch_sb, flags[1],  4,  8);
979 LE64_BITMASK(BCH_SB_INODE_32BIT,        struct bch_sb, flags[1],  8,  9);
980
981 LE64_BITMASK(BCH_SB_128_BIT_MACS,       struct bch_sb, flags[1],  9, 10);
982 LE64_BITMASK(BCH_SB_ENCRYPTION_TYPE,    struct bch_sb, flags[1], 10, 14);
983
984 /* 14-20 unused, was JOURNAL_ENTRY_SIZE */
985
986 LE64_BITMASK(BCH_SB_META_REPLICAS_REQ,  struct bch_sb, flags[1], 20, 24);
987 LE64_BITMASK(BCH_SB_DATA_REPLICAS_REQ,  struct bch_sb, flags[1], 24, 28);
988
989 /* Features: */
990 enum bch_sb_features {
991         BCH_FEATURE_LZ4                 = 0,
992         BCH_FEATURE_GZIP                = 1,
993 };
994
995 /* options: */
996
997 #define BCH_REPLICAS_MAX                4U
998
999 #if 0
1000 #define BCH_ERROR_ACTIONS()                                     \
1001         x(BCH_ON_ERROR_CONTINUE,        0, "continue")          \
1002         x(BCH_ON_ERROR_RO,              1, "remount-ro")        \
1003         x(BCH_ON_ERROR_PANIC,           2, "panic")             \
1004         x(BCH_NR_ERROR_ACTIONS,         3, NULL)
1005
1006 enum bch_error_actions {
1007 #define x(_opt, _nr, _str)      _opt = _nr,
1008         BCH_ERROR_ACTIONS()
1009 #undef x
1010 };
1011 #endif
1012
1013 enum bch_error_actions {
1014         BCH_ON_ERROR_CONTINUE           = 0,
1015         BCH_ON_ERROR_RO                 = 1,
1016         BCH_ON_ERROR_PANIC              = 2,
1017         BCH_NR_ERROR_ACTIONS            = 3,
1018 };
1019
1020 enum bch_csum_opts {
1021         BCH_CSUM_OPT_NONE               = 0,
1022         BCH_CSUM_OPT_CRC32C             = 1,
1023         BCH_CSUM_OPT_CRC64              = 2,
1024         BCH_CSUM_OPT_NR                 = 3,
1025 };
1026
1027 enum bch_str_hash_opts {
1028         BCH_STR_HASH_CRC32C             = 0,
1029         BCH_STR_HASH_CRC64              = 1,
1030         BCH_STR_HASH_SIPHASH            = 2,
1031         BCH_STR_HASH_NR                 = 3,
1032 };
1033
1034 enum bch_compression_opts {
1035         BCH_COMPRESSION_NONE            = 0,
1036         BCH_COMPRESSION_LZ4             = 1,
1037         BCH_COMPRESSION_GZIP            = 2,
1038         BCH_COMPRESSION_NR              = 3,
1039 };
1040
1041 /*
1042  * Magic numbers
1043  *
1044  * The various other data structures have their own magic numbers, which are
1045  * xored with the first part of the cache set's UUID
1046  */
1047
1048 #define BCACHE_MAGIC                                                    \
1049         UUID_LE(0xf67385c6, 0x1a4e, 0xca45,                             \
1050                 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81)
1051
1052 #define BCACHE_STATFS_MAGIC             0xca451a4e
1053
1054 #define JSET_MAGIC              __cpu_to_le64(0x245235c1a3625032ULL)
1055 #define BSET_MAGIC              __cpu_to_le64(0x90135c78b99e07f5ULL)
1056
1057 static inline __le64 __bch2_sb_magic(struct bch_sb *sb)
1058 {
1059         __le64 ret;
1060         memcpy(&ret, &sb->uuid, sizeof(ret));
1061         return ret;
1062 }
1063
1064 static inline __u64 __jset_magic(struct bch_sb *sb)
1065 {
1066         return __le64_to_cpu(__bch2_sb_magic(sb) ^ JSET_MAGIC);
1067 }
1068
1069 static inline __u64 __bset_magic(struct bch_sb *sb)
1070 {
1071         return __le64_to_cpu(__bch2_sb_magic(sb) ^ BSET_MAGIC);
1072 }
1073
1074 /* Journal */
1075
1076 #define BCACHE_JSET_VERSION_UUIDv1      1
1077 #define BCACHE_JSET_VERSION_UUID        1       /* Always latest UUID format */
1078 #define BCACHE_JSET_VERSION_JKEYS       2
1079 #define BCACHE_JSET_VERSION             2
1080
1081 struct jset_entry {
1082         __le16                  u64s;
1083         __u8                    btree_id;
1084         __u8                    level;
1085         __le32                  flags; /* designates what this jset holds */
1086
1087         union {
1088                 struct bkey_i   start[0];
1089                 __u64           _data[0];
1090         };
1091 };
1092
1093 #define JSET_KEYS_U64s  (sizeof(struct jset_entry) / sizeof(__u64))
1094
1095 LE32_BITMASK(JOURNAL_ENTRY_TYPE,        struct jset_entry, flags, 0, 8);
1096 enum {
1097         JOURNAL_ENTRY_BTREE_KEYS                = 0,
1098         JOURNAL_ENTRY_BTREE_ROOT                = 1,
1099         JOURNAL_ENTRY_PRIO_PTRS                 = 2, /* Obsolete */
1100
1101         /*
1102          * Journal sequence numbers can be blacklisted: bsets record the max
1103          * sequence number of all the journal entries they contain updates for,
1104          * so that on recovery we can ignore those bsets that contain index
1105          * updates newer that what made it into the journal.
1106          *
1107          * This means that we can't reuse that journal_seq - we have to skip it,
1108          * and then record that we skipped it so that the next time we crash and
1109          * recover we don't think there was a missing journal entry.
1110          */
1111         JOURNAL_ENTRY_JOURNAL_SEQ_BLACKLISTED   = 3,
1112 };
1113
1114 /*
1115  * On disk format for a journal entry:
1116  * seq is monotonically increasing; every journal entry has its own unique
1117  * sequence number.
1118  *
1119  * last_seq is the oldest journal entry that still has keys the btree hasn't
1120  * flushed to disk yet.
1121  *
1122  * version is for on disk format changes.
1123  */
1124 struct jset {
1125         struct bch_csum         csum;
1126
1127         __le64                  magic;
1128         __le64                  seq;
1129         __le32                  version;
1130         __le32                  flags;
1131
1132         __le32                  u64s; /* size of d[] in u64s */
1133
1134         __u8                    encrypted_start[0];
1135
1136         __le16                  read_clock;
1137         __le16                  write_clock;
1138
1139         /* Sequence number of oldest dirty journal entry */
1140         __le64                  last_seq;
1141
1142
1143         union {
1144                 struct jset_entry start[0];
1145                 __u64           _data[0];
1146         };
1147 } __attribute__((packed, aligned(8)));
1148
1149 LE32_BITMASK(JSET_CSUM_TYPE,    struct jset, flags, 0, 4);
1150 LE32_BITMASK(JSET_BIG_ENDIAN,   struct jset, flags, 4, 5);
1151
1152 #define BCH_JOURNAL_BUCKETS_MIN         20
1153
1154 /* Btree: */
1155
1156 #define DEFINE_BCH_BTREE_IDS()                                  \
1157         DEF_BTREE_ID(EXTENTS,   0, "extents")                   \
1158         DEF_BTREE_ID(INODES,    1, "inodes")                    \
1159         DEF_BTREE_ID(DIRENTS,   2, "dirents")                   \
1160         DEF_BTREE_ID(XATTRS,    3, "xattrs")                    \
1161         DEF_BTREE_ID(ALLOC,     4, "alloc")
1162
1163 #define DEF_BTREE_ID(kwd, val, name) BTREE_ID_##kwd = val,
1164
1165 enum btree_id {
1166         DEFINE_BCH_BTREE_IDS()
1167         BTREE_ID_NR
1168 };
1169
1170 #undef DEF_BTREE_ID
1171
1172 #define BTREE_MAX_DEPTH         4U
1173
1174 /* Btree nodes */
1175
1176 /* Version 1: Seed pointer into btree node checksum
1177  */
1178 #define BCACHE_BSET_CSUM                1
1179 #define BCACHE_BSET_KEY_v1              2
1180 #define BCACHE_BSET_JOURNAL_SEQ         3
1181 #define BCACHE_BSET_VERSION             3
1182
1183 /*
1184  * Btree nodes
1185  *
1186  * On disk a btree node is a list/log of these; within each set the keys are
1187  * sorted
1188  */
1189 struct bset {
1190         __le64                  seq;
1191
1192         /*
1193          * Highest journal entry this bset contains keys for.
1194          * If on recovery we don't see that journal entry, this bset is ignored:
1195          * this allows us to preserve the order of all index updates after a
1196          * crash, since the journal records a total order of all index updates
1197          * and anything that didn't make it to the journal doesn't get used.
1198          */
1199         __le64                  journal_seq;
1200
1201         __le32                  flags;
1202         __le16                  version;
1203         __le16                  u64s; /* count of d[] in u64s */
1204
1205         union {
1206                 struct bkey_packed start[0];
1207                 __u64           _data[0];
1208         };
1209 } __attribute__((packed, aligned(8)));
1210
1211 LE32_BITMASK(BSET_CSUM_TYPE,    struct bset, flags, 0, 4);
1212
1213 LE32_BITMASK(BSET_BIG_ENDIAN,   struct bset, flags, 4, 5);
1214 LE32_BITMASK(BSET_SEPARATE_WHITEOUTS,
1215                                 struct bset, flags, 5, 6);
1216
1217 struct btree_node {
1218         struct bch_csum         csum;
1219         __le64                  magic;
1220
1221         /* this flags field is encrypted, unlike bset->flags: */
1222         __le64                  flags;
1223
1224         /* Closed interval: */
1225         struct bpos             min_key;
1226         struct bpos             max_key;
1227         struct bch_extent_ptr   ptr;
1228         struct bkey_format      format;
1229
1230         union {
1231         struct bset             keys;
1232         struct {
1233                 __u8            pad[22];
1234                 __le16          u64s;
1235                 __u64           _data[0];
1236
1237         };
1238         };
1239 } __attribute__((packed, aligned(8)));
1240
1241 LE64_BITMASK(BTREE_NODE_ID,     struct btree_node, flags, 0, 4);
1242 LE64_BITMASK(BTREE_NODE_LEVEL,  struct btree_node, flags, 4, 8);
1243
1244 struct btree_node_entry {
1245         struct bch_csum         csum;
1246
1247         union {
1248         struct bset             keys;
1249         struct {
1250                 __u8            pad[22];
1251                 __le16          u64s;
1252                 __u64           _data[0];
1253
1254         };
1255         };
1256 } __attribute__((packed, aligned(8)));
1257
1258 /* Obsolete: */
1259
1260 struct prio_set {
1261         struct bch_csum         csum;
1262
1263         __le64                  magic;
1264         __le32                  nonce[3];
1265         __le16                  version;
1266         __le16                  flags;
1267
1268         __u8                    encrypted_start[0];
1269
1270         __le64                  next_bucket;
1271
1272         struct bucket_disk {
1273                 __le16          prio[2];
1274                 __u8            gen;
1275         } __attribute__((packed)) data[];
1276 } __attribute__((packed, aligned(8)));
1277
1278 LE32_BITMASK(PSET_CSUM_TYPE,    struct prio_set, flags, 0, 4);
1279
1280 #define PSET_MAGIC              __cpu_to_le64(0x6750e15f87337f91ULL)
1281
1282 static inline __u64 __pset_magic(struct bch_sb *sb)
1283 {
1284         return __le64_to_cpu(__bch2_sb_magic(sb) ^ PSET_MAGIC);
1285 }
1286
1287 #endif /* _BCACHEFS_FORMAT_H */