Commit fc634d8e authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: btree_and_journal_iter.trans

we now always have a btree_trans when using a btree_and_journal_iter;
prep work for adding prefetching to btree_and_journal_iter
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 916abefd
...@@ -389,7 +389,7 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct ...@@ -389,7 +389,7 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct
have_child = dropped_children = false; have_child = dropped_children = false;
bch2_bkey_buf_init(&prev_k); bch2_bkey_buf_init(&prev_k);
bch2_bkey_buf_init(&cur_k); bch2_bkey_buf_init(&cur_k);
bch2_btree_and_journal_iter_init_node_iter(&iter, c, b); bch2_btree_and_journal_iter_init_node_iter(trans, &iter, b);
while ((k = bch2_btree_and_journal_iter_peek(&iter)).k) { while ((k = bch2_btree_and_journal_iter_peek(&iter)).k) {
BUG_ON(bpos_lt(k.k->p, b->data->min_key)); BUG_ON(bpos_lt(k.k->p, b->data->min_key));
...@@ -478,7 +478,7 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct ...@@ -478,7 +478,7 @@ static int bch2_btree_repair_topology_recurse(struct btree_trans *trans, struct
goto err; goto err;
bch2_btree_and_journal_iter_exit(&iter); bch2_btree_and_journal_iter_exit(&iter);
bch2_btree_and_journal_iter_init_node_iter(&iter, c, b); bch2_btree_and_journal_iter_init_node_iter(trans, &iter, b);
while ((k = bch2_btree_and_journal_iter_peek(&iter)).k) { while ((k = bch2_btree_and_journal_iter_peek(&iter)).k) {
bch2_bkey_buf_reassemble(&cur_k, c, k); bch2_bkey_buf_reassemble(&cur_k, c, k);
...@@ -931,7 +931,7 @@ static int bch2_gc_btree_init_recurse(struct btree_trans *trans, struct btree *b ...@@ -931,7 +931,7 @@ static int bch2_gc_btree_init_recurse(struct btree_trans *trans, struct btree *b
struct printbuf buf = PRINTBUF; struct printbuf buf = PRINTBUF;
int ret = 0; int ret = 0;
bch2_btree_and_journal_iter_init_node_iter(&iter, c, b); bch2_btree_and_journal_iter_init_node_iter(trans, &iter, b);
bch2_bkey_buf_init(&prev); bch2_bkey_buf_init(&prev);
bch2_bkey_buf_init(&cur); bch2_bkey_buf_init(&cur);
bkey_init(&prev.k->k); bkey_init(&prev.k->k);
...@@ -963,7 +963,7 @@ static int bch2_gc_btree_init_recurse(struct btree_trans *trans, struct btree *b ...@@ -963,7 +963,7 @@ static int bch2_gc_btree_init_recurse(struct btree_trans *trans, struct btree *b
if (b->c.level > target_depth) { if (b->c.level > target_depth) {
bch2_btree_and_journal_iter_exit(&iter); bch2_btree_and_journal_iter_exit(&iter);
bch2_btree_and_journal_iter_init_node_iter(&iter, c, b); bch2_btree_and_journal_iter_init_node_iter(trans, &iter, b);
while ((k = bch2_btree_and_journal_iter_peek(&iter)).k) { while ((k = bch2_btree_and_journal_iter_peek(&iter)).k) {
struct btree *child; struct btree *child;
......
...@@ -891,7 +891,7 @@ static noinline int btree_node_iter_and_journal_peek(struct btree_trans *trans, ...@@ -891,7 +891,7 @@ static noinline int btree_node_iter_and_journal_peek(struct btree_trans *trans,
struct bkey_s_c k; struct bkey_s_c k;
int ret = 0; int ret = 0;
__bch2_btree_and_journal_iter_init_node_iter(&jiter, c, l->b, l->iter, path->pos); __bch2_btree_and_journal_iter_init_node_iter(trans, &jiter, l->b, l->iter, path->pos);
k = bch2_btree_and_journal_iter_peek(&jiter); k = bch2_btree_and_journal_iter_peek(&jiter);
......
...@@ -376,17 +376,18 @@ void bch2_btree_and_journal_iter_exit(struct btree_and_journal_iter *iter) ...@@ -376,17 +376,18 @@ void bch2_btree_and_journal_iter_exit(struct btree_and_journal_iter *iter)
bch2_journal_iter_exit(&iter->journal); bch2_journal_iter_exit(&iter->journal);
} }
void __bch2_btree_and_journal_iter_init_node_iter(struct btree_and_journal_iter *iter, void __bch2_btree_and_journal_iter_init_node_iter(struct btree_trans *trans,
struct bch_fs *c, struct btree_and_journal_iter *iter,
struct btree *b, struct btree *b,
struct btree_node_iter node_iter, struct btree_node_iter node_iter,
struct bpos pos) struct bpos pos)
{ {
memset(iter, 0, sizeof(*iter)); memset(iter, 0, sizeof(*iter));
iter->trans = trans;
iter->b = b; iter->b = b;
iter->node_iter = node_iter; iter->node_iter = node_iter;
bch2_journal_iter_init(c, &iter->journal, b->c.btree_id, b->c.level, pos); bch2_journal_iter_init(trans->c, &iter->journal, b->c.btree_id, b->c.level, pos);
INIT_LIST_HEAD(&iter->journal.list); INIT_LIST_HEAD(&iter->journal.list);
iter->pos = b->data->min_key; iter->pos = b->data->min_key;
iter->at_end = false; iter->at_end = false;
...@@ -396,15 +397,15 @@ void __bch2_btree_and_journal_iter_init_node_iter(struct btree_and_journal_iter ...@@ -396,15 +397,15 @@ void __bch2_btree_and_journal_iter_init_node_iter(struct btree_and_journal_iter
* this version is used by btree_gc before filesystem has gone RW and * this version is used by btree_gc before filesystem has gone RW and
* multithreaded, so uses the journal_iters list: * multithreaded, so uses the journal_iters list:
*/ */
void bch2_btree_and_journal_iter_init_node_iter(struct btree_and_journal_iter *iter, void bch2_btree_and_journal_iter_init_node_iter(struct btree_trans *trans,
struct bch_fs *c, struct btree_and_journal_iter *iter,
struct btree *b) struct btree *b)
{ {
struct btree_node_iter node_iter; struct btree_node_iter node_iter;
bch2_btree_node_iter_init_from_start(&node_iter, b); bch2_btree_node_iter_init_from_start(&node_iter, b);
__bch2_btree_and_journal_iter_init_node_iter(iter, c, b, node_iter, b->data->min_key); __bch2_btree_and_journal_iter_init_node_iter(trans, iter, b, node_iter, b->data->min_key);
list_add(&iter->journal.list, &c->journal_iters); list_add(&iter->journal.list, &trans->c->journal_iters);
} }
/* sort and dedup all keys in the journal: */ /* sort and dedup all keys in the journal: */
......
...@@ -15,6 +15,7 @@ struct journal_iter { ...@@ -15,6 +15,7 @@ struct journal_iter {
*/ */
struct btree_and_journal_iter { struct btree_and_journal_iter {
struct btree_trans *trans;
struct btree *b; struct btree *b;
struct btree_node_iter node_iter; struct btree_node_iter node_iter;
struct bkey unpacked; struct bkey unpacked;
...@@ -29,6 +30,9 @@ struct bkey_i *bch2_journal_keys_peek_upto(struct bch_fs *, enum btree_id, ...@@ -29,6 +30,9 @@ struct bkey_i *bch2_journal_keys_peek_upto(struct bch_fs *, enum btree_id,
struct bkey_i *bch2_journal_keys_peek_slot(struct bch_fs *, enum btree_id, struct bkey_i *bch2_journal_keys_peek_slot(struct bch_fs *, enum btree_id,
unsigned, struct bpos); unsigned, struct bpos);
int bch2_btree_and_journal_iter_prefetch(struct btree_trans *, struct btree_path *,
struct btree_and_journal_iter *);
int bch2_journal_key_insert_take(struct bch_fs *, enum btree_id, int bch2_journal_key_insert_take(struct bch_fs *, enum btree_id,
unsigned, struct bkey_i *); unsigned, struct bkey_i *);
int bch2_journal_key_insert(struct bch_fs *, enum btree_id, int bch2_journal_key_insert(struct bch_fs *, enum btree_id,
...@@ -42,12 +46,11 @@ void bch2_btree_and_journal_iter_advance(struct btree_and_journal_iter *); ...@@ -42,12 +46,11 @@ 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_peek(struct btree_and_journal_iter *);
void bch2_btree_and_journal_iter_exit(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 *, void __bch2_btree_and_journal_iter_init_node_iter(struct btree_trans *,
struct bch_fs *, struct btree *, struct btree_and_journal_iter *, struct btree *,
struct btree_node_iter, struct bpos); struct btree_node_iter, struct bpos);
void bch2_btree_and_journal_iter_init_node_iter(struct btree_and_journal_iter *, void bch2_btree_and_journal_iter_init_node_iter(struct btree_trans *,
struct bch_fs *, struct btree_and_journal_iter *, struct btree *);
struct btree *);
void bch2_journal_keys_put(struct bch_fs *); void bch2_journal_keys_put(struct bch_fs *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment