bcachefs: Improve bch2_fatal_error()
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 18 Mar 2024 01:51:19 +0000 (21:51 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 18 Mar 2024 04:24:24 +0000 (00:24 -0400)
error messages should always include __func__

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
15 files changed:
fs/bcachefs/alloc_background.c
fs/bcachefs/btree_io.c
fs/bcachefs/btree_key_cache.c
fs/bcachefs/btree_update_interior.c
fs/bcachefs/btree_write_buffer.c
fs/bcachefs/buckets.c
fs/bcachefs/debug.c
fs/bcachefs/ec.c
fs/bcachefs/error.h
fs/bcachefs/fs.c
fs/bcachefs/journal_io.c
fs/bcachefs/logged_ops.c
fs/bcachefs/movinggc.c
fs/bcachefs/super-io.c
fs/bcachefs/super.c

index 720b10f43a6045a3313972077293c4ff9e67e568..893e38f9db807f4c6d819a470339b6af97f85804 100644 (file)
@@ -853,7 +853,7 @@ int bch2_trigger_alloc(struct btree_trans *trans,
                                        bucket_journal_seq);
                        if (ret) {
                                bch2_fs_fatal_error(c,
-                                       "error setting bucket_needs_journal_commit: %i", ret);
+                                       "setting bucket_needs_journal_commit: %s", bch2_err_str(ret));
                                return ret;
                        }
                }
index 44856f018adf6394e041c840d860645c22921993..34df8ccc5fecc2bfbad874e77f53fa1f5f068251 100644 (file)
@@ -1066,7 +1066,7 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
 
                        ret = bset_encrypt(c, i, b->written << 9);
                        if (bch2_fs_fatal_err_on(ret, c,
-                                       "error decrypting btree node: %i", ret))
+                                       "decrypting btree node: %s", bch2_err_str(ret)))
                                goto fsck_err;
 
                        btree_err_on(btree_node_type_is_extents(btree_node_type(b)) &&
@@ -1107,7 +1107,7 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
 
                        ret = bset_encrypt(c, i, b->written << 9);
                        if (bch2_fs_fatal_err_on(ret, c,
-                                       "error decrypting btree node: %i\n", ret))
+                                       "decrypting btree node: %s", bch2_err_str(ret)))
                                goto fsck_err;
 
                        sectors = vstruct_sectors(bne, c->block_bits);
@@ -1874,8 +1874,8 @@ out:
        return;
 err:
        set_btree_node_noevict(b);
-       if (!bch2_err_matches(ret, EROFS))
-               bch2_fs_fatal_error(c, "fatal error writing btree node: %s", bch2_err_str(ret));
+       bch2_fs_fatal_err_on(!bch2_err_matches(ret, EROFS), c,
+                            "writing btree node: %s", bch2_err_str(ret));
        goto out;
 }
 
@@ -2131,7 +2131,7 @@ do_write:
 
        ret = bset_encrypt(c, i, b->written << 9);
        if (bch2_fs_fatal_err_on(ret, c,
-                       "error encrypting btree node: %i\n", ret))
+                       "encrypting btree node: %s", bch2_err_str(ret)))
                goto err;
 
        nonce = btree_nonce(i, b->written << 9);
index 8a71d43444b9425808ff1db86ec0fd296c9900ff..581edcb0911bfa39e9ec6242686bd213c47f352c 100644 (file)
@@ -676,7 +676,7 @@ static int btree_key_cache_flush_pos(struct btree_trans *trans,
                             !bch2_err_matches(ret, BCH_ERR_transaction_restart) &&
                             !bch2_err_matches(ret, BCH_ERR_journal_reclaim_would_deadlock) &&
                             !bch2_journal_error(j), c,
-                            "error flushing key cache: %s", bch2_err_str(ret));
+                            "flushing key cache: %s", bch2_err_str(ret));
        if (ret)
                goto out;
 
