bcachefs: Fix trans_lock_write()
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 3 Nov 2021 21:23:03 +0000 (17:23 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:15 +0000 (17:09 -0400)
On failure to get a write lock (because we had a conflicting read lock),
we need to make sure to upgrade the read lock to an intent lock - or we
could end up spinning.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/btree_update_leaf.c

index 43ae2d83cfa7faacfcf16ae292fa3689ca4db933..fa6ba018378b175a8ff7022d3404f545f2c110ac 100644 (file)
@@ -569,7 +569,8 @@ static inline bool have_conflicting_read_lock(struct btree_trans *trans, struct
                //if (path == pos)
                //      break;
 
-               if (path->nodes_locked != path->nodes_intent_locked)
+               if (path->nodes_locked != path->nodes_intent_locked &&
+                   !bch2_btree_path_upgrade(trans, path, path->level + 1))
                        return true;
        }