bcachefs: print_str_as_lines() -> print_str()
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 15 Apr 2025 21:31:47 +0000 (17:31 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:18 +0000 (20:14 -0400)
bch2_print_string_as_lines() is a low level helper that allows messages
longer than 1k to be printed without truncation.

But we should always be printing with the helpers that take a filesystem
object, if we're in fsck they direct output to the userspace process
controlling fsck instead of the dmesg log.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
19 files changed:
fs/bcachefs/alloc_foreground.c
fs/bcachefs/bcachefs.h
fs/bcachefs/btree_io.c
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_locking.c
fs/bcachefs/btree_node_scan.c
fs/bcachefs/btree_update_interior.c
fs/bcachefs/buckets.c
fs/bcachefs/data_update.c
fs/bcachefs/error.c
fs/bcachefs/fs-io.c
fs/bcachefs/io_write.c
fs/bcachefs/journal.c
fs/bcachefs/journal_io.c
fs/bcachefs/recovery_passes.c
fs/bcachefs/sb-members.c
fs/bcachefs/super.c
fs/bcachefs/util.c
fs/bcachefs/util.h

index 31d2207a071b69e3da9fd716df159da9ab44a680..d56cee7e8cb5a360b6b3d6c41d0c861d10abe421 100644 (file)
@@ -1664,7 +1664,7 @@ static noinline void bch2_print_allocator_stuck(struct bch_fs *c)
        bch2_journal_debug_to_text(&buf, &c->journal);
        printbuf_indent_sub(&buf, 2);
 
-       bch2_print_string_as_lines(KERN_ERR, buf.buf);
+       bch2_print_str(c, KERN_ERR, buf.buf);
        printbuf_exit(&buf);
 }
 
index 7782e311b6e2163ca8442295d6374f3045615ff4..4fd0963497906bc6156e022a400f26d3a0368b1d 100644 (file)
@@ -269,7 +269,8 @@ do {                                                                        \
 
 #define bch2_fmt(_c, fmt)              bch2_log_msg(_c, fmt "\n")
 
-void bch2_print_str(struct bch_fs *, const char *);
+void bch2_print_str(struct bch_fs *, const char *, const char *);
+void bch2_print_str_nonblocking(struct bch_fs *, const char *, const char *);
 
 __printf(2, 3)
 void bch2_print_opts(struct bch_opts *, const char *, ...);
index 4832ac31392a559033653e12896b7e3e78772bbf..b6f5e0dfc9f1b9c0b2519f87c4f764068e85653a 100644 (file)
@@ -605,7 +605,7 @@ static int __btree_err(int ret,
        }
 
        if (!silent)
-               bch2_print_string_as_lines(KERN_ERR, out.buf);
+               bch2_print_str(c, KERN_ERR, out.buf);
 out:
 fsck_err:
        printbuf_exit(&out);
index cfd6363dfc39adb8bd624acb5fe0a811444634c0..bd3a0bc07511930341c96d90818dd6c640d0515e 100644 (file)
@@ -1591,7 +1591,7 @@ void __bch2_dump_trans_paths_updates(struct btree_trans *trans, bool nosort)
        __bch2_trans_paths_to_text(&buf, trans, nosort);
        bch2_trans_updates_to_text(&buf, trans);
 
-       bch2_print_str(trans->c, buf.buf);
+       bch2_print_str(trans->c, KERN_ERR, buf.buf);
        printbuf_exit(&buf);
 }
 
@@ -3121,7 +3121,7 @@ void *__bch2_trans_kmalloc(struct btree_trans *trans, size_t size, unsigned long
 #ifdef CONFIG_BCACHEFS_TRANS_KMALLOC_TRACE
                struct printbuf buf = PRINTBUF;
                bch2_trans_kmalloc_trace_to_text(&buf, &trans->trans_kmalloc_trace);
-               bch2_print_string_as_lines(KERN_ERR, buf.buf);
+               bch2_print_str(c, KERN_ERR, buf.buf);
                printbuf_exit(&buf);
 #endif
        }
index f4f5639443400228e9e8d6b4c10b773e13307619..baa505a9a706416cb0cb3dcd5ed985f8c96fa6d4 100644 (file)
@@ -236,7 +236,7 @@ static noinline int break_cycle(struct lock_graph *g, struct printbuf *cycle,
                        prt_newline(&buf);
                }
 
-               bch2_print_string_as_lines_nonblocking(KERN_ERR, buf.buf);
+               bch2_print_str_nonblocking(g->g->trans->c, KERN_ERR, buf.buf);
                printbuf_exit(&buf);
                BUG();
        }
