1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_JOURNAL_IO_H
3 #define _BCACHEFS_JOURNAL_IO_H
5 #include <linux/darray_types.h>
16 * Only used for holding the journal entries we read in btree_journal_read()
17 * during cache_registration
19 struct journal_replay {
20 DARRAY_PREALLOCATED(struct journal_ptr, 8) ptrs;
28 static inline struct jset_entry *__jset_entry_type_next(struct jset *jset,
29 struct jset_entry *entry, unsigned type)
31 while (entry < vstruct_last(jset)) {
32 if (entry->type == type)
35 entry = vstruct_next(entry);
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))
46 #define jset_entry_for_each_key(_e, _k) \
47 for (_k = (_e)->start; \
48 _k < vstruct_last(_e); \
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)
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 *,
61 void bch2_journal_ptrs_to_text(struct printbuf *, struct bch_fs *,
62 struct journal_replay *);
64 int bch2_journal_read(struct bch_fs *, u64 *, u64 *, u64 *);
66 CLOSURE_CALLBACK(bch2_journal_write);
68 static inline struct jset_entry *jset_entry_init(struct jset_entry **end, size_t size)
70 struct jset_entry *entry = *end;
71 unsigned u64s = DIV_ROUND_UP(size, sizeof(u64));
73 memset(entry, 0, u64s * sizeof(u64));
75 * The u64s field counts from the start of data, ignoring the shared
78 entry->u64s = cpu_to_le16(u64s - 1);
80 *end = vstruct_next(*end);
84 #endif /* _BCACHEFS_JOURNAL_IO_H */