Skip to content

Commit aac4947

Browse files
author
Kent Overstreet
committed
bcachefs: Give out new path if upgrade fails
Avoid transaction restarts due to failure to upgrade - we can traverse a new iterator without a transaction restart. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 66782b2 commit aac4947

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

fs/bcachefs/btree_iter.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,10 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans,
17401740

17411741
btree_trans_sort_paths(trans);
17421742

1743+
if (intent)
1744+
locks_want = max(locks_want, level + 1);
1745+
locks_want = min(locks_want, BTREE_MAX_DEPTH);
1746+
17431747
trans_for_each_path_inorder(trans, path, iter) {
17441748
if (__btree_path_cmp(path,
17451749
btree_id,
@@ -1754,7 +1758,8 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans,
17541758
if (path_pos &&
17551759
trans->paths[path_pos].cached == cached &&
17561760
trans->paths[path_pos].btree_id == btree_id &&
1757-
trans->paths[path_pos].level == level) {
1761+
trans->paths[path_pos].level == level &&
1762+
bch2_btree_path_upgrade_norestart(trans, trans->paths + path_pos, locks_want)) {
17581763
trace_btree_path_get(trans, trans->paths + path_pos, &pos);
17591764

17601765
__btree_path_get(trans, trans->paths + path_pos, intent);
@@ -1786,9 +1791,6 @@ btree_path_idx_t bch2_path_get(struct btree_trans *trans,
17861791
if (!(flags & BTREE_ITER_nopreserve))
17871792
path->preserve = true;
17881793

1789-
if (path->intent_ref)
1790-
locks_want = max(locks_want, level + 1);
1791-
17921794
/*
17931795
* If the path has locks_want greater than requested, we don't downgrade
17941796
* 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,
17971799
* a successful transaction commit.
17981800
*/
17991801

1800-
locks_want = min(locks_want, BTREE_MAX_DEPTH);
1801-
if (locks_want > path->locks_want)
1802-
bch2_btree_path_upgrade_norestart(trans, path, locks_want);
1803-
18041802
return path_idx;
18051803
}
18061804

0 commit comments

Comments
 (0)