From 9c5d38bba034253dace198e5801dc7bad6fb8c7e Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Thu, 16 Feb 2023 21:02:14 -0500 Subject: [PATCH] bcachefs: Don't print out duplicate fsck errors Signed-off-by: Kent Overstreet --- fs/bcachefs/error.c | 30 ++++++++++++++++++++---------- fs/bcachefs/error.h | 3 ++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/fs/bcachefs/error.c b/fs/bcachefs/error.c index c2882c599896..1dae649ff0e2 100644 --- a/fs/bcachefs/error.c +++ b/fs/bcachefs/error.c @@ -98,7 +98,6 @@ static struct fsck_err_state *fsck_err_get(struct bch_fs *c, const char *fmt) INIT_LIST_HEAD(&s->list); s->fmt = fmt; - s->buf = PRINTBUF; list_add(&s->list, &c->fsck_errors); return s; } @@ -111,9 +110,23 @@ int bch2_fsck_err(struct bch_fs *c, unsigned flags, const char *fmt, ...) struct printbuf buf = PRINTBUF, *out = &buf; int ret = -BCH_ERR_fsck_ignore; + va_start(args, fmt); + prt_vprintf(out, fmt, args); + va_end(args); + mutex_lock(&c->fsck_error_lock); s = fsck_err_get(c, fmt); if (s) { + if (s->last_msg && !strcmp(buf.buf, s->last_msg)) { + ret = s->ret; + mutex_unlock(&c->fsck_error_lock); + printbuf_exit(&buf); + return ret; + } + + kfree(s->last_msg); + s->last_msg = kstrdup(buf.buf, GFP_KERNEL); + if (c->opts.ratelimit_errors && !(flags & FSCK_NO_RATELIMIT) && s->nr >= FSCK_ERR_RATELIMIT_NR) { @@ -123,8 +136,6 @@ int bch2_fsck_err(struct bch_fs *c, unsigned flags, const char *fmt, ...) print = false; } - printbuf_reset(&s->buf); - out = &s->buf; s->nr++; } @@ -133,10 +144,6 @@ int bch2_fsck_err(struct bch_fs *c, unsigned flags, const char *fmt, ...) prt_printf(out, bch2_log_msg(c, "")); #endif - va_start(args, fmt); - prt_vprintf(out, fmt, args); - va_end(args); - if (test_bit(BCH_FS_FSCK_DONE, &c->flags)) { if (c->opts.errors != BCH_ON_ERROR_continue || !(flags & (FSCK_CAN_FIX|FSCK_CAN_IGNORE))) { @@ -190,6 +197,9 @@ int bch2_fsck_err(struct bch_fs *c, unsigned flags, const char *fmt, ...) else if (suppressing) bch_err(c, "Ratelimiting new instances of previous error"); + if (s) + s->ret = ret; + mutex_unlock(&c->fsck_error_lock); printbuf_exit(&buf); @@ -214,11 +224,11 @@ void bch2_flush_fsck_errs(struct bch_fs *c) mutex_lock(&c->fsck_error_lock); list_for_each_entry_safe(s, n, &c->fsck_errors, list) { - if (s->ratelimited) - bch_err(c, "Saw %llu errors like:\n %s", s->nr, s->buf.buf); + if (s->ratelimited && s->last_msg) + bch_err(c, "Saw %llu errors like:\n %s", s->nr, s->last_msg); list_del(&s->list); - printbuf_exit(&s->buf); + kfree(s->last_msg); kfree(s); } diff --git a/fs/bcachefs/error.h b/fs/bcachefs/error.h index 9991879dfbff..91c7e4ee8f72 100644 --- a/fs/bcachefs/error.h +++ b/fs/bcachefs/error.h @@ -103,7 +103,8 @@ struct fsck_err_state { const char *fmt; u64 nr; bool ratelimited; - struct printbuf buf; + int ret; + char *last_msg; }; #define FSCK_CAN_FIX (1 << 0)