]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bcachefs: Fix btree_trans_peek_key_cache()
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 21 Jan 2025 07:26:13 +0000 (02:26 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Tue, 21 Jan 2025 17:26:25 +0000 (12:26 -0500)
BTREE_ITER_cached_nofill has some tricky corner cases; it's used
internally for iterators that aren't walking the key cache, but need to
be coherent with the key cache.

It tells traverse to look up and lock the key cache entry if present,
but don't create one if it doesn't exist.

That means we have to have a BTREE_ITER_UPTODATE path (because after
traverse the path has to be UPTODATE, or we pop assertions) that doesn't
point to anything (which is the less bad option, taken by the previous
fix).

The previous fix for this path missed an issue that can happen in
bch2_trans_peek_key_cache(): we can't set should_be_locked on a path
that doesn't point to anything and doesn't hold locks.

Fixes: bd5b09727f3d ("bcachefs: Don't set btree_path to updtodate if we don't fill")
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_key_cache.c

index 367231ab1980b13ef1f70e73a3dedeb8bb1642dd..5988219c690849974bd8ece6d6f846c87142fe43 100644 (file)
@@ -2239,8 +2239,6 @@ struct bkey_s_c btree_trans_peek_key_cache(struct btree_iter *iter, struct bpos
        if (unlikely(ret))
                return bkey_s_c_err(ret);
 
-       btree_path_set_should_be_locked(trans, trans->paths + iter->key_cache_path);
-
        k = bch2_btree_path_peek_slot(trans->paths + iter->key_cache_path, &u);
        if (!k.k)
                return k;
@@ -2251,6 +2249,7 @@ struct bkey_s_c btree_trans_peek_key_cache(struct btree_iter *iter, struct bpos
 
        iter->k = u;
        k.k = &iter->k;
+       btree_path_set_should_be_locked(trans, trans->paths + iter->key_cache_path);
        return k;
 }
 
index 3b62296c3100e77ffe17c0446e0d5150cd39e0b1..c378b97ebeca711550f3385ab99c5ec5c24b0040 100644 (file)
@@ -291,8 +291,10 @@ static noinline int btree_key_cache_fill(struct btree_trans *trans,
                                         struct btree_path *ck_path,
                                         unsigned flags)
 {
-       if (flags & BTREE_ITER_cached_nofill)
+       if (flags & BTREE_ITER_cached_nofill) {
+               ck_path->l[0].b = NULL;
                return 0;
+       }
 
        struct bch_fs *c = trans->c;
        struct btree_iter iter;