]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/buckets_types.h
Update bcachefs sources to 4837f82ee1 bcachefs: Use cached iterators for alloc btree
[bcachefs-tools-debian] / libbcachefs / buckets_types.h
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 struct bucket_mark {
11         union {
12         atomic64_t      v;
13
14         struct {
15         u8              gen;
16         u8              data_type:3,
17                         owned_by_allocator:1,
18                         journal_seq_valid:1,
19                         stripe:1;
20         u16             dirty_sectors;
21         u16             cached_sectors;
22
23         /*
24          * low bits of journal sequence number when this bucket was most
25          * recently modified: if journal_seq_valid is set, this bucket can't be
26          * reused until the journal sequence number written to disk is >= the
27          * bucket's journal sequence number:
28          */
29         u16             journal_seq;
30         };
31         };
32 };
33
34 struct bucket {
35         union {
36                 struct bucket_mark      _mark;
37                 const struct bucket_mark mark;
38         };
39
40         u16                             io_time[2];
41         u8                              oldest_gen;
42         u8                              gc_gen;
43         unsigned                        gen_valid:1;
44 };
45
46 struct bucket_array {
47         struct rcu_head         rcu;
48         u16                     first_bucket;
49         size_t                  nbuckets;
50         struct bucket           b[];
51 };
52
53 struct bch_dev_usage {
54         u64                     buckets[BCH_DATA_NR];
55         u64                     buckets_alloc;
56         u64                     buckets_ec;
57         u64                     buckets_unavailable;
58
59         /* _compressed_ sectors: */
60         u64                     sectors[BCH_DATA_NR];
61         u64                     sectors_fragmented;
62 };
63
64 struct bch_fs_usage {
65         /* all fields are in units of 512 byte sectors: */
66
67         u64                     online_reserved;
68
69         /* fields after online_reserved are cleared/recalculated by gc: */
70         u64                     gc_start[0];
71
72         u64                     hidden;
73         u64                     btree;
74         u64                     data;
75         u64                     cached;
76         u64                     reserved;
77         u64                     nr_inodes;
78
79         /* XXX: add stats for compression ratio */
80 #if 0
81         u64                     uncompressed;
82         u64                     compressed;
83 #endif
84
85         /* broken out: */
86
87         u64                     persistent_reserved[BCH_REPLICAS_MAX];
88         u64                     replicas[];
89 };
90
91 struct bch_fs_usage_short {
92         u64                     capacity;
93         u64                     used;
94         u64                     free;
95         u64                     nr_inodes;
96 };
97
98 struct replicas_delta {
99         s64                     delta;
100         struct bch_replicas_entry r;
101 } __packed;
102
103 struct replicas_delta_list {
104         unsigned                size;
105         unsigned                used;
106
107         struct                  {} memset_start;
108         u64                     nr_inodes;
109         u64                     persistent_reserved[BCH_REPLICAS_MAX];
110         struct                  {} memset_end;
111         struct replicas_delta   d[0];
112 };
113
114 /*
115  * A reservation for space on disk:
116  */
117 struct disk_reservation {
118         u64                     sectors;
119         u32                     gen;
120         unsigned                nr_replicas;
121 };
122
123 struct copygc_heap_entry {
124         u8                      gen;
125         u32                     sectors;
126         u64                     offset;
127 };
128
129 typedef HEAP(struct copygc_heap_entry) copygc_heap;
130
131 #endif /* _BUCKETS_TYPES_H */