bcachefs: Fix btree_trans_peek_key_cache() BTREE_ITER_all_snapshots
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 12 Dec 2024 07:26:15 +0000 (02:26 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:23 +0000 (01:36 -0500)
In BTREE_ITER_all_snapshots mode, we're required to only return keys
where the snapshot field matches the iterator position -
BTREE_ITER_filter_snapshots requires pulling keys into the key cache
from ancestor snapshots, so we have to check for that.

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

index 51ebce9d5b5c062009612c46e94393766f04ab6e..e370fa327769c032845f27a13916f28365b4440a 100644 (file)
@@ -2230,6 +2230,10 @@ struct bkey_s_c btree_trans_peek_key_cache(struct btree_iter *iter, struct bpos
 
        k = bch2_btree_path_peek_slot(trans->paths + iter->key_cache_path, &u);
        if (k.k && !bkey_err(k)) {
+               if ((iter->flags & BTREE_ITER_all_snapshots) &&
+                   !bpos_eq(pos, k.k->p))
+                       return bkey_s_c_null;
+
                iter->k = u;
                k.k = &iter->k;
        }