bcachefs: Improve debug assertion
authorKent Overstreet <kent.overstreet@gmail.com>
Fri, 25 Feb 2022 00:04:11 +0000 (19:04 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:25 +0000 (17:09 -0400)
We're hitting a strange bug with transaction paths not being sorted
correctly - this dumps transaction paths in the order we thought was
sorted, which will hopefully shed some light as to what's going on.

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

index 8aacaa05fc144bf71de439fb0223f721ba71dc68..b58219292f3435636b34b46c89dd90f18384333b 100644 (file)
@@ -1410,7 +1410,7 @@ static int btree_path_traverse_one(struct btree_trans *, struct btree_path *,
 static int bch2_btree_path_traverse_all(struct btree_trans *trans)
 {
        struct bch_fs *c = trans->c;
-       struct btree_path *path, *prev = NULL;
+       struct btree_path *path, *prev;
        unsigned long trace_ip = _RET_IP_;
        int i, ret = 0;
 
@@ -1419,6 +1419,7 @@ static int bch2_btree_path_traverse_all(struct btree_trans *trans)
 
        trans->in_traverse_all = true;
 retry_all:
+       prev = NULL;
        trans->restarted = false;
 
        trans_for_each_path(trans, path)
@@ -1852,6 +1853,7 @@ struct btree_path *bch2_path_get(struct btree_trans *trans,
        int i;
 
        BUG_ON(trans->restarted);
+       btree_trans_sort_paths(trans);
 
        btree_trans_sort_paths(trans);
 
@@ -2722,7 +2724,10 @@ static void btree_trans_verify_sorted(struct btree_trans *trans)
        unsigned i;
 
        trans_for_each_path_inorder(trans, path, i) {
-               BUG_ON(prev && btree_path_cmp(prev, path) > 0);
+               if (prev && btree_path_cmp(prev, path) > 0) {
+                       bch2_dump_trans_paths_updates(trans);
+                       panic("trans paths out of order!\n");
+               }
                prev = path;
        }
 }