xref: /linux/fs/bcachefs/btree_journal_iter.h (revision ab475966455ce285c2c9978a3e3bfe97d75ff8d4)
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		*b;
19 	struct btree_node_iter	node_iter;
20 	struct bkey		unpacked;
21 
22 	struct journal_iter	journal;
23 	struct bpos		pos;
24 	bool			at_end;
25 };
26 
27 struct bkey_i *bch2_journal_keys_peek_upto(struct bch_fs *, enum btree_id,
28 				unsigned, struct bpos, struct bpos, size_t *);
29 struct bkey_i *bch2_journal_keys_peek_slot(struct bch_fs *, enum btree_id,
30 					   unsigned, struct bpos);
31 
32 int bch2_journal_key_insert_take(struct bch_fs *, enum btree_id,
33 				 unsigned, struct bkey_i *);
34 int bch2_journal_key_insert(struct bch_fs *, enum btree_id,
35 			    unsigned, struct bkey_i *);
36 int bch2_journal_key_delete(struct bch_fs *, enum btree_id,
37 			    unsigned, struct bpos);
38 void bch2_journal_key_overwritten(struct bch_fs *, enum btree_id,
39 				  unsigned, struct bpos);
40 
41 void bch2_btree_and_journal_iter_advance(struct btree_and_journal_iter *);
42 struct bkey_s_c bch2_btree_and_journal_iter_peek(struct btree_and_journal_iter *);
43 
44 void bch2_btree_and_journal_iter_exit(struct btree_and_journal_iter *);
45 void __bch2_btree_and_journal_iter_init_node_iter(struct btree_and_journal_iter *,
46 				struct bch_fs *, struct btree *,
47 				struct btree_node_iter, struct bpos);
48 void bch2_btree_and_journal_iter_init_node_iter(struct btree_and_journal_iter *,
49 						struct bch_fs *,
50 						struct btree *);
51 
52 void bch2_journal_keys_free(struct journal_keys *);
53 void bch2_journal_entries_free(struct bch_fs *);
54 
55 int bch2_journal_keys_sort(struct bch_fs *);
56 
57 #endif /* _BCACHEFS_BTREE_JOURNAL_ITER_H */
58