d1d7737fd9
Btree updates before we go RW work by inserting into the array of keys that journal replay will insert - but inserting into a flat array is O(n), meaning if btree_gc needs to update many alloc keys, we're O(n^2). Fortunately, the updates btree_gc does happens in sequential order, which means a gap buffer works nicely here - this patch implements a gap buffer for journal keys. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
64 lines
1.9 KiB
C
64 lines
1.9 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _BCACHEFS_RECOVERY_H
|
|
#define _BCACHEFS_RECOVERY_H
|
|
|
|
struct journal_iter {
|
|
struct list_head list;
|
|
enum btree_id btree_id;
|
|
unsigned level;
|
|
size_t idx;
|
|
struct journal_keys *keys;
|
|
};
|
|
|
|
/*
|
|
* Iterate over keys in the btree, with keys from the journal overlaid on top:
|
|
*/
|
|
|
|
struct btree_and_journal_iter {
|
|
struct btree *b;
|
|
struct btree_node_iter node_iter;
|
|
struct bkey unpacked;
|
|
|
|
struct journal_iter journal;
|
|
|
|
enum last_key_returned {
|
|
none,
|
|
btree,
|
|
journal,
|
|
} last;
|
|
};
|
|
|
|
size_t bch2_journal_key_search(struct journal_keys *, enum btree_id,
|
|
unsigned, struct bpos);
|
|
struct bkey_i *bch2_journal_keys_peek(struct bch_fs *, enum btree_id,
|
|
unsigned, struct bpos pos);
|
|
|
|
int bch2_journal_key_insert_take(struct bch_fs *, enum btree_id,
|
|
unsigned, struct bkey_i *);
|
|
int bch2_journal_key_insert(struct bch_fs *, enum btree_id,
|
|
unsigned, struct bkey_i *);
|
|
int bch2_journal_key_delete(struct bch_fs *, enum btree_id,
|
|
unsigned, struct bpos);
|
|
void bch2_journal_key_overwritten(struct bch_fs *, enum btree_id,
|
|
unsigned, struct bpos);
|
|
|
|
void bch2_btree_and_journal_iter_advance(struct btree_and_journal_iter *);
|
|
struct bkey_s_c bch2_btree_and_journal_iter_peek(struct btree_and_journal_iter *);
|
|
struct bkey_s_c bch2_btree_and_journal_iter_next(struct btree_and_journal_iter *);
|
|
|
|
void bch2_btree_and_journal_iter_exit(struct btree_and_journal_iter *);
|
|
void __bch2_btree_and_journal_iter_init_node_iter(struct btree_and_journal_iter *,
|
|
struct bch_fs *, struct btree *,
|
|
struct btree_node_iter, struct bpos);
|
|
void bch2_btree_and_journal_iter_init_node_iter(struct btree_and_journal_iter *,
|
|
struct bch_fs *,
|
|
struct btree *);
|
|
|
|
void bch2_journal_keys_free(struct journal_keys *);
|
|
void bch2_journal_entries_free(struct list_head *);
|
|
|
|
int bch2_fs_recovery(struct bch_fs *);
|
|
int bch2_fs_initialize(struct bch_fs *);
|
|
|
|
#endif /* _BCACHEFS_RECOVERY_H */
|