bcachefs: Give out new path if upgrade fails
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 22:00:45 +0000 (18:00 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 23 May 2025 11:59:43 +0000 (07:59 -0400)
Avoid transaction restarts due to failure to upgrade - we can traverse a
new iterator without a transaction restart.

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

index 831275f8e79f7fd788163ee85948d9566f244386..cae0fa60434bf62528691d3ae8162240cb553b44 100644 (file)
@@ -1740,6 +1740,10 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans,
 
        btree_trans_sort_paths(trans);
 
+       if (intent)
+               locks_want = max(locks_want, level + 1);
+       locks_want = min(locks_want, BTREE_MAX_DEPTH);
+
        trans_for_each_path_inorder(trans, path, iter) {
                if (__btree_path_cmp(path,
                                     btree_id,
@@ -1754,7 +1758,8 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans,
        if (path_pos &&
            trans->paths[path_pos].cached       == cached &&
            trans->paths[path_pos].btree_id     == btree_id &&
-           trans->paths[path_pos].level        == level) {
+           trans->paths[path_pos].level        == level &&
+           bch2_btree_path_upgrade_norestart(trans, trans->paths + path_pos, locks_want)) {
                trace_btree_path_get(trans, trans->paths + path_pos, &pos);
 
                __btree_path_get(trans, trans->paths + path_pos, intent);
@@ -1786,9 +1791,6 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans,
        if (!(flags & BTREE_ITER_nopreserve))
                path->preserve = true;
 
-       if (path->intent_ref)
-               locks_want = max(locks_want, level + 1);
-
        /*
         * If the path has locks_want greater than requested, we don't downgrade
         * it here - on transaction restart because btree node split needs to
@@ -1797,10 +1799,6 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans,
         * a successful transaction commit.
         */
 
-       locks_want = min(locks_want, BTREE_MAX_DEPTH);
-       if (locks_want > path->locks_want)
-               bch2_btree_path_upgrade_norestart(trans, path, locks_want);
-
        return path_idx;
 }