1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHEFS_JOURNAL_IO_H
3 #define _BCACHEFS_JOURNAL_IO_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;
23 bool ignore_blacklisted;
24 bool ignore_not_dirty;
29 static inline bool journal_replay_ignore(struct journal_replay *i)
31 return !i || i->ignore_blacklisted || i->ignore_not_dirty;
34 static inline struct jset_entry *__jset_entry_type_next(struct jset *jset,
35 struct jset_entry *entry, unsigned type)
37 while (entry < vstruct_last(jset)) {
38 if (entry->type == type)
41 entry = vstruct_next(entry);
47 #define for_each_jset_entry_type(entry, jset, type) \
48 for (struct jset_entry *entry = (jset)->start; \
49 (entry = __jset_entry_type_next(jset, entry, type)); \
50 entry = vstruct_next(entry))
52 #define jset_entry_for_each_key(_e, _k) \
53 for (struct bkey_i *_k = (_e)->start; \
54 _k < vstruct_last(_e); \
57 #define for_each_jset_key(k, entry, jset) \
58 for_each_jset_entry_type(entry, jset, BCH_JSET_ENTRY_btree_keys)\
59 jset_entry_for_each_key(entry, k)
61 int bch2_journal_entry_validate(struct bch_fs *, struct jset *,
62 struct jset_entry *, unsigned, int,
63 enum bkey_invalid_flags);
64 void bch2_journal_entry_to_text(struct printbuf *, struct bch_fs *,
67 void bch2_journal_ptrs_to_text(struct printbuf *, struct bch_fs *,
68 struct journal_replay *);
70 int bch2_journal_read(struct bch_fs *, u64 *, u64 *, u64 *);
72 CLOSURE_CALLBACK(bch2_journal_write);
74 static inline struct jset_entry *jset_entry_init(struct jset_entry **end, size_t size)
76 struct jset_entry *entry = *end;
77 unsigned u64s = DIV_ROUND_UP(size, sizeof(u64));
79 memset(entry, 0, u64s * sizeof(u64));
81 * The u64s field counts from the start of data, ignoring the shared
84 entry->u64s = cpu_to_le16(u64s - 1);
86 *end = vstruct_next(*end);
90 #endif /* _BCACHEFS_JOURNAL_IO_H */