1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _BCACHEFS_BTREE_JOURNAL_ITER_H 3 #define _BCACHEFS_BTREE_JOURNAL_ITER_H 4 5 struct journal_iter { 6 struct list_head list; 7 enum btree_id btree_id; 8 unsigned level; 9 size_t idx; 10 struct journal_keys *keys; 11 }; 12 13 /* 14 * Iterate over keys in the btree, with keys from the journal overlaid on top: 15 */ 16 17 struct btree_and_journal_iter { 18 struct btree_trans *trans; 19 struct btree *b; 20 struct btree_node_iter node_iter; 21 struct bkey unpacked; 22 23 struct journal_iter journal; 24 struct bpos pos; 25 bool at_end; 26 bool prefetch; 27 }; 28 29 struct bkey_i *bch2_journal_keys_peek_upto(struct bch_fs *, enum btree_id, 30 unsigned, struct bpos, struct bpos, size_t *); 31 struct bkey_i *bch2_journal_keys_peek_slot(struct bch_fs *, enum btree_id, 32 unsigned, struct bpos); 33 34 int bch2_btree_and_journal_iter_prefetch(struct btree_trans *, struct btree_path *, 35 struct btree_and_journal_iter *); 36 37 int bch2_journal_key_insert_take(struct bch_fs *, enum btree_id, 38 unsigned, struct bkey_i *); 39 int bch2_journal_key_insert(struct bch_fs *, enum btree_id, 40 unsigned, struct bkey_i *); 41 int bch2_journal_key_delete(struct bch_fs *, enum btree_id, 42 unsigned, struct bpos); 43 bool bch2_key_deleted_in_journal(struct btree_trans *, enum btree_id, unsigned, struct bpos); 44 void bch2_journal_key_overwritten(struct bch_fs *, enum btree_id, unsigned, struct bpos); 45 46 void bch2_btree_and_journal_iter_advance(struct btree_and_journal_iter *); 47 struct bkey_s_c bch2_btree_and_journal_iter_peek(struct btree_and_journal_iter *); 48 49 void bch2_btree_and_journal_iter_exit(struct btree_and_journal_iter *); 50 void __bch2_btree_and_journal_iter_init_node_iter(struct btree_trans *, 51 struct btree_and_journal_iter *, struct btree *, 52 struct btree_node_iter, struct bpos); 53 void bch2_btree_and_journal_iter_init_node_iter(struct btree_trans *, 54 struct btree_and_journal_iter *, struct btree *); 55 56 void bch2_journal_keys_put(struct bch_fs *); 57 58 static inline void bch2_journal_keys_put_initial(struct bch_fs *c) 59 { 60 if (c->journal_keys.initial_ref_held) 61 bch2_journal_keys_put(c); 62 c->journal_keys.initial_ref_held = false; 63 } 64 65 void bch2_journal_entries_free(struct bch_fs *); 66 67 int bch2_journal_keys_sort(struct bch_fs *); 68 69 void bch2_shoot_down_journal_keys(struct bch_fs *, enum btree_id, 70 unsigned, unsigned, 71 struct bpos, struct bpos); 72 73 #endif /* _BCACHEFS_BTREE_JOURNAL_ITER_H */ 74