bcachefs: bch2_path_get() reuses paths if upgrade_fails & !should_be_locked
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 22:12:54 +0000 (18:12 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 23 May 2025 11:59:43 +0000 (07:59 -0400)
Small additional optimization over the previous patch, bringing us
closer to the original behaviour, except when we need to clone to avoid
a transaction restart.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_locking.c

index 6e43269a9c47af1f8e573de5e820d1e3ac274f4f..78f485ed174696b9c0666036650ed77b1ea16f90 100644 (file)
@@ -628,8 +628,13 @@ bool __bch2_btree_path_upgrade_norestart(struct btree_trans *trans,
 {
        path->locks_want = new_locks_want;
 
-       struct get_locks_fail f = {};
-       bool ret = !btree_path_get_locks(trans, path, true, &f, 0);
+       /*
+        * If we need it locked, we can't touch it. Otherwise, we can return
+        * success - bch2_path_get() will use this path, and it'll just be
+        * retraversed:
+        */
+       bool ret = !btree_path_get_locks(trans, path, true, NULL, 0) ||
+               !path->should_be_locked;
 
        bch2_btree_path_verify_locks(path);
        return ret;