From df6a24f81aa29a0e844afb53f7d5bc8989cdbac3 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sat, 22 Oct 2022 15:10:28 -0400 Subject: [PATCH] bcachefs: Make error messages more uniform Use __func__ in error messages that refer to function name, and do so more uniformly - suggested by checkpatch.pl Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_update_interior.c | 6 ++-- fs/bcachefs/buckets.c | 8 +++-- fs/bcachefs/fsck.c | 26 ++++++++-------- fs/bcachefs/tests.c | 47 ++++++++++++++--------------- 4 files changed, 43 insertions(+), 44 deletions(-) diff --git a/fs/bcachefs/btree_update_interior.c b/fs/bcachefs/btree_update_interior.c index 30b7c46cb86b..0150943074fa 100644 --- a/fs/bcachefs/btree_update_interior.c +++ b/fs/bcachefs/btree_update_interior.c @@ -665,7 +665,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, - "error %i in btree_update_nodes_written()", ret); + "%s(): error %s", __func__, bch2_err_str(ret)); err: if (as->b) { struct btree_path *path; @@ -1839,10 +1839,10 @@ int __bch2_foreground_maybe_merge(struct btree_trans *trans, bch2_bpos_to_text(&buf1, prev->data->max_key); bch2_bpos_to_text(&buf2, next->data->min_key); bch_err(c, - "btree topology error in btree merge:\n" + "%s(): btree topology error:\n" " prev ends at %s\n" " next starts at %s", - buf1.buf, buf2.buf); + __func__, buf1.buf, buf2.buf); printbuf_exit(&buf1); printbuf_exit(&buf2); bch2_topology_error(c); diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c index 17a1e4767077..fffe59f0e89b 100644 --- a/fs/bcachefs/buckets.c +++ b/fs/bcachefs/buckets.c @@ -578,7 +578,8 @@ int bch2_mark_alloc(struct btree_trans *trans, -((s64) old_a.cached_sectors), journal_seq, gc); if (ret) { - bch2_fs_fatal_error(c, "bch2_mark_alloc(): no replicas entry while updating cached sectors"); + bch2_fs_fatal_error(c, "%s(): no replicas entry while updating cached sectors", + __func__); return ret; } } @@ -972,7 +973,8 @@ int bch2_mark_extent(struct btree_trans *trans, ret = update_cached_sectors(c, k, p.ptr.dev, disk_sectors, journal_seq, true); if (ret) { - bch2_fs_fatal_error(c, "bch2_mark_extent(): no replicas entry while updating cached sectors"); + bch2_fs_fatal_error(c, "%s(): no replicas entry while updating cached sectors", + __func__); return ret; } } @@ -1000,7 +1002,7 @@ int bch2_mark_extent(struct btree_trans *trans, struct printbuf buf = PRINTBUF; bch2_bkey_val_to_text(&buf, c, k); - bch2_fs_fatal_error(c, "no replicas entry for %s", buf.buf); + bch2_fs_fatal_error(c, "%s(): no replicas entry for %s", __func__, buf.buf); printbuf_exit(&buf); return ret; } diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c index ca95d85b7348..6f7310f010b9 100644 --- a/fs/bcachefs/fsck.c +++ b/fs/bcachefs/fsck.c @@ -321,7 +321,7 @@ static int __remove_dirent(struct btree_trans *trans, struct bpos pos) bch2_trans_iter_exit(trans, &iter); err: if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err(c, "error from __remove_dirent(): %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); return ret; } @@ -506,7 +506,7 @@ static int snapshots_seen_add(struct bch_fs *c, struct snapshots_seen *s, u32 id break; if (i->equiv == n.equiv) { - bch_err(c, "adding duplicate snapshot in snapshots_seen_add()"); + bch_err(c, "%s(): adding duplicate snapshot", __func__); return -EINVAL; } } @@ -1000,7 +1000,7 @@ static int check_inode(struct btree_trans *trans, err: fsck_err: if (ret) - bch_err(c, "error from check_inode(): %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); return ret; } @@ -1026,7 +1026,7 @@ static int check_inodes(struct bch_fs *c, bool full) bch2_trans_exit(&trans); snapshots_seen_exit(&s); if (ret) - bch_err(c, "error from check_inodes(): %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); return ret; } @@ -1159,7 +1159,7 @@ static int check_i_sectors(struct btree_trans *trans, struct inode_walker *w) } fsck_err: if (ret) - bch_err(c, "error from check_i_sectors(): %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); if (!ret && trans_was_restarted(trans, restart_count)) ret = -BCH_ERR_transaction_restart_nested; return ret; @@ -1295,7 +1295,7 @@ static int check_extent(struct btree_trans *trans, struct btree_iter *iter, printbuf_exit(&buf); if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err(c, "error from check_extent(): %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); return ret; } @@ -1337,7 +1337,7 @@ static int check_extents(struct bch_fs *c) snapshots_seen_exit(&s); if (ret) - bch_err(c, "error from check_extents(): %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); return ret; } @@ -1376,7 +1376,7 @@ static int check_subdir_count(struct btree_trans *trans, struct inode_walker *w) } fsck_err: if (ret) - bch_err(c, "error from check_subdir_count(): %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); if (!ret && trans_was_restarted(trans, restart_count)) ret = -BCH_ERR_transaction_restart_nested; return ret; @@ -1497,7 +1497,7 @@ static int check_dirent_target(struct btree_trans *trans, printbuf_exit(&buf); if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err(c, "error from check_target(): %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); return ret; } @@ -1667,7 +1667,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter, printbuf_exit(&buf); if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err(c, "error from check_dirent(): %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); return ret; } @@ -1706,7 +1706,7 @@ static int check_dirents(struct bch_fs *c) inode_walker_exit(&target); if (ret) - bch_err(c, "error from check_dirents(): %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); return ret; } @@ -1742,7 +1742,7 @@ static int check_xattr(struct btree_trans *trans, struct btree_iter *iter, ret = hash_check_key(trans, bch2_xattr_hash_desc, hash_info, iter, k); fsck_err: if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err(c, "error from check_xattr(): %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); return ret; } @@ -1774,7 +1774,7 @@ static int check_xattrs(struct bch_fs *c) bch2_trans_exit(&trans); if (ret) - bch_err(c, "error from check_xattrs(): %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); return ret; } diff --git a/fs/bcachefs/tests.c b/fs/bcachefs/tests.c index bed830e678bb..72364313126b 100644 --- a/fs/bcachefs/tests.c +++ b/fs/bcachefs/tests.c @@ -46,7 +46,7 @@ static int test_delete(struct bch_fs *c, u64 nr) bch2_btree_iter_traverse(&iter) ?: bch2_trans_update(&trans, &iter, &k.k_i, 0)); if (ret) { - bch_err(c, "update error in test_delete: %s", bch2_err_str(ret)); + bch_err(c, "%s(): update error in: %s", __func__, bch2_err_str(ret)); goto err; } @@ -55,7 +55,7 @@ static int test_delete(struct bch_fs *c, u64 nr) bch2_btree_iter_traverse(&iter) ?: bch2_btree_delete_at(&trans, &iter, 0)); if (ret) { - bch_err(c, "delete error (first) in test_delete: %s", bch2_err_str(ret)); + bch_err(c, "%s(): delete error (first): %s", __func__, bch2_err_str(ret)); goto err; } @@ -64,7 +64,7 @@ static int test_delete(struct bch_fs *c, u64 nr) bch2_btree_iter_traverse(&iter) ?: bch2_btree_delete_at(&trans, &iter, 0)); if (ret) { - bch_err(c, "delete error (second) in test_delete: %s", bch2_err_str(ret)); + bch_err(c, "%s(): delete error (second): %s", __func__, bch2_err_str(ret)); goto err; } err: @@ -92,7 +92,7 @@ static int test_delete_written(struct bch_fs *c, u64 nr) bch2_btree_iter_traverse(&iter) ?: bch2_trans_update(&trans, &iter, &k.k_i, 0)); if (ret) { - bch_err(c, "update error in test_delete_written: %s", bch2_err_str(ret)); + bch_err(c, "%s(): update error: %s", __func__, bch2_err_str(ret)); goto err; } @@ -103,7 +103,7 @@ static int test_delete_written(struct bch_fs *c, u64 nr) bch2_btree_iter_traverse(&iter) ?: bch2_btree_delete_at(&trans, &iter, 0)); if (ret) { - bch_err(c, "delete error in test_delete_written: %s", bch2_err_str(ret)); + bch_err(c, "%s(): delete error: %s", __func__, bch2_err_str(ret)); goto err; } err: @@ -136,7 +136,7 @@ static int test_iterate(struct bch_fs *c, u64 nr) ret = bch2_btree_insert(c, BTREE_ID_xattrs, &k.k_i, NULL, NULL, 0); if (ret) { - bch_err(c, "insert error in test_iterate: %s", bch2_err_str(ret)); + bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); goto err; } } @@ -202,7 +202,7 @@ static int test_iterate_extents(struct bch_fs *c, u64 nr) ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i, NULL, NULL, 0); if (ret) { - bch_err(c, "insert error in test_iterate_extents: %s", bch2_err_str(ret)); + bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); goto err; } } @@ -269,7 +269,7 @@ static int test_iterate_slots(struct bch_fs *c, u64 nr) ret = bch2_btree_insert(c, BTREE_ID_xattrs, &k.k_i, NULL, NULL, 0); if (ret) { - bch_err(c, "insert error in test_iterate_slots: %s", bch2_err_str(ret)); + bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); goto err; } } @@ -342,7 +342,7 @@ static int test_iterate_slots_extents(struct bch_fs *c, u64 nr) ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i, NULL, NULL, 0); if (ret) { - bch_err(c, "insert error in test_iterate_slots_extents: %s", bch2_err_str(ret)); + bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); goto err; } } @@ -456,7 +456,7 @@ static int insert_test_extent(struct bch_fs *c, ret = bch2_btree_insert(c, BTREE_ID_extents, &k.k_i, NULL, NULL, 0); if (ret) - bch_err(c, "insert error in insert_test_extent: %s", bch2_err_str(ret)); + bch_err(c, "%s(): insert error: %s", __func__, bch2_err_str(ret)); return ret; } @@ -555,7 +555,7 @@ static int test_snapshots(struct bch_fs *c, u64 nr) ret = test_snapshot_filter(c, snapids[0], snapids[1]); if (ret) { - bch_err(c, "err from test_snapshot_filter: %s", bch2_err_str(ret)); + bch_err(c, "%s(): err from test_snapshot_filter: %s", __func__, bch2_err_str(ret)); return ret; } @@ -567,11 +567,8 @@ static int test_snapshots(struct bch_fs *c, u64 nr) static u64 test_rand(void) { u64 v; -#if 0 - v = prandom_u32_max(U32_MAX); -#else + get_random_bytes(&v, sizeof(v)); -#endif return v; } @@ -592,7 +589,7 @@ static int rand_insert(struct bch_fs *c, u64 nr) ret = commit_do(&trans, NULL, NULL, 0, __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k.k_i)); if (ret) { - bch_err(c, "error in rand_insert: %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); break; } } @@ -628,7 +625,7 @@ static int rand_insert_multi(struct bch_fs *c, u64 nr) __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[6].k_i) ?: __bch2_btree_insert(&trans, BTREE_ID_xattrs, &k[7].k_i)); if (ret) { - bch_err(c, "error in rand_insert_multi: %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); break; } } @@ -655,7 +652,7 @@ static int rand_lookup(struct bch_fs *c, u64 nr) lockrestart_do(&trans, bkey_err(k = bch2_btree_iter_peek(&iter))); ret = bkey_err(k); if (ret) { - bch_err(c, "error in rand_lookup: %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); break; } } @@ -678,7 +675,7 @@ static int rand_mixed_trans(struct btree_trans *trans, k = bch2_btree_iter_peek(iter); ret = bkey_err(k); if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) - bch_err(trans->c, "lookup error in rand_mixed: %s", bch2_err_str(ret)); + bch_err(trans->c, "%s(): lookup error: %s", __func__, bch2_err_str(ret)); if (ret) return ret; @@ -708,7 +705,7 @@ static int rand_mixed(struct bch_fs *c, u64 nr) ret = commit_do(&trans, NULL, NULL, 0, rand_mixed_trans(&trans, &iter, &cookie, i, rand)); if (ret) { - bch_err(c, "update error in rand_mixed: %s", bch2_err_str(ret)); + bch_err(c, "%s(): update error: %s", __func__, bch2_err_str(ret)); break; } } @@ -754,7 +751,7 @@ static int rand_delete(struct bch_fs *c, u64 nr) ret = commit_do(&trans, NULL, NULL, 0, __do_delete(&trans, pos)); if (ret) { - bch_err(c, "error in rand_delete: %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); break; } } @@ -786,7 +783,7 @@ static int seq_insert(struct bch_fs *c, u64 nr) bch2_trans_update(&trans, &iter, &insert.k_i, 0); })); if (ret) - bch_err(c, "error in %s(): %s", __func__, bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); bch2_trans_exit(&trans); return ret; @@ -805,7 +802,7 @@ static int seq_lookup(struct bch_fs *c, u64 nr) SPOS(0, 0, U32_MAX), 0, k, 0); if (ret) - bch_err(c, "error in %s(): %s", __func__, bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); bch2_trans_exit(&trans); return ret; @@ -831,7 +828,7 @@ static int seq_overwrite(struct bch_fs *c, u64 nr) bch2_trans_update(&trans, &iter, &u.k_i, 0); })); if (ret) - bch_err(c, "error in %s(): %s", __func__, bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); bch2_trans_exit(&trans); return ret; @@ -845,7 +842,7 @@ static int seq_delete(struct bch_fs *c, u64 nr) SPOS(0, 0, U32_MAX), SPOS_MAX, 0, NULL); if (ret) - bch_err(c, "error in seq_delete: %s", bch2_err_str(ret)); + bch_err(c, "%s(): error %s", __func__, bch2_err_str(ret)); return ret; }