bcachefs: Fix btree_iter_peek_prev() at end of inode
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 22 Apr 2025 08:54:54 +0000 (04:54 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 24 Apr 2025 23:09:52 +0000 (19:09 -0400)
At the end of the inode, on an extents iterator, peek_slot() has to
advance to the next position to avoid returning a 0 size extent, which
is not allowed.

Changing iter->pos confuses peek_prev(), but we don't need to call
peek_slot() in this case.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c

index 400ff650553b4dff0f81496223dcb26cea26c3af..59fa527ac68548e2841a81f333ee20c475198d73 100644 (file)
@@ -2577,7 +2577,10 @@ struct bkey_s_c bch2_btree_iter_peek_prev_min(struct btree_trans *trans, struct
                                              struct bpos end)
 {
        if ((iter->flags & (BTREE_ITER_is_extents|BTREE_ITER_filter_snapshots)) &&
-          !bkey_eq(iter->pos, POS_MAX)) {
+          !bkey_eq(iter->pos, POS_MAX) &&
+          !((iter->flags & BTREE_ITER_is_extents) &&
+            iter->pos.offset == U64_MAX)) {
+
                /*
                 * bkey_start_pos(), for extents, is not monotonically
                 * increasing until after filtering for snapshots: