]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: factor out break_cycle_fail()
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 26 May 2025 20:29:56 +0000 (16:29 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 30 May 2025 05:21:12 +0000 (01:21 -0400)
More stack usage work.

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

index 2f2aed0c9916c10a4b4cd7f6266ea5fcd4073944..09ae5a8c68742c3191c2e5c0f9c02c228b66586b 100644 (file)
@@ -194,6 +194,30 @@ static int btree_trans_abort_preference(struct btree_trans *trans)
        return 3;
 }
 
+static noinline __noreturn void break_cycle_fail(struct lock_graph *g)
+{
+       struct printbuf buf = PRINTBUF;
+       buf.atomic++;
+
+       prt_printf(&buf, bch2_fmt(g->g->trans->c, "cycle of nofail locks"));
+
+       for (struct trans_waiting_for_lock *i = g->g; i < g->g + g->nr; i++) {
+               struct btree_trans *trans = i->trans;
+
+               bch2_btree_trans_to_text(&buf, trans);
+
+               prt_printf(&buf, "backtrace:\n");
+               printbuf_indent_add(&buf, 2);
+               bch2_prt_task_backtrace(&buf, trans->locking_wait.task, 2, GFP_NOWAIT);
+               printbuf_indent_sub(&buf, 2);
+               prt_newline(&buf);
+       }
+
+       bch2_print_str_nonblocking(g->g->trans->c, KERN_ERR, buf.buf);
+       printbuf_exit(&buf);
+       BUG();
+}
+
 static noinline int break_cycle(struct lock_graph *g, struct printbuf *cycle,
                                struct trans_waiting_for_lock *from)
 {
@@ -219,28 +243,8 @@ static noinline int break_cycle(struct lock_graph *g, struct printbuf *cycle,
                }
        }
 
-       if (unlikely(!best)) {
-               struct printbuf buf = PRINTBUF;
-               buf.atomic++;
-
-               prt_printf(&buf, bch2_fmt(g->g->trans->c, "cycle of nofail locks"));
-
-               for (i = g->g; i < g->g + g->nr; i++) {
-                       struct btree_trans *trans = i->trans;
-
-                       bch2_btree_trans_to_text(&buf, trans);
-
-                       prt_printf(&buf, "backtrace:\n");
-                       printbuf_indent_add(&buf, 2);
-                       bch2_prt_task_backtrace(&buf, trans->locking_wait.task, 2, GFP_NOWAIT);
-                       printbuf_indent_sub(&buf, 2);
-                       prt_newline(&buf);
-               }
-
-               bch2_print_str_nonblocking(g->g->trans->c, KERN_ERR, buf.buf);
-               printbuf_exit(&buf);
-               BUG();
-       }
+       if (unlikely(!best))
+               break_cycle_fail(g);
 
        ret = abort_lock(g, abort);
 out:
@@ -255,15 +259,14 @@ static int lock_graph_descend(struct lock_graph *g, struct btree_trans *trans,
                              struct printbuf *cycle)
 {
        struct btree_trans *orig_trans = g->g->trans;
-       struct trans_waiting_for_lock *i;
 
-       for (i = g->g; i < g->g + g->nr; i++)
+       for (struct trans_waiting_for_lock *i = g->g; i < g->g + g->nr; i++)
                if (i->trans == trans) {
                        closure_put(&trans->ref);
                        return break_cycle(g, cycle, i);
                }
 
-       if (g->nr == ARRAY_SIZE(g->g)) {
+       if (unlikely(g->nr == ARRAY_SIZE(g->g))) {
                closure_put(&trans->ref);
 
                if (orig_trans->lock_may_not_fail)