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 /* Only info on bucket countns: */ 58 struct bch_dev_usage { 59 u64 buckets[BCH_DATA_NR]; 60 }; 61 62 struct bch_dev_usage_full { 63 struct bch_dev_usage_type { 64 u64 buckets; 65 u64 sectors; /* _compressed_ sectors: */ 66 /* 67 * XXX 68 * Why do we have this? Isn't it just buckets * bucket_size - 69 * sectors? 70 */ 71 u64 fragmented; 72 } d[BCH_DATA_NR]; 73 }; 74 75 struct bch_fs_usage_base { 76 u64 hidden; 77 u64 btree; 78 u64 data; 79 u64 cached; 80 u64 reserved; 81 u64 nr_inodes; 82 }; 83 84 struct bch_fs_usage_short { 85 u64 capacity; 86 u64 used; 87 u64 free; 88 u64 nr_inodes; 89 }; 90 91 /* 92 * A reservation for space on disk: 93 */ 94 struct disk_reservation { 95 u64 sectors; 96 u32 gen; 97 unsigned nr_replicas; 98 }; 99 100 #endif /* _BUCKETS_TYPES_H */ 101