Skip to content

Commit 22e921a

Browse files
author
Kent Overstreet
committed
bcachefs: Simplify bch2_path_put()
Simplify the "do we need to keep this locked?" checks. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 80a160e commit 22e921a

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

fs/bcachefs/btree_iter.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,35 +1399,44 @@ static bool bch2_btree_path_can_relock(struct btree_trans *trans, struct btree_p
13991399

14001400
void bch2_path_put(struct btree_trans *trans, btree_path_idx_t path_idx, bool intent)
14011401
{
1402-
struct btree_path *path = trans->paths + path_idx, *dup;
1402+
struct btree_path *path = trans->paths + path_idx, *dup = NULL;
14031403

14041404
if (!__btree_path_put(trans, path, intent))
14051405
return;
14061406

1407+
if (!path->preserve && !path->should_be_locked)
1408+
goto free;
1409+
14071410
dup = path->preserve
14081411
? have_path_at_pos(trans, path)
14091412
: have_node_at_pos(trans, path);
1410-
1411-
trace_btree_path_free(trans, path_idx, dup);
1412-
1413-
if (!dup && !(!path->preserve && !is_btree_node(path, path->level)))
1413+
if (!dup)
14141414
return;
14151415

1416-
if (path->should_be_locked && !trans->restarted) {
1417-
if (!dup)
1418-
return;
1419-
1416+
/*
1417+
* If we need this path locked, the duplicate also has te be locked
1418+
* before we free this one:
1419+
*/
1420+
if (path->should_be_locked &&
1421+
!dup->should_be_locked &&
1422+
!trans->restarted) {
14201423
if (!(trans->locked
14211424
? bch2_btree_path_relock_norestart(trans, dup)
14221425
: bch2_btree_path_can_relock(trans, dup)))
14231426
return;
1424-
}
14251427

1426-
if (dup) {
1427-
dup->preserve |= path->preserve;
1428-
dup->should_be_locked |= path->should_be_locked;
1428+
dup->should_be_locked = true;
14291429
}
14301430

1431+
BUG_ON(path->should_be_locked &&
1432+
!trans->restarted &&
1433+
trans->locked &&
1434+
!btree_node_locked(dup, dup->level));
1435+
1436+
path->should_be_locked = false;
1437+
dup->preserve |= path->preserve;
1438+
free:
1439+
trace_btree_path_free(trans, path_idx, dup);
14311440
__bch2_path_free(trans, path_idx);
14321441
}
14331442

0 commit comments

Comments
 (0)