Skip to content

Commit b1c71cb

Browse files
author
Kent Overstreet
committed
bcachefs: Fix broken btree_path lock invariants in next_node()
This fixes btree locking assert pops users were seeing during evacuate: koverstreet/bcachefs#878 May 09 22:45:02 sharon kernel: bcachefs (68116e25-fa2d-4c6f-86c7-e8b431d792ae): bch2_btree_insert_node(): node not locked at level 1 May 09 22:45:02 sharon kernel: bch2_btree_node_rewrite [bcachefs]: watermark=btree no_check_rw alloc l=0-1 mode=none nodes_written=0 cl.remaining=2 journal_seq=0 May 09 22:45:02 sharon kernel: path: idx 1 ref 1:0 S B btree=alloc level=0 pos 0:3699637:0 0:3698012:1-0:3699637:0 bch2_move_btree.isra.0+0x1db/0x490 [bcachefs] uptodate 0 locks_want 2 May 09 22:45:02 sharon kernel: l=0 locks intent seq 4 node ffff8bd700c93600 May 09 22:45:02 sharon kernel: l=1 locks unlocked seq 1712 node ffff8bd6fd5e7a00 May 09 22:45:02 sharon kernel: l=2 locks unlocked seq 2295 node ffff8bd6cc725400 May 09 22:45:02 sharon kernel: l=3 locks unlocked seq 0 node 0000000000000000 Evacuate walks btree nodes with bch2_btree_iter_next_node() and rewrites them, bch2_btree_update_start() upgrades the path to take intent locks as far as it needs to. But next_node() does low level unlock/relock calls on individual nodes, and didn't handle the case where a path is supposed to be holding multiple intent locks. If a path has locks_want > 1, it needs to be either holding locks on all the btree nodes (at each level) requested, or none of them. Fix this with a bch2_btree_path_downgrade(). Signed-off-by: Kent Overstreet <[email protected]>
1 parent cd52cc3 commit b1c71cb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/bcachefs/btree_iter.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,12 @@ struct btree *bch2_btree_iter_next_node(struct btree_trans *trans, struct btree_
19711971
return NULL;
19721972
}
19731973

1974+
/*
1975+
* We don't correctly handle nodes with extra intent locks here:
1976+
* downgrade so we don't violate locking invariants
1977+
*/
1978+
bch2_btree_path_downgrade(trans, path);
1979+
19741980
if (!bch2_btree_node_relock(trans, path, path->level + 1)) {
19751981
__bch2_btree_path_unlock(trans, path);
19761982
path->l[path->level].b = ERR_PTR(-BCH_ERR_no_btree_node_relock);

0 commit comments

Comments
 (0)