index 86acf037590ccc529176105c32602e2b17366dce..81ee7ae88a776cf4c0b6d523de02c72fad8ee49f 100644 (file)
@@ -395,7 +395,7 @@ int bch2_scan_for_btree_nodes(struct bch_fs *c)
                printbuf_reset(&buf);
                prt_printf(&buf, "%s: nodes found:\n", __func__);
                found_btree_nodes_to_text(&buf, c, f->nodes);
-               bch2_print_string_as_lines(KERN_INFO, buf.buf);
+               bch2_print_str(c, KERN_INFO, buf.buf);
        }
 
        sort_nonatomic(f->nodes.data, f->nodes.nr, sizeof(f->nodes.data[0]), found_btree_node_cmp_cookie, NULL);
@@ -424,7 +424,7 @@ int bch2_scan_for_btree_nodes(struct bch_fs *c)
                printbuf_reset(&buf);
                prt_printf(&buf, "%s: nodes after merging replicas:\n", __func__);
                found_btree_nodes_to_text(&buf, c, f->nodes);
-               bch2_print_string_as_lines(KERN_INFO, buf.buf);
+               bch2_print_str(c, KERN_INFO, buf.buf);
        }
 
        swap(nodes_heap, f->nodes);
@@ -470,7 +470,7 @@ int bch2_scan_for_btree_nodes(struct bch_fs *c)
                printbuf_reset(&buf);
                prt_printf(&buf, "%s: nodes found after overwrites:\n", __func__);
                found_btree_nodes_to_text(&buf, c, f->nodes);
-               bch2_print_string_as_lines(KERN_INFO, buf.buf);
+               bch2_print_str(c, KERN_INFO, buf.buf);
        } else {
                bch_info(c, "btree node scan found %zu nodes after overwrites", f->nodes.nr);
        }
index 00307356d7c81457323774e68b285eab327e7719..2be7c10fc59cba2ac183db46bfbc25f68217cfb3 100644 (file)
@@ -1807,7 +1807,7 @@ static int bch2_btree_insert_node(struct btree_update *as, struct btree_trans *t
                bch2_btree_update_to_text(&buf, as);
                bch2_btree_path_to_text(&buf, trans, path_idx);
 
-               bch2_print_string_as_lines(KERN_ERR, buf.buf);
+               bch2_print_str(c, KERN_ERR, buf.buf);
                printbuf_exit(&buf);
                bch2_fs_emergency_read_only(c);
                return -EIO;
index 8e64077c15c16c955a203d3b54552980302997a1..36c1e391d4dfc026533b6a7e724a0c611cab354d 100644 (file)
@@ -409,7 +409,7 @@ static int bucket_ref_update_err(struct btree_trans *trans, struct printbuf *buf
        }
 
        if (print || insert)
-               bch2_print_string_as_lines(KERN_ERR, buf->buf);
+               bch2_print_str(c, KERN_ERR, buf->buf);
        return ret;
 }
 
@@ -706,7 +706,7 @@ err:
                                   (u64) p.ec.idx);
                        bch2_bkey_val_to_text(&buf, c, k);
                        __bch2_inconsistent_error(c, &buf);
-                       bch2_print_string_as_lines(KERN_ERR, buf.buf);
+                       bch2_print_str(c, KERN_ERR, buf.buf);
                        printbuf_exit(&buf);
                        return -BCH_ERR_trigger_stripe_pointer;
                }
@@ -976,7 +976,7 @@ static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans,
                                        BCH_RECOVERY_PASS_check_allocations);
 
                if (print)
-                       bch2_print_string_as_lines(KERN_ERR, buf.buf);
+                       bch2_print_str(c, KERN_ERR, buf.buf);
                printbuf_exit(&buf);
                ret = -BCH_ERR_metadata_bucket_inconsistency;
                goto err;
index b211c97238aba9a80c48f648b1911d56475d0c57..c3034338f9e4236c101fb447455eaf927d1749f5 100644 (file)
@@ -358,7 +358,7 @@ restart_drop_extra_replicas:
                        prt_str(&buf, "\nnew: ");
                        bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(insert));
 
-                       bch2_print_string_as_lines(KERN_ERR, buf.buf);
+                       bch2_print_str(c, KERN_ERR, buf.buf);
                        printbuf_exit(&buf);
 
                        bch2_fatal_error(c);
index 4627aabd1f1a192d9d066dbc054c54c3f1cf2164..20495062d6e15ec2b6eb2b0d0c1e550e735ff938 100644 (file)
@@ -34,7 +34,7 @@ bool __bch2_inconsistent_error(struct bch_fs *c, struct printbuf *out)
                                   journal_cur_seq(&c->journal));
                return true;
        case BCH_ON_ERROR_panic:
-               bch2_print_string_as_lines_nonblocking(KERN_ERR, out->buf);
+               bch2_print_str(c, KERN_ERR, out->buf);
                panic(bch2_fmt(c, "panic after error"));
                return true;
        default:
