diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-02-17 20:51:52 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:53 -0400 |
commit | 6623c0fcdffe22db466ec38c5f9f4b3a44c33003 (patch) | |
tree | c5751424930e029896f6fe3e8d1ba2afea5590f7 /fs/bcachefs/btree_iter.c | |
parent | 2c7dd446d91681e90396c82e20c703b93f8daa2f (diff) | |
download | lwn-6623c0fcdffe22db466ec38c5f9f4b3a44c33003.tar.gz lwn-6623c0fcdffe22db466ec38c5f9f4b3a44c33003.zip |
bcachefs: Add an assertion for using multiple btree_trans
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>
Diffstat (limited to 'fs/bcachefs/btree_iter.c')
-rw-r--r-- | fs/bcachefs/btree_iter.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index 4ac1364acc8b..5ab22c4c2b2e 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -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; |