xref: /linux/fs/bcachefs/buckets_types.h (revision 4a4b30ea80d8cb5e8c4c62bb86201f4ea0d9b030)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BUCKETS_TYPES_H
3 #define _BUCKETS_TYPES_H
4 
5 #include "bcachefs_format.h"
6 #include "util.h"
7 
8 #define BUCKET_JOURNAL_SEQ_BITS		16
9 
10 /*
11  * Ugly hack alert:
12  *
13  * We need to cram a spinlock in a single byte, because that's what we have left
14  * in struct bucket, and we care about the size of these - during fsck, we need
15  * in memory state for every single bucket on every device.
16  *
17  * We used to do
18  *   while (xchg(&b->lock, 1) cpu_relax();
19  * but, it turns out not all architectures support xchg on a single byte.
20  *
21  * So now we use bit_spin_lock(), with fun games since we can't burn a whole
22  * ulong for this - we just need to make sure the lock bit always ends up in the
23  * first byte.
24  */
25 
26 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
27 #define BUCKET_LOCK_BITNR	0
28 #else
29 #define BUCKET_LOCK_BITNR	(BITS_PER_LONG - 1)
30 #endif
31 
32 union ulong_byte_assert {
33 	ulong	ulong;
34 	u8	byte;
35 };
36 
37 struct bucket {
38 	u8			lock;
39 	u8			gen_valid:1;
40 	u8			data_type:7;
41 	u8			gen;
42 	u8			stripe_redundancy;
43 	u32			stripe;
44 	u32			dirty_sectors;
45 	u32			cached_sectors;
46 	u32			stripe_sectors;
47 } __aligned(sizeof(long));
48 
49 struct bucket_gens {
50 	struct rcu_head		rcu;
51 	u16			first_bucket;
52 	size_t			nbuckets;
53 	size_t			nbuckets_minus_first;
54 	u8			b[] __counted_by(nbuckets);
55 };
56 
57 struct bch_dev_usage {
58 	struct bch_dev_usage_type {
59 		u64		buckets;
60 		u64		sectors; /* _compressed_ sectors: */
61 		/*
62 		 * XXX
63 		 * Why do we have this? Isn't it just buckets * bucket_size -
64 		 * sectors?
65 		 */
66 		u64		fragmented;
67 	}			d[BCH_DATA_NR];
68 };
69 
70 struct bch_fs_usage_base {
71 	u64			hidden;
72 	u64			btree;
73 	u64			data;
74 	u64			cached;
75 	u64			reserved;
76 	u64			nr_inodes;
77 };
78 
79 struct bch_fs_usage_short {
80 	u64			capacity;
81 	u64			used;
82 	u64			free;
83 	u64			nr_inodes;
84 };
85 
86 /*
87  * A reservation for space on disk:
88  */
89 struct disk_reservation {
90 	u64			sectors;
91 	u32			gen;
92 	unsigned		nr_replicas;
93 };
94 
95 #endif /* _BUCKETS_TYPES_H */
96