Skip to content

Commit 18e9284

Browse files
author
Kent Overstreet
committed
bcachefs: Make btree_deadlock_to_text() clearer
btree_deadlock_to_text() searches the list of btree transactions to find a deadlock - when it finds one it's done; it's not like other *_read() functions that's printing each object. Factor out btree_deadlock_to_text() to make this clearer. Signed-off-by: Kent Overstreet <[email protected]>
1 parent f44cc26 commit 18e9284

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

fs/bcachefs/debug.c

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -802,48 +802,54 @@ static const struct file_operations btree_transaction_stats_op = {
802802
.read = btree_transaction_stats_read,
803803
};
804804

805-
static ssize_t bch2_btree_deadlock_read(struct file *file, char __user *buf,
806-
size_t size, loff_t *ppos)
805+
/* walk btree transactions until we find a deadlock and print it */
806+
static void btree_deadlock_to_text(struct printbuf *out, struct bch_fs *c)
807807
{
808-
struct dump_iter *i = file->private_data;
809-
struct bch_fs *c = i->c;
810808
struct btree_trans *trans;
811-
ssize_t ret = 0;
812-
813-
i->ubuf = buf;
814-
i->size = size;
815-
i->ret = 0;
816-
817-
if (i->iter)
818-
goto out;
809+
pid_t iter = 0;
819810
restart:
820811
seqmutex_lock(&c->btree_trans_lock);
821812
list_for_each_entry(trans, &c->btree_trans_list, list) {
822813
struct task_struct *task = READ_ONCE(trans->locking_wait.task);
823814

824-
if (!task || task->pid <= i->iter)
815+
if (!task || task->pid <= iter)
825816
continue;
826817

818+
iter = task->pid;
819+
827820
closure_get(&trans->ref);
828-
u32 seq = seqmutex_unlock(&c->btree_trans_lock);
829821

830-
ret = flush_buf(i);
831-
if (ret) {
832-
closure_put(&trans->ref);
833-
goto out;
834-
}
822+
u32 seq = seqmutex_unlock(&c->btree_trans_lock);
835823

836-
bch2_check_for_deadlock(trans, &i->buf);
837-
838-
i->iter = task->pid;
824+
bool found = bch2_check_for_deadlock(trans, out) != 0;
839825

840826
closure_put(&trans->ref);
841827

828+
if (found)
829+
return;
830+
842831
if (!seqmutex_relock(&c->btree_trans_lock, seq))
843832
goto restart;
844833
}
845834
seqmutex_unlock(&c->btree_trans_lock);
846-
out:
835+
}
836+
837+
static ssize_t bch2_btree_deadlock_read(struct file *file, char __user *buf,
838+
size_t size, loff_t *ppos)
839+
{
840+
struct dump_iter *i = file->private_data;
841+
struct bch_fs *c = i->c;
842+
ssize_t ret = 0;
843+
844+
i->ubuf = buf;
845+
i->size = size;
846+
i->ret = 0;
847+
848+
if (!i->iter) {
849+
btree_deadlock_to_text(&i->buf, c);
850+
i->iter++;
851+
}
852+
847853
if (i->buf.allocation_failure)
848854
ret = -ENOMEM;
849855

0 commit comments

Comments
 (0)