Skip to content

Commit b41ac97

Browse files
author
Kent Overstreet
committed
bcachefs: Path must be locked if trans->locked && should_be_locked
If path->should_be_locked is true, that means user code (of the btree API) has seen, in this transaction, something guarded by the node this path has locked, and we have to keep it locked until the end of the transaction. Assert that we're not violating this; should_be_locked should also be cleared only in _very_ special situations. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 22e921a commit b41ac97

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

fs/bcachefs/btree_iter.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,6 +1979,7 @@ struct btree *bch2_btree_iter_next_node(struct btree_trans *trans, struct btree_
19791979

19801980
/* got to end? */
19811981
if (!btree_path_node(path, path->level + 1)) {
1982+
path->should_be_locked = false;
19821983
btree_path_set_level_up(trans, path);
19831984
return NULL;
19841985
}

fs/bcachefs/btree_iter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static inline void btree_path_set_dirty(struct btree_trans *trans,
5050
struct btree_path *path,
5151
enum btree_path_uptodate u)
5252
{
53+
BUG_ON(path->should_be_locked && trans->locked && !trans->restarted);
5354
path->uptodate = max_t(unsigned, path->uptodate, u);
5455
}
5556

fs/bcachefs/btree_locking.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -882,14 +882,15 @@ int __bch2_trans_mutex_lock(struct btree_trans *trans,
882882

883883
void __bch2_btree_path_verify_locks(struct btree_trans *trans, struct btree_path *path)
884884
{
885-
/*
886-
* A path may be uptodate and yet have nothing locked if and only if
887-
* there is no node at path->level, which generally means we were
888-
* iterating over all nodes and got to the end of the btree
889-
*/
890-
BUG_ON(path->uptodate == BTREE_ITER_UPTODATE &&
891-
btree_path_node(path, path->level) &&
892-
!path->nodes_locked);
885+
if (!path->nodes_locked && btree_path_node(path, path->level)) {
886+
/*
887+
* A path may be uptodate and yet have nothing locked if and only if
888+
* there is no node at path->level, which generally means we were
889+
* iterating over all nodes and got to the end of the btree
890+
*/
891+
BUG_ON(path->uptodate == BTREE_ITER_UPTODATE);
892+
BUG_ON(path->should_be_locked && trans->locked && !trans->restarted);
893+
}
893894

894895
if (!path->nodes_locked)
895896
return;

0 commit comments

Comments
 (0)