bcachefs: Better in_restart error
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 15 Oct 2024 03:52:51 +0000 (23:52 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:16 +0000 (01:36 -0500)
We're ramping up on checking transaction restart handling correctness -
so, in debug mode we now save a backtrace for where the restart was
emitted, which makes it much easier to track down the incorrect
handling.

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

index 98375c66021a3f18ad473bdd965b5c2d0b726c81..acf70aaf2fd2999929720aa567c877bc6184a057 100644 (file)
@@ -1427,9 +1427,17 @@ void __noreturn bch2_trans_restart_error(struct btree_trans *trans, u32 restart_
 
 void __noreturn bch2_trans_in_restart_error(struct btree_trans *trans)
 {
+#ifdef CONFIG_BCACHEFS_DEBUG
+       struct printbuf buf = PRINTBUF;
+       bch2_prt_backtrace(&buf, &trans->last_restarted_trace);
+       panic("in transaction restart: %s, last restarted by\n%s",
+             bch2_err_str(trans->restarted),
+             buf.buf);
+#else
        panic("in transaction restart: %s, last restarted by %pS\n",
              bch2_err_str(trans->restarted),
              (void *) trans->last_restarted_ip);
+#endif
 }
 
 void __noreturn bch2_trans_unlocked_error(struct btree_trans *trans)
@@ -3287,6 +3295,10 @@ void bch2_trans_put(struct btree_trans *trans)
        closure_return_sync(&trans->ref);
        trans->locking_wait.task = NULL;
 
+#ifdef CONFIG_BCACHEFS_DEBUG
+       darray_exit(&trans->last_restarted_trace);
+#endif
+
        unsigned long *paths_allocated = trans->paths_allocated;
        trans->paths_allocated  = NULL;
        trans->paths            = NULL;
index dda07a3204880abf80029f5540654f4922e3b24a..36899c6b134e5e2785ef871c2ed362d00fa309f3 100644 (file)
@@ -350,6 +350,10 @@ static int btree_trans_restart_ip(struct btree_trans *trans, int err, unsigned l
 
        trans->restarted = err;
        trans->last_restarted_ip = ip;
+#ifdef CONFIG_BCACHEFS_DEBUG
+       darray_exit(&trans->last_restarted_trace);
+       bch2_save_backtrace(&trans->last_restarted_trace, current, 0, GFP_NOWAIT);
+#endif
        return -err;
 }
 
index 4568a41fefaf63bee803c169eb8b07a30d625a40..baab5288ecc9bf67eb44980218fcbcefda9dde75 100644 (file)
@@ -513,6 +513,9 @@ struct btree_trans {
        u64                     last_begin_time;
        unsigned long           last_begin_ip;
        unsigned long           last_restarted_ip;
+#ifdef CONFIG_BCACHEFS_DEBUG
+       bch_stacktrace          last_restarted_trace;
+#endif
        unsigned long           last_unlock_ip;
        unsigned long           srcu_lock_time;