index ea768c2bf8e1b24d47d9b7afbb706d486595c8a8..f44776b8006d190dfc4e2d97c844fbe79cba87d0 100644 (file)
@@ -646,7 +646,7 @@ static void btree_update_nodes_written(struct btree_update *as)
        bch2_trans_unlock(trans);
 
        bch2_fs_fatal_err_on(ret && !bch2_journal_error(&c->journal), c,
-                            "%s(): error %s", __func__, bch2_err_str(ret));
+                            "%s", bch2_err_str(ret));
 err:
        if (as->b) {
 
@@ -1193,7 +1193,8 @@ bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path,
 err:
        bch2_btree_update_free(as, trans);
        if (!bch2_err_matches(ret, ENOSPC) &&
-           !bch2_err_matches(ret, EROFS))
+           !bch2_err_matches(ret, EROFS) &&
+           ret != -BCH_ERR_journal_reclaim_would_deadlock)
                bch_err_fn_ratelimited(c, ret);
        return ERR_PTR(ret);
 }
index b77e7b382b66660f8b02925c13657118dc28fed1..5cbad8445782c4006074365c13551b1c38b57849 100644 (file)
@@ -378,7 +378,7 @@ static int bch2_btree_write_buffer_flush_locked(struct btree_trans *trans)
                }
        }
 err:
-       bch2_fs_fatal_err_on(ret, c, "%s: insert error %s", __func__, bch2_err_str(ret));
+       bch2_fs_fatal_err_on(ret, c, "%s", bch2_err_str(ret));
        trace_write_buffer_flush(trans, wb->flushing.keys.nr, skipped, fast, 0);
        bch2_journal_pin_drop(j, &wb->flushing.pin);
        wb->flushing.keys.nr = 0;
index c2f46b267b3ad50c796690320f0a700411940931..96edf2c34d433d1c1ad41ec8da0c77b8d40afe9f 100644 (file)
@@ -990,8 +990,8 @@ static int __trigger_extent(struct btree_trans *trans,
                                ret = !gc
                                        ? bch2_update_cached_sectors_list(trans, p.ptr.dev, disk_sectors)
                                        : update_cached_sectors(c, k, p.ptr.dev, disk_sectors, 0, true);
-                               bch2_fs_fatal_err_on(ret && gc, c, "%s(): no replicas entry while updating cached sectors",
-                                                    __func__);
+                               bch2_fs_fatal_err_on(ret && gc, c, "%s: no replicas entry while updating cached sectors",
+                                                    bch2_err_str(ret));
                                if (ret)
                                        return ret;
                        }
@@ -1020,7 +1020,7 @@ static int __trigger_extent(struct btree_trans *trans,
                        struct printbuf buf = PRINTBUF;
 
                        bch2_bkey_val_to_text(&buf, c, k);
-                       bch2_fs_fatal_error(c, "%s(): no replicas entry for %s", __func__, buf.buf);
+                       bch2_fs_fatal_error(c, ": no replicas entry for %s", buf.buf);
                        printbuf_exit(&buf);
                }
                if (ret)
index b1f147e6be4d5cdd0ab491932db9c625b763e29e..208ce6f0fc4317d561582bae51785da2c016a1cd 100644 (file)
@@ -170,7 +170,7 @@ void __bch2_btree_verify(struct bch_fs *c, struct btree *b)
                struct printbuf buf = PRINTBUF;
 
                bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(&b->key));
-               bch2_fs_fatal_error(c, "btree node verify failed for : %s\n", buf.buf);
+               bch2_fs_fatal_error(c, ": btree node verify failed for: %s\n", buf.buf);
                printbuf_exit(&buf);
        }
 out:
index b98e2c2b8bf06f59fa70cfe23873e51529a917b8..082075244e16aedc824249b239ecec6efb1a07fa 100644 (file)
@@ -448,7 +448,7 @@ int bch2_trigger_stripe(struct btree_trans *trans,
                        struct printbuf buf = PRINTBUF;
 
                        bch2_bkey_val_to_text(&buf, c, new);
-                       bch2_fs_fatal_error(c, "no replicas entry for %s", buf.buf);
+                       bch2_fs_fatal_error(c, "no replicas entry for %s", buf.buf);
                        printbuf_exit(&buf);
                        return ret;
                }
