From 5e2d8be8bd7985aa590dcccec14fb38fb529b3f0 Mon Sep 17 00:00:00 2001
From: Kent Overstreet <kent.overstreet@linux.dev>
Date: Sat, 18 Feb 2023 21:20:18 -0500
Subject: [PATCH] bcachefs: Split trans->last_begin_ip and
 trans->last_restarted_ip

These are two different things - this improves our debug assert
messages.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 fs/bcachefs/btree_iter.c  | 5 +++--
 fs/bcachefs/btree_iter.h  | 1 +
 fs/bcachefs/btree_types.h | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c
index 5ab22c4c2b2e..63213205a043 100644
--- a/fs/bcachefs/btree_iter.c
+++ b/fs/bcachefs/btree_iter.c
@@ -976,6 +976,7 @@ static int bch2_btree_path_traverse_all(struct btree_trans *trans)
 	trans->in_traverse_all = true;
 retry_all:
 	trans->restarted = 0;
+	trans->last_restarted_ip = 0;
 
 	trans_for_each_path(trans, path)
 		path->should_be_locked = false;
@@ -1360,7 +1361,7 @@ void __noreturn bch2_trans_restart_error(struct btree_trans *trans, u32 restart_
 {
 	panic("trans->restart_count %u, should be %u, last restarted by %pS\n",
 	      trans->restart_count, restart_count,
-	      (void *) trans->last_restarted_ip);
+	      (void *) trans->last_begin_ip);
 }
 
 void __noreturn bch2_trans_in_restart_error(struct btree_trans *trans)
@@ -2865,7 +2866,7 @@ u32 bch2_trans_begin(struct btree_trans *trans)
 	if (unlikely(time_after(jiffies, trans->srcu_lock_time + msecs_to_jiffies(10))))
 		bch2_trans_reset_srcu_lock(trans);
 
-	trans->last_restarted_ip = _RET_IP_;
+	trans->last_begin_ip = _RET_IP_;
 	if (trans->restarted) {
 		bch2_btree_path_traverse_all(trans);
 		trans->notrace_relock_fail = false;
diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h
index 458c7f7dc5b7..50b39704c56f 100644
--- a/fs/bcachefs/btree_iter.h
+++ b/fs/bcachefs/btree_iter.h
@@ -260,6 +260,7 @@ static inline int btree_trans_restart_nounlock(struct btree_trans *trans, int er
 	BUG_ON(!bch2_err_matches(err, BCH_ERR_transaction_restart));
 
 	trans->restarted = err;
+	trans->last_restarted_ip = _THIS_IP_;
 	return -err;
 }
 
diff --git a/fs/bcachefs/btree_types.h b/fs/bcachefs/btree_types.h
index 9fdddfb15782..38bc2a1d198b 100644
--- a/fs/bcachefs/btree_types.h
+++ b/fs/bcachefs/btree_types.h
@@ -431,6 +431,7 @@ struct btree_trans {
 	bool			notrace_relock_fail:1;
 	enum bch_errcode	restarted:16;
 	u32			restart_count;
+	unsigned long		last_begin_ip;
 	unsigned long		last_restarted_ip;
 	unsigned long		srcu_lock_time;
 
-- 
2.30.9