bcachefs: Simplify bch2_count_fsck_err()
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 15 Apr 2025 17:55:16 +0000 (13:55 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:17 +0000 (20:14 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/buckets.c
fs/bcachefs/error.c
fs/bcachefs/error.h
fs/bcachefs/fs-io.c
fs/bcachefs/io_write.c

index ffe957602ccafb0fa68f79f1720828539f4eb5f2..8e64077c15c16c955a203d3b54552980302997a1 100644 (file)
@@ -392,29 +392,23 @@ static int bucket_ref_update_err(struct btree_trans *trans, struct printbuf *buf
                                 struct bkey_s_c k, bool insert, enum bch_sb_error_id id)
 {
        struct bch_fs *c = trans->c;
-       bool repeat = false, print = true, suppress = false;
 
        prt_printf(buf, "\nwhile marking ");
        bch2_bkey_val_to_text(buf, c, k);
        prt_newline(buf);
 
-       __bch2_count_fsck_err(c, id, buf->buf, &repeat, &print, &suppress);
+       bool print = __bch2_count_fsck_err(c, id, buf);
 
        int ret = bch2_run_explicit_recovery_pass_printbuf(c, buf,
                                        BCH_RECOVERY_PASS_check_allocations);
 
        if (insert) {
-               print = true;
-               suppress = false;
-
                bch2_trans_updates_to_text(buf, trans);
                __bch2_inconsistent_error(c, buf);
                ret = -BCH_ERR_bucket_ref_update;
        }
 
-       if (suppress)
-               prt_printf(buf, "Ratelimiting new instances of previous error\n");
-       if (print)
+       if (print || insert)
                bch2_print_string_as_lines(KERN_ERR, buf->buf);
        return ret;
 }
@@ -976,15 +970,11 @@ static int __bch2_trans_mark_metadata_bucket(struct btree_trans *trans,
                           bch2_data_type_str(type),
                           bch2_data_type_str(type));
 
-               bool repeat = false, print = true, suppress = false;
-               bch2_count_fsck_err(c, bucket_metadata_type_mismatch, buf.buf,
-                                   &repeat, &print, &suppress);
+               bool print = bch2_count_fsck_err(c, bucket_metadata_type_mismatch, &buf);
 
                bch2_run_explicit_recovery_pass_printbuf(c, &buf,
                                        BCH_RECOVERY_PASS_check_allocations);
 
-               if (suppress)
-                       prt_printf(&buf, "Ratelimiting new instances of previous error\n");
                if (print)
                        bch2_print_string_as_lines(KERN_ERR, buf.buf);
                printbuf_exit(&buf);
index faeadffa11038ebe3f40ef78f9257c8273e5906d..4627aabd1f1a192d9d066dbc054c54c3f1cf2164 100644 (file)
@@ -376,15 +376,21 @@ static struct fsck_err_state *count_fsck_err_locked(struct bch_fs *c,
        return s;
 }
 
-void __bch2_count_fsck_err(struct bch_fs *c,
-                          enum bch_sb_error_id id, const char *msg,
-                          bool *repeat, bool *print, bool *suppress)
+bool __bch2_count_fsck_err(struct bch_fs *c,
+                          enum bch_sb_error_id id, struct printbuf *msg)
 {
        bch2_sb_error_count(c, id);
 
        mutex_lock(&c->fsck_error_msgs_lock);
-       count_fsck_err_locked(c, id, msg, repeat, print, suppress);
+       bool print = true, repeat = false, suppress = false;
+
+       count_fsck_err_locked(c, id, msg->buf, &repeat, &print, &suppress);
        mutex_unlock(&c->fsck_error_msgs_lock);
+
+       if (suppress)
+               prt_printf(msg, "Ratelimiting new instances of previous error\n");
+
+       return print && !repeat;
 }
 
 int __bch2_fsck_err(struct bch_fs *c,
index 4a364fd44abe0eed989dafaa1d3b0799636c9a5b..0b3ede1c20158badc00dacbef66f7128a1b0e7df 100644 (file)
@@ -76,9 +76,7 @@ struct fsck_err_state {
 
 #define fsck_err_count(_c, _err)       bch2_sb_err_count(_c, BCH_FSCK_ERR_##_err)
 
-void __bch2_count_fsck_err(struct bch_fs *,
-                          enum bch_sb_error_id, const char *,
-                          bool *, bool *, bool *);
+bool __bch2_count_fsck_err(struct bch_fs *, enum bch_sb_error_id, struct printbuf *);
 #define bch2_count_fsck_err(_c, _err, ...)                             \
        __bch2_count_fsck_err(_c, BCH_FSCK_ERR_##_err, __VA_ARGS__)
 
index 9657144666b8b278ed9598027851e3baa031b3bc..b81117b51c6934d55e7ca4b50941e71a901744ce 100644 (file)
@@ -151,8 +151,7 @@ void __bch2_i_sectors_acct(struct bch_fs *c, struct bch_inode_info *inode,
                           inode->v.i_ino, (u64) inode->v.i_blocks, sectors,
                           inode->ei_inode.bi_sectors);
 
-               bool repeat = false, print = false, suppress = false;
-               bch2_count_fsck_err(c, vfs_inode_i_blocks_underflow, buf.buf, &repeat, &print, &suppress);
+               bool print = bch2_count_fsck_err(c, vfs_inode_i_blocks_underflow, &buf);
                if (print)
                        bch2_print_str(c, buf.buf);
                printbuf_exit(&buf);
@@ -526,9 +525,7 @@ int bchfs_truncate(struct mnt_idmap *idmap,
                           inode->v.i_ino, (u64) inode->v.i_blocks,
                           inode->ei_inode.bi_sectors);
 
-               bool repeat = false, print = false, suppress = false;
-               bch2_count_fsck_err(c, vfs_inode_i_blocks_not_zero_at_truncate, buf.buf,
-                                   &repeat, &print, &suppress);
+               bool print = bch2_count_fsck_err(c, vfs_inode_i_blocks_not_zero_at_truncate, &buf);
                if (print)
                        bch2_print_str(c, buf.buf);
                printbuf_exit(&buf);
index 401347e135b7c76a684869ad99195aabb1a18837..c738ae6fd9a53073e9cd6f4ef85040a7f78bbe06 100644 (file)
@@ -263,9 +263,7 @@ static inline int bch2_extent_update_i_size_sectors(struct btree_trans *trans,
                        prt_printf(&buf, "inode %llu i_sectors underflow: %lli + %lli < 0",
                                   extent_iter->pos.inode, bi_sectors, i_sectors_delta);
 
-                       bool repeat = false, print = false, suppress = false;
-                       bch2_count_fsck_err(c, inode_i_sectors_underflow, buf.buf,
-                                           &repeat, &print, &suppress);
+                       bool print = bch2_count_fsck_err(c, inode_i_sectors_underflow, &buf);
                        if (print)
                                bch2_print_str(c, buf.buf);
                        printbuf_exit(&buf);