Commit a8581752 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: Fix btree_trans_peek_key_cache()



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: bd5b0972 ("bcachefs: Don't set btree_path to updtodate if we don't fill")
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent ff0b7ed6
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -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;
}

+3 −1
Original line number Diff line number Diff line
@@ -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;