Commit 2ae4573e authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: bch2_btree_iter_peek_slot() now works on interior nodes

The new backpointers code will be using bch2_btree_iter_peek_slot() on
interior nodes - this patch updates peek_slot() to make that work.

 - Pass the correct level to bch2_journal_keys_peek_slot()
 - We should only set BTREE_ITER_CACHED or BTREE_ITER_WITH_KEY_CACHE
   when using bch2_trans_iter_init(), not bch2_trans_node_iter_init()
 - Update assertions
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 7419646b
...@@ -2226,7 +2226,8 @@ struct bkey_s_c btree_trans_peek_slot_journal(struct btree_trans *trans, ...@@ -2226,7 +2226,8 @@ struct bkey_s_c btree_trans_peek_slot_journal(struct btree_trans *trans,
struct btree_iter *iter) struct btree_iter *iter)
{ {
struct bkey_i *k = bch2_journal_keys_peek_slot(trans->c, iter->btree_id, struct bkey_i *k = bch2_journal_keys_peek_slot(trans->c, iter->btree_id,
0, iter->path->pos); iter->path->level,
iter->path->pos);
if (k) { if (k) {
iter->k = k->k; iter->k = k->k;
...@@ -2649,9 +2650,9 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter) ...@@ -2649,9 +2650,9 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter)
struct bkey_s_c k; struct bkey_s_c k;
int ret; int ret;
EBUG_ON(iter->path->level);
bch2_btree_iter_verify(iter); bch2_btree_iter_verify(iter);
bch2_btree_iter_verify_entry_exit(iter); bch2_btree_iter_verify_entry_exit(iter);
EBUG_ON(iter->path->level && (iter->flags & BTREE_ITER_WITH_KEY_CACHE));
/* extents can't span inode numbers: */ /* extents can't span inode numbers: */
if ((iter->flags & BTREE_ITER_IS_EXTENTS) && if ((iter->flags & BTREE_ITER_IS_EXTENTS) &&
...@@ -2696,6 +2697,8 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter) ...@@ -2696,6 +2697,8 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter)
} else { } else {
struct bpos next; struct bpos next;
EBUG_ON(iter->path->level);
if (iter->flags & BTREE_ITER_INTENT) { if (iter->flags & BTREE_ITER_INTENT) {
struct btree_iter iter2; struct btree_iter iter2;
struct bpos end = iter->pos; struct bpos end = iter->pos;
...@@ -2934,12 +2937,6 @@ static void __bch2_trans_iter_init(struct btree_trans *trans, ...@@ -2934,12 +2937,6 @@ static void __bch2_trans_iter_init(struct btree_trans *trans,
if (trans->journal_replay_not_finished) if (trans->journal_replay_not_finished)
flags |= BTREE_ITER_WITH_JOURNAL; flags |= BTREE_ITER_WITH_JOURNAL;
if (!btree_id_cached(trans->c, btree_id)) {
flags &= ~BTREE_ITER_CACHED;
flags &= ~BTREE_ITER_WITH_KEY_CACHE;
} else if (!(flags & BTREE_ITER_CACHED))
flags |= BTREE_ITER_WITH_KEY_CACHE;
iter->trans = trans; iter->trans = trans;
iter->path = NULL; iter->path = NULL;
iter->update_path = NULL; iter->update_path = NULL;
...@@ -2962,6 +2959,12 @@ void bch2_trans_iter_init(struct btree_trans *trans, ...@@ -2962,6 +2959,12 @@ void bch2_trans_iter_init(struct btree_trans *trans,
unsigned btree_id, struct bpos pos, unsigned btree_id, struct bpos pos,
unsigned flags) unsigned flags)
{ {
if (!btree_id_cached(trans->c, btree_id)) {
flags &= ~BTREE_ITER_CACHED;
flags &= ~BTREE_ITER_WITH_KEY_CACHE;
} else if (!(flags & BTREE_ITER_CACHED))
flags |= BTREE_ITER_WITH_KEY_CACHE;
__bch2_trans_iter_init(trans, iter, btree_id, pos, __bch2_trans_iter_init(trans, iter, btree_id, pos,
0, 0, flags); 0, 0, flags);
} }
......
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