@@ -1868,10 +1868,10 @@ static int __bch2_ec_stripe_head_reuse(struct btree_trans *trans, struct ec_stri
                return -BCH_ERR_stripe_alloc_blocked;
 
        ret = get_stripe_key_trans(trans, idx, &h->s->existing_stripe);
+       bch2_fs_fatal_err_on(ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart), c,
+                            "reading stripe key: %s", bch2_err_str(ret));
        if (ret) {
                bch2_stripe_close(c, h->s);
-               if (!bch2_err_matches(ret, BCH_ERR_transaction_restart))
-                       bch2_fs_fatal_error(c, "error reading stripe key: %s", bch2_err_str(ret));
                return ret;
        }
 
index 94491190e09e9d5085ca1ef87c5764c4192d6a24..ae1d6674c512d44521379f21d5872b2b79993f57 100644 (file)
@@ -191,9 +191,9 @@ do {                                                                        \
 
 void bch2_fatal_error(struct bch_fs *);
 
-#define bch2_fs_fatal_error(c, ...)                                    \
+#define bch2_fs_fatal_error(c, _msg, ...)                              \
 do {                                                                   \
-       bch_err(c, __VA_ARGS__);                                        \
+       bch_err(c, "%s(): fatal error " _msg, __func__, ##__VA_ARGS__); \
        bch2_fatal_error(c);                                            \
 } while (0)
 
index 3f073845bbd77391306a55c6ac7a87771f7e5890..0ccee05f6887b3b0aedf1e7c11f82665c7d38ba5 100644 (file)
@@ -108,7 +108,8 @@ retry:
                goto retry;
 
        bch2_fs_fatal_err_on(bch2_err_matches(ret, ENOENT), c,
-                            "inode %u:%llu not found when updating",
+                            "%s: inode %u:%llu not found when updating",
+                            bch2_err_str(ret),
                             inode_inum(inode).subvol,
                             inode_inum(inode).inum);
 
index a3b66a3c76dd5b9fd01f2aea599335b2daa75967..725fcf46f6312c267c2a7c05f1eaa6aed5fb83e7 100644 (file)
@@ -1082,9 +1082,7 @@ reread:
                ret = bch2_encrypt(c, JSET_CSUM_TYPE(j), journal_nonce(j),
                             j->encrypted_start,
                             vstruct_end(j) - (void *) j->encrypted_start);
-               bch2_fs_fatal_err_on(ret, c,
-                               "error decrypting journal entry: %s",
-                               bch2_err_str(ret));
+               bch2_fs_fatal_err_on(ret, c, "decrypting journal entry: %s", bch2_err_str(ret));
 
                mutex_lock(&jlist->lock);
                ret = journal_entry_add(c, ca, (struct journal_ptr) {
@@ -1820,7 +1818,8 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
                        jset_entry_for_each_key(i, k) {
                                ret = bch2_journal_key_to_wb(c, &wb, i->btree_id, k);
                                if (ret) {
-                                       bch2_fs_fatal_error(c, "-ENOMEM flushing journal keys to btree write buffer");
+                                       bch2_fs_fatal_error(c, "flushing journal keys to btree write buffer: %s",
+                                                           bch2_err_str(ret));
                                        bch2_journal_keys_to_write_buffer_end(c, &wb);
                                        return ret;
                                }
@@ -1857,7 +1856,7 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
        bytes   = vstruct_bytes(jset);
 
        if (sectors > w->sectors) {
-               bch2_fs_fatal_error(c, "aieeee! journal write overran available space, %zu > %u (extra %u reserved %u/%u)",
+               bch2_fs_fatal_error(c, ": journal write overran available space, %zu > %u (extra %u reserved %u/%u)",
                                    vstruct_bytes(jset), w->sectors << 9,
                                    u64s, w->u64s_reserved, j->entry_u64s_reserved);
                return -EINVAL;
@@ -1885,8 +1884,7 @@ static int bch2_journal_write_prep(struct journal *j, struct journal_buf *w)
        ret = bch2_encrypt(c, JSET_CSUM_TYPE(jset), journal_nonce(jset),
                    jset->encrypted_start,
                    vstruct_end(jset) - (void *) jset->encrypted_start);
-       if (bch2_fs_fatal_err_on(ret, c,
-                       "error decrypting journal entry: %i", ret))
+       if (bch2_fs_fatal_err_on(ret, c, "decrypting journal entry: %s", bch2_err_str(ret)))
                return ret;
 
        jset->csum = csum_vstruct(c, JSET_CSUM_TYPE(jset),
index ad598105c587cc0354773b85461293099bbbe36d..9fac838d123e8e40fb836d895afccde634f2d54c 100644 (file)
@@ -101,8 +101,8 @@ void bch2_logged_op_finish(struct btree_trans *trans, struct bkey_i *k)
                struct printbuf buf = PRINTBUF;
 
                bch2_bkey_val_to_text(&buf, c, bkey_i_to_s_c(k));
-               bch2_fs_fatal_error(c, "%s: error deleting logged operation %s: %s",
-                                    __func__, buf.buf, bch2_err_str(ret));
+               bch2_fs_fatal_error(c, "deleting logged operation %s: %s",
+                                   buf.buf, bch2_err_str(ret));
                printbuf_exit(&buf);
        }
 }
index 69e06a84dad4094847e8c737860d5acc37b25d79..0d2b82d8d11f39efe6a65bee8678e8f2496bdbcf 100644 (file)
@@ -155,8 +155,7 @@ static int bch2_copygc_get_buckets(struct moving_context *ctxt,
        if (bch2_err_matches(ret, EROFS))
                return ret;
 
-       if (bch2_fs_fatal_err_on(ret, c, "%s: error %s from bch2_btree_write_buffer_tryflush()",
-                                __func__, bch2_err_str(ret)))
+       if (bch2_fs_fatal_err_on(ret, c, "%s: from bch2_btree_write_buffer_tryflush()", bch2_err_str(ret)))
                return ret;
 
        ret = for_each_btree_key_upto(trans, iter, BTREE_ID_lru,
index 010daebf987b5b843e217f857279bcd77dd438fe..647cbaf1ab69669a86aaa7bfc2f8a8a652f331d6 100644 (file)
@@ -985,7 +985,7 @@ int bch2_write_super(struct bch_fs *c)
                prt_str(&buf, " > ");
                bch2_version_to_text(&buf, bcachefs_metadata_version_current);
                prt_str(&buf, ")");
-               bch2_fs_fatal_error(c, "%s", buf.buf);
+               bch2_fs_fatal_error(c, "%s", buf.buf);
                printbuf_exit(&buf);
                return -BCH_ERR_sb_not_downgraded;
        }
@@ -1005,7 +1005,7 @@ int bch2_write_super(struct bch_fs *c)
 
                if (le64_to_cpu(ca->sb_read_scratch->seq) < ca->disk_sb.seq) {
                        bch2_fs_fatal_error(c,
-                               "Superblock write was silently dropped! (seq %llu expected %llu)",
+                               "Superblock write was silently dropped! (seq %llu expected %llu)",
                                le64_to_cpu(ca->sb_read_scratch->seq),
                                ca->disk_sb.seq);
                        percpu_ref_put(&ca->io_ref);
@@ -1015,7 +1015,7 @@ int bch2_write_super(struct bch_fs *c)
 
                if (le64_to_cpu(ca->sb_read_scratch->seq) > ca->disk_sb.seq) {
                        bch2_fs_fatal_error(c,
-                               "Superblock modified by another process (seq %llu expected %llu)",
+                               "Superblock modified by another process (seq %llu expected %llu)",
                                le64_to_cpu(ca->sb_read_scratch->seq),
                                ca->disk_sb.seq);
                        percpu_ref_put(&ca->io_ref);
@@ -1066,7 +1066,7 @@ int bch2_write_super(struct bch_fs *c)
                                 !can_mount_with_written ||
                                 (can_mount_without_written &&
                                  !can_mount_with_written), c,
-               "Unable to write superblock to sufficient devices (from %ps)",
+               "Unable to write superblock to sufficient devices (from %ps)",
                (void *) _RET_IP_))
                ret = -1;
 out:
index 1cabdd47e88d5195b183b8f8fcb2a4eaa195f952..1ad6e5cd9476c86f4b905feff6f727b4cdd94a4e 100644 (file)
@@ -87,6 +87,7 @@ const char * const bch2_fs_flag_strs[] = {
        NULL
 };
 
+__printf(2, 0)
 static void bch2_print_maybe_redirect(struct stdio_redirect *stdio, const char *fmt, va_list args)
 {
 #ifdef __KERNEL__