2023-08-05 20:08:44 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef _BCACHEFS_BTREE_JOURNAL_ITER_H
|
|
|
|
#define _BCACHEFS_BTREE_JOURNAL_ITER_H
|
|
|
|
|
2024-06-04 22:31:13 +00:00
|
|
|
#include "bkey.h"
|
|
|
|
|
2023-08-05 20:08:44 +00:00
|
|
|
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 {
|
2024-01-22 19:37:42 +00:00
|
|
|
struct btree_trans *trans;
|
2023-08-05 20:08:44 +00:00
|
|
|
struct btree *b;
|
|
|
|
struct btree_node_iter node_iter;
|
|
|
|
struct bkey unpacked;
|
|
|
|
|
|
|
|
struct journal_iter journal;
|
|
|
|
struct bpos pos;
|
|
|
|
bool at_end;
|
2024-01-22 19:25:00 +00:00
|
|
|
bool prefetch;
|
2024-11-17 19:39:46 +00:00
|
|
|
bool fail_if_too_many_whiteouts;
|
2023-08-05 20:08:44 +00:00
|
|
|
};
|
|
|
|
|
2024-11-17 19:20:35 +00:00
|
|
|
static inline int __journal_key_btree_cmp(enum btree_id l_btree_id,
|
|
|
|
unsigned l_level,
|
|
|
|
const struct journal_key *r)
|
|
|
|
{
|
|
|
|
return -cmp_int(l_level, r->level) ?:
|
|
|
|
cmp_int(l_btree_id, r->btree_id);
|
|
|
|
}
|
|
|
|
|
2023-12-28 01:59:01 +00:00
|
|
|
static inline int __journal_key_cmp(enum btree_id l_btree_id,
|
|
|
|
unsigned l_level,
|
|
|
|
struct bpos l_pos,
|
|
|
|
const struct journal_key *r)
|
|
|
|
{
|
2024-11-17 19:20:35 +00:00
|
|
|
return __journal_key_btree_cmp(l_btree_id, l_level, r) ?:
|
|
|
|
bpos_cmp(l_pos, r->k->k.p);
|
2023-12-28 01:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int journal_key_cmp(const struct journal_key *l, const struct journal_key *r)
|
|
|
|
{
|
|
|
|
return __journal_key_cmp(l->btree_id, l->level, l->k->k.p, r);
|
|
|
|
}
|
|
|
|
|
2024-10-24 22:39:59 +00:00
|
|
|
struct bkey_i *bch2_journal_keys_peek_max(struct bch_fs *, enum btree_id,
|
2023-08-05 20:08:44 +00:00
|
|
|
unsigned, struct bpos, struct bpos, size_t *);
|
2024-10-25 02:12:37 +00:00
|
|
|
struct bkey_i *bch2_journal_keys_peek_prev_min(struct bch_fs *, enum btree_id,
|
|
|
|
unsigned, struct bpos, struct bpos, size_t *);
|
2023-08-05 20:08:44 +00:00
|
|
|
struct bkey_i *bch2_journal_keys_peek_slot(struct bch_fs *, enum btree_id,
|
|
|
|
unsigned, struct bpos);
|
|
|
|
|
2024-01-22 19:37:42 +00:00
|
|
|
int bch2_btree_and_journal_iter_prefetch(struct btree_trans *, struct btree_path *,
|
|
|
|
struct btree_and_journal_iter *);
|
|
|
|
|
2023-08-05 20:08:44 +00:00
|
|
|
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);
|
2024-03-26 21:14:43 +00:00
|
|
|
bool bch2_key_deleted_in_journal(struct btree_trans *, enum btree_id, unsigned, struct bpos);
|
|
|
|
void bch2_journal_key_overwritten(struct bch_fs *, enum btree_id, unsigned, struct bpos);
|
2023-08-05 20:08:44 +00:00
|
|
|
|
|
|
|
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 *);
|
|
|
|
|
|
|
|
void bch2_btree_and_journal_iter_exit(struct btree_and_journal_iter *);
|
2024-01-22 19:37:42 +00:00
|
|
|
void __bch2_btree_and_journal_iter_init_node_iter(struct btree_trans *,
|
|
|
|
struct btree_and_journal_iter *, struct btree *,
|
2023-08-05 20:08:44 +00:00
|
|
|
struct btree_node_iter, struct bpos);
|
2024-01-22 19:37:42 +00:00
|
|
|
void bch2_btree_and_journal_iter_init_node_iter(struct btree_trans *,
|
|
|
|
struct btree_and_journal_iter *, struct btree *);
|
2023-08-05 20:08:44 +00:00
|
|
|
|
2023-11-18 04:13:49 +00:00
|
|
|
void bch2_journal_keys_put(struct bch_fs *);
|
|
|
|
|
|
|
|
static inline void bch2_journal_keys_put_initial(struct bch_fs *c)
|
|
|
|
{
|
|
|
|
if (c->journal_keys.initial_ref_held)
|
|
|
|
bch2_journal_keys_put(c);
|
|
|
|
c->journal_keys.initial_ref_held = false;
|
|
|
|
}
|
|
|
|
|
2023-08-05 20:08:44 +00:00
|
|
|
int bch2_journal_keys_sort(struct bch_fs *);
|
|
|
|
|
2024-03-19 22:56:26 +00:00
|
|
|
void bch2_shoot_down_journal_keys(struct bch_fs *, enum btree_id,
|
|
|
|
unsigned, unsigned,
|
|
|
|
struct bpos, struct bpos);
|
|
|
|
|
2024-04-09 04:04:31 +00:00
|
|
|
void bch2_journal_keys_dump(struct bch_fs *);
|
|
|
|
|
2024-11-17 07:23:24 +00:00
|
|
|
void bch2_fs_journal_keys_init(struct bch_fs *);
|
|
|
|
|
2023-08-05 20:08:44 +00:00
|
|
|
#endif /* _BCACHEFS_BTREE_JOURNAL_ITER_H */
|