Commit cbdf24ce authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Fix a btree iter bug when iter pos == POS_MAX

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent a00fd8c5
......@@ -36,7 +36,16 @@ static inline int __btree_iter_pos_cmp(struct btree_iter *iter,
return cmp;
if (bkey_deleted(k))
return -1;
if (iter->flags & BTREE_ITER_IS_EXTENTS)
/*
* Normally, for extents we want the first key strictly greater than
* the iterator position - with the exception that for interior nodes,
* we don't want to advance past the last key if the iterator position
* is POS_MAX:
*/
if (iter->flags & BTREE_ITER_IS_EXTENTS &&
(!interior_node ||
bkey_cmp_left_packed_byval(b, k, POS_MAX)))
return -1;
return 1;
}
......@@ -691,8 +700,7 @@ static inline bool btree_iter_pos_after_node(struct btree_iter *iter,
struct btree *b)
{
return __btree_iter_pos_cmp(iter, NULL,
bkey_to_packed(&b->key), true) < 0 &&
bkey_cmp(b->key.k.p, POS_MAX);
bkey_to_packed(&b->key), true) < 0;
}
static inline bool btree_iter_pos_in_node(struct btree_iter *iter,
......
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