bcachefs: bch2_print_string_as_lines()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 25 Sep 2022 20:43:55 +0000 (16:43 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:41 +0000 (17:09 -0400)
This adds a helper for printing a large buffer one line at a time, to
avoid the 1k printk limit.

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

index 237e5c0afffae301963942de611f5fc72097d2de..d58e29acfda3998be9ea699d42ac68136c9bae8e 100644 (file)
@@ -1334,7 +1334,7 @@ void bch2_dump_trans_updates(struct btree_trans *trans)
        struct printbuf buf = PRINTBUF;
 
        bch2_trans_updates_to_text(&buf, trans);
-       bch_err(trans->c, "%s", buf.buf);
+       bch2_print_string_as_lines(KERN_ERR, buf.buf);
        printbuf_exit(&buf);
 }
 
@@ -1382,11 +1382,10 @@ void __bch2_dump_trans_paths_updates(struct btree_trans *trans, bool nosort)
        struct printbuf buf = PRINTBUF;
 
        __bch2_trans_paths_to_text(&buf, trans, nosort);
+       bch2_trans_updates_to_text(&buf, trans);
 
-       printk(KERN_ERR "%s", buf.buf);
+       bch2_print_string_as_lines(KERN_ERR, buf.buf);
        printbuf_exit(&buf);
-
-       bch2_dump_trans_updates(trans);
 }
 
 noinline __cold
index 61cd44c5a6b4a0af73a9189ea8810d16f83c2261..477c260de50b375953bb13041b31e19e85729da5 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <linux/bio.h>
 #include <linux/blkdev.h>
+#include <linux/console.h>
 #include <linux/ctype.h>
 #include <linux/debugfs.h>
 #include <linux/freezer.h>
@@ -244,6 +245,26 @@ void bch2_prt_u64_binary(struct printbuf *out, u64 v, unsigned nr_bits)
                prt_char(out, '0' + ((v >> --nr_bits) & 1));
 }
 
+void bch2_print_string_as_lines(const char *prefix, const char *lines)
+{
+       const char *p;
+
+       if (!lines) {
+               printk("%s (null)\n", prefix);
+               return;
+       }
+
+       console_lock();
+       while (1) {
+               p = strchrnul(lines, '\n');
+               printk("%s%.*s\n", prefix, (int) (p - lines), lines);
+               if (!*p)
+                       break;
+               lines = p + 1;
+       }
+       console_unlock();
+}
+
 /* time stats: */
 
 #ifndef CONFIG_BCACHEFS_NO_LATENCY_ACCT
index 192d8b53f2ca42139a4d2df267128b8870cb1156..a16f8bb9d4152de988e3b6c1a790f68a86bca9a0 100644 (file)
@@ -382,6 +382,8 @@ u64 bch2_read_flag_list(char *, const char * const[]);
 
 void bch2_prt_u64_binary(struct printbuf *, u64, unsigned);
 
+void bch2_print_string_as_lines(const char *prefix, const char *lines);
+
 #define NR_QUANTILES   15
 #define QUANTILE_IDX(i)        inorder_to_eytzinger0(i, NR_QUANTILES)
 #define QUANTILE_FIRST eytzinger0_first(NR_QUANTILES)