@@ -71,7 +71,7 @@ static bool bch2_fs_trans_inconsistent(struct bch_fs *c, struct btree_trans *tra
        if (trans)
                bch2_trans_updates_to_text(&buf, trans);
        bool ret = __bch2_inconsistent_error(c, &buf);
-       bch2_print_string_as_lines_nonblocking(KERN_ERR, buf.buf);
+       bch2_print_str_nonblocking(c, KERN_ERR, buf.buf);
 
        printbuf_exit(&buf);
        return ret;
@@ -121,7 +121,7 @@ int bch2_fs_topology_error(struct bch_fs *c, const char *fmt, ...)
        va_end(args);
 
        int ret = __bch2_topology_error(c, &buf);
-       bch2_print_string_as_lines(KERN_ERR, buf.buf);
+       bch2_print_str(c, KERN_ERR, buf.buf);
 
        printbuf_exit(&buf);
        return ret;
@@ -328,7 +328,7 @@ static int do_fsck_ask_yn(struct bch_fs *c,
        if (bch2_fs_stdio_redirect(c))
                bch2_print(c, "%s", question->buf);
        else
-               bch2_print_string_as_lines(KERN_ERR, question->buf);
+               bch2_print_str(c, KERN_ERR, question->buf);
 
        int ask = bch2_fsck_ask_yn(c, trans);
 
@@ -565,7 +565,7 @@ print:
                if (bch2_fs_stdio_redirect(c))
                        bch2_print(c, "%s", out->buf);
                else
-                       bch2_print_string_as_lines(KERN_ERR, out->buf);
+                       bch2_print_str(c, KERN_ERR, out->buf);
        }
 
        if (s)
index b81117b51c6934d55e7ca4b50941e71a901744ce..7200ec00128d28195386f4c8e9cc94f55f7d225c 100644 (file)
@@ -153,7 +153,7 @@ void __bch2_i_sectors_acct(struct bch_fs *c, struct bch_inode_info *inode,
 
                bool print = bch2_count_fsck_err(c, vfs_inode_i_blocks_underflow, &buf);
                if (print)
-                       bch2_print_str(c, buf.buf);
+                       bch2_print_str(c, KERN_ERR, buf.buf);
                printbuf_exit(&buf);
 
                if (sectors < 0)
@@ -527,7 +527,7 @@ int bchfs_truncate(struct mnt_idmap *idmap,
 
                bool print = bch2_count_fsck_err(c, vfs_inode_i_blocks_not_zero_at_truncate, &buf);
                if (print)
-                       bch2_print_str(c, buf.buf);
+                       bch2_print_str(c, KERN_ERR, buf.buf);
                printbuf_exit(&buf);
        }
 
index c738ae6fd9a53073e9cd6f4ef85040a7f78bbe06..38086c1a8e2815fd7f1b0625b2096577c736f60f 100644 (file)
@@ -265,7 +265,7 @@ static inline int bch2_extent_update_i_size_sectors(struct btree_trans *trans,
 
                        bool print = bch2_count_fsck_err(c, inode_i_sectors_underflow, &buf);
                        if (print)
-                               bch2_print_str(c, buf.buf);
+                               bch2_print_str(c, KERN_ERR, buf.buf);
                        printbuf_exit(&buf);
 
                        if (i_sectors_delta < 0)
index a51ad32931b895ef1b114902535b7b6f1ea83c32..5442d526a4483eb5c63c06dc2ba278dc877d0833 100644 (file)
@@ -173,7 +173,7 @@ journal_error_check_stuck(struct journal *j, int error, unsigned flags)
        spin_unlock(&j->lock);
        prt_printf(&buf, bch2_fmt(c, "Journal stuck! Hava a pre-reservation but journal full (error %s)"),
                                  bch2_err_str(error));
-       bch2_print_string_as_lines(KERN_ERR, buf.buf);
+       bch2_print_str(c, KERN_ERR, buf.buf);
 
        printbuf_reset(&buf);
        bch2_journal_pins_to_text(&buf, j);
@@ -743,7 +743,7 @@ int bch2_journal_res_get_slowpath(struct journal *j, struct journal_res *res,
 
        struct printbuf buf = PRINTBUF;
        bch2_journal_debug_to_text(&buf, j);
-       bch2_print_string_as_lines(KERN_ERR, buf.buf);
+       bch2_print_str(c, KERN_ERR, buf.buf);
        prt_printf(&buf, bch2_fmt(c, "Journal stuck? Waited for 10 seconds, err %s"), bch2_err_str(ret));
        printbuf_exit(&buf);
 
index ded18a94ed021e58a07a0aa86f189db33a6b5894..28fa381cd58924274941c9228c3b3b4c912f2b25 100644 (file)
@@ -2107,7 +2107,7 @@ CLOSURE_CALLBACK(bch2_journal_write)
                                          le64_to_cpu(w->data->seq),
                                          vstruct_sectors(w->data, c->block_bits),
                                          bch2_err_str(ret));
-               bch2_print_string_as_lines(KERN_ERR, buf.buf);
+               bch2_print_str(c, KERN_ERR, buf.buf);
                printbuf_exit(&buf);
        }
        if (ret)
index 946428daeecc57c6bf3d9b4852312308f5b0af3b..de1a14c4bc3c38c62428dc8a594be823b36938be 100644 (file)
@@ -163,7 +163,7 @@ int bch2_run_explicit_recovery_pass(struct bch_fs *c,
        int ret = bch2_run_explicit_recovery_pass_printbuf(c, &buf, pass);
 
        if (len != buf.pos)
-               bch2_print_string_as_lines(KERN_NOTICE, buf.buf);
+               bch2_print_str(c, KERN_NOTICE, buf.buf);
        printbuf_exit(&buf);
        return ret;
 }
index f776b00c3cc0301cd0cb96c90fa1135fa591e08e..77809ee23c455dc1a9bfcccd1f5a7deb36c7614a 100644 (file)
@@ -24,7 +24,7 @@ int bch2_dev_missing_bkey(struct bch_fs *c, struct bkey_s_c k, unsigned dev)
                                                 BCH_RECOVERY_PASS_check_allocations);
 
        if (print)
-               bch2_print_string_as_lines(KERN_ERR, buf.buf);
+               bch2_print_str(c, KERN_ERR, buf.buf);
        printbuf_exit(&buf);
        return ret;
 }
