From: Kent Overstreet Date: Thu, 22 May 2025 20:03:08 +0000 (-0400) Subject: bcachefs: Clear should_be_locked before unlock in key_cache_drop() X-Git-Tag: v6.16-rc1~211^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eb34365adae033659384d1dedae99f73abd9815a;p=thirdparty%2Fkernel%2Flinux.git bcachefs: Clear should_be_locked before unlock in key_cache_drop() We're adding new should_be_locked assertions, also add a comment explaining why clearing should_be_locked is safe here. Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c index b8efe2fddbc44..9948d0e4d442c 100644 --- a/fs/bcachefs/btree_key_cache.c +++ b/fs/bcachefs/btree_key_cache.c @@ -646,9 +646,16 @@ void bch2_btree_key_cache_drop(struct btree_trans *trans, unsigned i; trans_for_each_path(trans, path2, i) if (path2->l[0].b == (void *) ck) { + /* + * It's safe to clear should_be_locked here because + * we're evicting from the key cache, and we still have + * the underlying btree locked: filling into the key + * cache would require taking a write lock on the btree + * node + */ + path2->should_be_locked = false; __bch2_btree_path_unlock(trans, path2); path2->l[0].b = ERR_PTR(-BCH_ERR_no_btree_node_drop); - path2->should_be_locked = false; btree_path_set_dirty(path2, BTREE_ITER_NEED_TRAVERSE); }