bcachefs: Fix lock ordering under traverse_all()
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 7 Mar 2022 02:17:43 +0000 (21:17 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:27 +0000 (17:09 -0400)
traverse_all() traverses btree paths in sorted order, so it should never
see transaction restarts due to lock ordering violations. But some code
in __bch2_btree_path_upgrade(), while necessary when not running under
traverse_all(), was causing some confusing lock ordering violations -
disabling this code under traverse_all() will let us put in some more
assertions.

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

index 90f5d30..1cfd2e9 100644 (file)
@@ -473,14 +473,15 @@ bool __bch2_btree_path_upgrade(struct btree_trans *trans,
         * before interior nodes - now that's handled by
         * bch2_btree_path_traverse_all().
         */
-       trans_for_each_path(trans, linked)
-               if (linked != path &&
-                   linked->cached == path->cached &&
-                   linked->btree_id == path->btree_id &&
-                   linked->locks_want < new_locks_want) {
-                       linked->locks_want = new_locks_want;
-                       btree_path_get_locks(trans, linked, true);
-               }
+       if (!path->cached && !trans->in_traverse_all)
+               trans_for_each_path(trans, linked)
+                       if (linked != path &&
+                           linked->cached == path->cached &&
+                           linked->btree_id == path->btree_id &&
+                           linked->locks_want < new_locks_want) {
+                               linked->locks_want = new_locks_want;
+                               btree_path_get_locks(trans, linked, true);
+                       }
 
        return false;
 }