Skip to content

Commit a858175

Browse files
author
Kent Overstreet
committed
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: bd5b097 ("bcachefs: Don't set btree_path to updtodate if we don't fill") Signed-off-by: Kent Overstreet <[email protected]>
1 parent ff0b7ed commit a858175

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

fs/bcachefs/btree_iter.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,8 +2239,6 @@ struct bkey_s_c btree_trans_peek_key_cache(struct btree_iter *iter, struct bpos
22392239
if (unlikely(ret))
22402240
return bkey_s_c_err(ret);
22412241

2242-
btree_path_set_should_be_locked(trans, trans->paths + iter->key_cache_path);
2243-
22442242
k = bch2_btree_path_peek_slot(trans->paths + iter->key_cache_path, &u);
22452243
if (!k.k)
22462244
return k;
@@ -2251,6 +2249,7 @@ struct bkey_s_c btree_trans_peek_key_cache(struct btree_iter *iter, struct bpos
22512249

22522250
iter->k = u;
22532251
k.k = &iter->k;
2252+
btree_path_set_should_be_locked(trans, trans->paths + iter->key_cache_path);
22542253
return k;
22552254
}
22562255

fs/bcachefs/btree_key_cache.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,10 @@ static noinline int btree_key_cache_fill(struct btree_trans *trans,
291291
struct btree_path *ck_path,
292292
unsigned flags)
293293
{
294-
if (flags & BTREE_ITER_cached_nofill)
294+
if (flags & BTREE_ITER_cached_nofill) {
295+
ck_path->l[0].b = NULL;
295296
return 0;
297+
}
296298

297299
struct bch_fs *c = trans->c;
298300
struct btree_iter iter;

0 commit comments

Comments
 (0)