From a8f35428430446d8c9e871b36ab2b49c0a9daec7 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 25 Sep 2022 16:43:55 -0400 Subject: [PATCH] bcachefs: bch2_print_string_as_lines() 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 --- fs/bcachefs/btree_iter.c | 7 +++---- fs/bcachefs/util.c | 21 +++++++++++++++++++++ fs/bcachefs/util.h | 2 ++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index 237e5c0afffa..d58e29acfda3 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -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 diff --git a/fs/bcachefs/util.c b/fs/bcachefs/util.c index 61cd44c5a6b4..477c260de50b 100644 --- a/fs/bcachefs/util.c +++ b/fs/bcachefs/util.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -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 diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h index 192d8b53f2ca..a16f8bb9d415 100644 --- a/fs/bcachefs/util.h +++ b/fs/bcachefs/util.h @@ -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)