Commit f42238b5 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Fix a rare path in bch2_btree_path_peek_slot()

In the drop_alloc tests, we may end up calling
bch2_btree_iter_peek_slot() on an interior level that doesn't exist.
Previously, this would hit the path->uptodate assertion in
bch2_btree_path_peek_slot(); this path first checks a NULL btree node,
which is how we know we're at the end of the btree.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 7dcbdbd8
...@@ -1544,14 +1544,17 @@ struct btree_path *bch2_path_get(struct btree_trans *trans, ...@@ -1544,14 +1544,17 @@ struct btree_path *bch2_path_get(struct btree_trans *trans,
inline struct bkey_s_c bch2_btree_path_peek_slot(struct btree_path *path, struct bkey *u) inline struct bkey_s_c bch2_btree_path_peek_slot(struct btree_path *path, struct bkey *u)
{ {
struct btree_path_level *l = path_l(path);
struct bkey_packed *_k;
struct bkey_s_c k; struct bkey_s_c k;
if (!path->cached) { if (unlikely(!l->b))
struct btree_path_level *l = path_l(path); return bkey_s_c_null;
struct bkey_packed *_k;
EBUG_ON(path->uptodate != BTREE_ITER_UPTODATE); EBUG_ON(path->uptodate != BTREE_ITER_UPTODATE);
EBUG_ON(!btree_node_locked(path, path->level));
if (!path->cached) {
_k = bch2_btree_node_iter_peek_all(&l->iter, l->b); _k = bch2_btree_node_iter_peek_all(&l->iter, l->b);
k = _k ? bkey_disassemble(l->b, _k, u) : bkey_s_c_null; k = _k ? bkey_disassemble(l->b, _k, u) : bkey_s_c_null;
...@@ -1566,7 +1569,6 @@ inline struct bkey_s_c bch2_btree_path_peek_slot(struct btree_path *path, struct ...@@ -1566,7 +1569,6 @@ inline struct bkey_s_c bch2_btree_path_peek_slot(struct btree_path *path, struct
(path->btree_id != ck->key.btree_id || (path->btree_id != ck->key.btree_id ||
bkey_cmp(path->pos, ck->key.pos))); bkey_cmp(path->pos, ck->key.pos)));
EBUG_ON(!ck || !ck->valid); EBUG_ON(!ck || !ck->valid);
EBUG_ON(path->uptodate != BTREE_ITER_UPTODATE);
*u = ck->k->k; *u = ck->k->k;
k = bkey_i_to_s_c(ck->k); k = bkey_i_to_s_c(ck->k);
...@@ -2381,6 +2383,8 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter) ...@@ -2381,6 +2383,8 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter)
} }
k = bch2_btree_path_peek_slot(iter->path, &iter->k); k = bch2_btree_path_peek_slot(iter->path, &iter->k);
if (unlikely(!k.k))
goto out_no_locked;
} else { } else {
struct bpos next; struct bpos next;
...@@ -2412,7 +2416,7 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter) ...@@ -2412,7 +2416,7 @@ struct bkey_s_c bch2_btree_iter_peek_slot(struct btree_iter *iter)
} }
if (unlikely(bkey_err(k))) if (unlikely(bkey_err(k)))
return k; goto out_no_locked;
next = k.k ? bkey_start_pos(k.k) : POS_MAX; next = k.k ? bkey_start_pos(k.k) : POS_MAX;
......
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