]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bcachefs: Fix locking in bch2_btree_iter_traverse_cached()
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 8 Mar 2021 22:09:13 +0000 (17:09 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:55 +0000 (17:08 -0400)
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>
fs/bcachefs/btree_key_cache.c

index 6dc13fa3d1f4e56e89d8d72714386be289640c43..76f19f86c8adbbe5d5428be45dd30b9888d260e5 100644 (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) {