bcachefs: Fix locking in bch2_btree_iter_traverse_cached()

bch2_btree_iter_traverse() is supposed to ensure we have the correct
type of lock - it was downgrading if necessary, but if we entered with a
read lock it wasn't upgrading to an intent lock, oops.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2021-03-08 17:09:13 -05:00 committed by Kent Overstreet
parent c7bb769c81
commit 53b3e3c0e2

View File

@ -298,7 +298,14 @@ fill:
set_bit(BKEY_CACHED_ACCESSED, &ck->flags);
iter->uptodate = BTREE_ITER_NEED_PEEK;
bch2_btree_iter_downgrade(iter);
if (!(iter->flags & BTREE_ITER_INTENT))
bch2_btree_iter_downgrade(iter);
else if (!iter->locks_want) {
if (!__bch2_btree_iter_upgrade(iter, 1))
ret = -EINTR;
}
return ret;
err:
if (ret != -EINTR) {