bcachefs: bch2_trans_in_restart_error()
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 1 Feb 2023 21:15:51 +0000 (16:15 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:50 +0000 (17:09 -0400)
This replaces various BUG_ON() assertions with panics that tell us where
the restart was done and the restart type.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_iter.h
fs/bcachefs/btree_update_leaf.c

index 1a71e8af52d0db83cd0f842b5dee5f02d1695a93..25345ed11076e056b8f3345958c2d57bb22ce62d 100644 (file)
@@ -1224,7 +1224,7 @@ __bch2_btree_path_set_pos(struct btree_trans *trans,
 {
        unsigned level = path->level;
 
-       EBUG_ON(trans->restarted);
+       bch2_trans_verify_not_in_restart(trans);
        EBUG_ON(!path->ref);
 
        path = bch2_btree_path_make_mut(trans, path, intent, ip);
@@ -1353,6 +1353,20 @@ static void bch2_path_put_nokeep(struct btree_trans *trans, struct btree_path *p
        __bch2_path_free(trans, path);
 }
 
+void __noreturn bch2_trans_restart_error(struct btree_trans *trans, u32 restart_count)
+{
+       panic("trans->restart_count %u, should be %u, last restarted by %pS\n",
+             trans->restart_count, restart_count,
+             (void *) trans->last_restarted_ip);
+}
+
+void __noreturn bch2_trans_in_restart_error(struct btree_trans *trans)
+{
+       panic("in transaction restart: %s, last restarted by %pS\n",
+             bch2_err_str(trans->restarted),
+             (void *) trans->last_restarted_ip);
+}
+
 noinline __cold
 void bch2_trans_updates_to_text(struct printbuf *buf, struct btree_trans *trans)
 {
@@ -1519,7 +1533,7 @@ struct btree_path *bch2_path_get(struct btree_trans *trans,
        bool intent = flags & BTREE_ITER_INTENT;
        int i;
 
-       EBUG_ON(trans->restarted);
+       bch2_trans_verify_not_in_restart(trans);
        bch2_trans_verify_locks(trans);
 
        btree_trans_sort_paths(trans);
@@ -1695,7 +1709,7 @@ struct btree *bch2_btree_iter_next_node(struct btree_iter *iter)
        struct btree *b = NULL;
        int ret;
 
-       BUG_ON(trans->restarted);
+       bch2_trans_verify_not_in_restart(trans);
        EBUG_ON(iter->path->cached);
        bch2_btree_iter_verify(iter);
 
@@ -2833,14 +2847,6 @@ u32 bch2_trans_begin(struct btree_trans *trans)
        return trans->restart_count;
 }
 
-void bch2_trans_verify_not_restarted(struct btree_trans *trans, u32 restart_count)
-{
-       if (trans_was_restarted(trans, restart_count))
-               panic("trans->restart_count %u, should be %u, last restarted by %pS\n",
-                     trans->restart_count, restart_count,
-                     (void *) trans->last_restarted_ip);
-}
-
 static void bch2_trans_alloc_paths(struct btree_trans *trans, struct bch_fs *c)
 {
        size_t paths_bytes      = sizeof(struct btree_path) * BTREE_ITER_MAX;
index df87d88982ae93f9b6547c06d3f8d0cb96eb9841..2a57da036f271ecb7d9f1344efaad39ec0b94719 100644 (file)
@@ -227,7 +227,22 @@ static inline bool trans_was_restarted(struct btree_trans *trans, u32 restart_co
        return restart_count != trans->restart_count;
 }
 
-void bch2_trans_verify_not_restarted(struct btree_trans *, u32);
+void __noreturn bch2_trans_restart_error(struct btree_trans *, u32);
+
+static inline void bch2_trans_verify_not_restarted(struct btree_trans *trans,
+                                                  u32 restart_count)
+{
+       if (trans_was_restarted(trans, restart_count))
+               bch2_trans_restart_error(trans, restart_count);
+}
+
+void __noreturn bch2_trans_in_restart_error(struct btree_trans *);
+
+static inline void bch2_trans_verify_not_in_restart(struct btree_trans *trans)
+{
+       if (trans->restarted)
+               bch2_trans_in_restart_error(trans);
+}
 
 __always_inline
 static inline int btree_trans_restart_nounlock(struct btree_trans *trans, int err)
index 1dc86ac6f83753e7a4e23f31e3edcdaa43115dbb..656de4f59d828bb6aa12dbe97d3b119739957aff 100644 (file)
@@ -1098,7 +1098,7 @@ int __bch2_trans_commit(struct btree_trans *trans)
                        goto err;
        }
 retry:
-       EBUG_ON(trans->restarted);
+       bch2_trans_verify_not_in_restart(trans);
        memset(&trans->journal_res, 0, sizeof(trans->journal_res));
 
        ret = do_bch2_trans_commit(trans, &i, _RET_IP_);