]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcachefs/journal_io.h
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / libbcachefs / journal_io.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_JOURNAL_IO_H
3 #define _BCACHEFS_JOURNAL_IO_H
4
5 #include <linux/darray_types.h>
6
7 struct journal_ptr {
8         bool            csum_good;
9         u8              dev;
10         u32             bucket;
11         u32             bucket_offset;
12         u64             sector;
13 };
14
15 /*
16  * Only used for holding the journal entries we read in btree_journal_read()
17  * during cache_registration
18  */
19 struct journal_replay {
20         DARRAY_PREALLOCATED(struct journal_ptr, 8) ptrs;
21
22         bool                    csum_good;
23         bool                    ignore;
24         /* must be last: */
25         struct jset             j;
26 };
27
28 static inline struct jset_entry *__jset_entry_type_next(struct jset *jset,
29                                         struct jset_entry *entry, unsigned type)
30 {
31         while (entry < vstruct_last(jset)) {
32                 if (entry->type == type)
33                         return entry;
34
35                 entry = vstruct_next(entry);
36         }
37
38         return NULL;
39 }
40
41 #define for_each_jset_entry_type(entry, jset, type)                     \
42         for (entry = (jset)->start;                                     \
43              (entry = __jset_entry_type_next(jset, entry, type));       \
44              entry = vstruct_next(entry))
45
46 #define jset_entry_for_each_key(_e, _k)                                 \
47         for (_k = (_e)->start;                                          \
48              _k < vstruct_last(_e);                                     \
49              _k = bkey_next(_k))
50
51 #define for_each_jset_key(k, entry, jset)                               \
52         for_each_jset_entry_type(entry, jset, BCH_JSET_ENTRY_btree_keys)\
53                 jset_entry_for_each_key(entry, k)
54
55 int bch2_journal_entry_validate(struct bch_fs *, struct jset *,
56                                 struct jset_entry *, unsigned, int,
57                                 enum bkey_invalid_flags);
58 void bch2_journal_entry_to_text(struct printbuf *, struct bch_fs *,
59                                 struct jset_entry *);
60
61 void bch2_journal_ptrs_to_text(struct printbuf *, struct bch_fs *,
62                                struct journal_replay *);
63
64 int bch2_journal_read(struct bch_fs *, u64 *, u64 *, u64 *);
65
66 CLOSURE_CALLBACK(bch2_journal_write);
67
68 static inline struct jset_entry *jset_entry_init(struct jset_entry **end, size_t size)
69 {
70         struct jset_entry *entry = *end;
71         unsigned u64s = DIV_ROUND_UP(size, sizeof(u64));
72
73         memset(entry, 0, u64s * sizeof(u64));
74         /*
75          * The u64s field counts from the start of data, ignoring the shared
76          * fields.
77          */
78         entry->u64s = cpu_to_le16(u64s - 1);
79
80         *end = vstruct_next(*end);
81         return entry;
82 }
83
84 #endif /* _BCACHEFS_JOURNAL_IO_H */