bcachefs: Add an assertion for using multiple btree_trans
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 18 Feb 2023 01:51:52 +0000 (20:51 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:53 +0000 (17:09 -0400)
A thread should never be using more than one btree_trans - doing so is
an invitation for deadlocks.

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

index 4ac1364acc8bb9aa109b571827a57590a90f9b61..5ab22c4c2b2eb2760de221b110a552900afae958 100644 (file)
@@ -2955,6 +2955,15 @@ void __bch2_trans_init(struct btree_trans *trans, struct bch_fs *c, unsigned fn_
 
                mutex_lock(&c->btree_trans_lock);
                list_for_each_entry(pos, &c->btree_trans_list, list) {
+                       /*
+                        * We'd much prefer to be stricter here and completely
+                        * disallow multiple btree_trans in the same thread -
+                        * but the data move path calls bch2_write when we
+                        * already have a btree_trans initialized.
+                        */
+                       BUG_ON(trans->locking_wait.task->pid == pos->locking_wait.task->pid &&
+                              bch2_trans_locked(pos));
+
                        if (trans->locking_wait.task->pid < pos->locking_wait.task->pid) {
                                list_add_tail(&trans->list, &pos->list);
                                goto list_add_done;