index 65aab7ea182e23fa4f72fceb0dae94b3d69d6c07..b34c91dd51b15ce6f1f76484535de40ea09817dd 100644 (file)
@@ -84,7 +84,8 @@ const char * const bch2_fs_flag_strs[] = {
        NULL
 };
 
-void bch2_print_str(struct bch_fs *c, const char *str)
+static void __bch2_print_str(struct bch_fs *c, const char *prefix,
+                            const char *str, bool nonblocking)
 {
 #ifdef __KERNEL__
        struct stdio_redirect *stdio = bch2_fs_stdio_redirect(c);
@@ -94,7 +95,17 @@ void bch2_print_str(struct bch_fs *c, const char *str)
                return;
        }
 #endif
-       bch2_print_string_as_lines(KERN_ERR, str);
+       bch2_print_string_as_lines(KERN_ERR, str, nonblocking);
+}
+
+void bch2_print_str(struct bch_fs *c, const char *prefix, const char *str)
+{
+       __bch2_print_str(c, prefix, str, false);
+}
+
+void bch2_print_str_nonblocking(struct bch_fs *c, const char *prefix, const char *str)
+{
+       __bch2_print_str(c, prefix, str, true);
 }
 
 __printf(2, 0)
index 87af551692f44f946f7543a17ac80eb6521b79ab..6e5d7fc265bd2328c4242de5894bc312f70c4b08 100644 (file)
@@ -252,8 +252,8 @@ void bch2_prt_u64_base2(struct printbuf *out, u64 v)
        bch2_prt_u64_base2_nbits(out, v, fls64(v) ?: 1);
 }
 
-static void __bch2_print_string_as_lines(const char *prefix, const char *lines,
-                                        bool nonblocking)
+void bch2_print_string_as_lines(const char *prefix, const char *lines,
+                               bool nonblocking)
 {
        bool locked = false;
        const char *p;
@@ -281,16 +281,6 @@ static void __bch2_print_string_as_lines(const char *prefix, const char *lines,
                console_unlock();
 }
 
-void bch2_print_string_as_lines(const char *prefix, const char *lines)
-{
-       return __bch2_print_string_as_lines(prefix, lines, false);
-}
-
-void bch2_print_string_as_lines_nonblocking(const char *prefix, const char *lines)
-{
-       return __bch2_print_string_as_lines(prefix, lines, true);
-}
-
 int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *task, unsigned skipnr,
                        gfp_t gfp)
 {
index ccc1cf699c4bf16f83b05936ed7fd38fba8df79d..50f7197c67fce9b3ca5d8fb13334304040cf8990 100644 (file)
@@ -212,8 +212,7 @@ u64 bch2_read_flag_list(const char *, const char * const[]);
 void bch2_prt_u64_base2_nbits(struct printbuf *, u64, unsigned);
 void bch2_prt_u64_base2(struct printbuf *, u64);
 
-void bch2_print_string_as_lines(const char *prefix, const char *lines);
-void bch2_print_string_as_lines_nonblocking(const char *prefix, const char *lines);
+void bch2_print_string_as_lines(const char *, const char *, bool);
 
 typedef DARRAY(unsigned long) bch_stacktrace;
 int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *, unsigned, gfp_t);