]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Log & error message improvements
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 5 Jan 2022 00:05:08 +0000 (19:05 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:21 +0000 (17:09 -0400)
 - Add a shim uuid_unparse_lower() in the kernel, since %pU doesn't work
   in userspace

 - We don't need to print the bcachefs: or the filesystem name prefix in
   userspace

 - Improve a few error messages

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/bcachefs.h
fs/bcachefs/btree_io.c
fs/bcachefs/btree_key_cache.c
fs/bcachefs/checksum.c
fs/bcachefs/recovery.c
fs/bcachefs/super.c
fs/bcachefs/util.h

index 2dd3a0a1943a9fafc7301d39b9c83f3ac8957d68..8ef874b3afbbaa08a7b6ecbc0c35a20e2e471144 100644 (file)
 #define bch2_fmt(_c, fmt)              "bcachefs (%s): " fmt "\n", ((_c)->name)
 #define bch2_fmt_inum(_c, _inum, fmt)  "bcachefs (%s inum %llu): " fmt "\n", ((_c)->name), (_inum)
 #else
-#define bch2_fmt(_c, fmt)              "%s: " fmt "\n", ((_c)->name)
-#define bch2_fmt_inum(_c, _inum, fmt)  "%s inum %llu: " fmt "\n", ((_c)->name), (_inum)
+#define bch2_fmt(_c, fmt)              fmt "\n"
+#define bch2_fmt_inum(_c, _inum, fmt)  "inum %llu: " fmt "\n", (_inum)
 #endif
 
 #define bch_info(c, fmt, ...) \
index 287c45253a3304d4bfa55d8536c5b2c5fe3b7241..b6551db0396842788ae111a6db786ccbe1d71f4b 100644 (file)
@@ -967,19 +967,23 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
 
                SET_BSET_BIG_ENDIAN(i, CPU_BIG_ENDIAN);
 
-               b->written += sectors;
-
                blacklisted = bch2_journal_seq_is_blacklisted(c,
                                        le64_to_cpu(i->journal_seq),
                                        true);
 
                btree_err_on(blacklisted && first,
                             BTREE_ERR_FIXABLE, c, ca, b, i,
-                            "first btree node bset has blacklisted journal seq");
+                            "first btree node bset has blacklisted journal seq (%llu)",
+                            le64_to_cpu(i->journal_seq));
 
                btree_err_on(blacklisted && ptr_written,
                             BTREE_ERR_FIXABLE, c, ca, b, i,
-                            "found blacklisted bset in btree node with sectors_written");
+                            "found blacklisted bset (journal seq %llu) in btree node at offset %u-%u/%u",
+                            le64_to_cpu(i->journal_seq),
+                            b->written, b->written + sectors, ptr_written);
+
+               b->written += sectors;
+
                if (blacklisted && !first)
                        continue;
 
index 13012f26a677e44aae9106dcdff0b002815d4f30..08df768fbebba82f2748a2951eae5c3217dcaca0 100644 (file)
@@ -209,7 +209,6 @@ static int btree_key_cache_fill(struct btree_trans *trans,
                                struct btree_path *ck_path,
                                struct bkey_cached *ck)
 {
-       struct bch_fs *c = trans->c;
        struct btree_iter iter;
        struct bkey_s_c k;
        unsigned new_u64s = 0;
@@ -239,7 +238,7 @@ static int btree_key_cache_fill(struct btree_trans *trans,
                new_u64s = roundup_pow_of_two(new_u64s);
                new_k = kmalloc(new_u64s * sizeof(u64), GFP_NOFS);
                if (!new_k) {
-                       bch_err(c, "error allocating memory for key cache key, btree %s u64s %u",
+                       bch_err(trans->c, "error allocating memory for key cache key, btree %s u64s %u",
                                bch2_btree_ids[ck->key.btree_id], new_u64s);
                        ret = -ENOMEM;
                        goto err;
index fbe8603cfb3060eeeb7e29f5b5c64916ce381983..a1d89923d361a976aeed0f7de3b7ebb0658df495 100644 (file)
@@ -407,16 +407,12 @@ int bch2_rechecksum_bio(struct bch_fs *c, struct bio *bio,
 }
 
 #ifdef __KERNEL__
-int bch2_request_key(struct bch_sb *sb, struct bch_key *key)
+static int __bch2_request_key(char *key_description, struct bch_key *key)
 {
-       char key_description[60];
        struct key *keyring_key;
        const struct user_key_payload *ukp;
        int ret;
 
-       snprintf(key_description, sizeof(key_description),
-                "bcachefs:%pUb", &sb->user_uuid);
-
        keyring_key = request_key(&key_type_logon, key_description, NULL);
        if (IS_ERR(keyring_key))
                return PTR_ERR(keyring_key);
@@ -436,16 +432,10 @@ int bch2_request_key(struct bch_sb *sb, struct bch_key *key)
 }
 #else
 #include <keyutils.h>
-#include <uuid/uuid.h>
 
-int bch2_request_key(struct bch_sb *sb, struct bch_key *key)
+static int __bch2_request_key(char *key_description, struct bch_key *key)
 {
        key_serial_t key_id;
-       char key_description[60];
-       char uuid[40];
-
-       uuid_unparse_lower(sb->user_uuid.b, uuid);
-       sprintf(key_description, "bcachefs:%s", uuid);
 
        key_id = request_key("user", key_description, NULL,
                             KEY_SPEC_USER_KEYRING);
@@ -459,6 +449,17 @@ int bch2_request_key(struct bch_sb *sb, struct bch_key *key)
 }
 #endif
 
+int bch2_request_key(struct bch_sb *sb, struct bch_key *key)
+{
+       char key_description[60];
+       char uuid[40];
+
+       uuid_unparse_lower(sb->user_uuid.b, uuid);
+       sprintf(key_description, "bcachefs:%s", uuid);
+
+       return __bch2_request_key(key_description, key);
+}
+
 int bch2_decrypt_sb_key(struct bch_fs *c,
                        struct bch_sb_field_crypt *crypt,
                        struct bch_key *key)
index d11457c229ac14fc69451596c19d6bd55fa76fa7..7003cf77fdcd6441399dcfef95e3622cde55a0ee 100644 (file)
@@ -530,10 +530,8 @@ static int bch2_journal_replay(struct bch_fs *c)
             sizeof(keys_sorted[0]),
             journal_sort_seq_cmp, NULL);
 
-       if (keys->nr) {
-               bch_verbose(c, "starting journal replay, %zu keys", keys->nr);
+       if (keys->nr)
                replay_now_at(j, keys->journal_seq_base);
-       }
 
        for (i = 0; i < keys->nr; i++) {
                k = keys_sorted[i];
@@ -901,7 +899,6 @@ static int bch2_fs_initialize_subvolumes(struct bch_fs *c)
 
 static int bch2_fs_upgrade_for_subvolumes(struct btree_trans *trans)
 {
-       struct bch_fs *c = trans->c;
        struct btree_iter iter;
        struct bkey_s_c k;
        struct bch_inode_unpacked inode;
@@ -915,7 +912,7 @@ static int bch2_fs_upgrade_for_subvolumes(struct btree_trans *trans)
                goto err;
 
        if (!bkey_is_inode(k.k)) {
-               bch_err(c, "root inode not found");
+               bch_err(trans->c, "root inode not found");
                ret = -ENOENT;
                goto err;
        }
@@ -1138,7 +1135,7 @@ use_clean:
        if (c->opts.norecovery)
                goto out;
 
-       bch_verbose(c, "starting journal replay");
+       bch_verbose(c, "starting journal replay, %zu keys", c->journal_keys.nr);
        err = "journal replay failed";
        ret = bch2_journal_replay(c);
        if (ret)
index 7b7902fbdcc6d753d9567ae29d3b9481eabc7a23..47de774d18b8a5bf284aa297f0ac5789b4921e17 100644 (file)
@@ -745,7 +745,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
        if (ret)
                goto err;
 
-       scnprintf(c->name, sizeof(c->name), "%pU", &c->sb.user_uuid);
+       uuid_unparse_lower(c->sb.user_uuid.b, c->name);
 
        /* Compat: */
        if (sb->version <= bcachefs_metadata_version_inode_v2 &&
index 969139fef086cf049f75779f906b0a69d719077f..fbe5b710e9c5fcf940606217b8d88805fea33844 100644 (file)
@@ -764,4 +764,13 @@ static inline int u8_cmp(u8 l, u8 r)
        return cmp_int(l, r);
 }
 
+#ifdef __KERNEL__
+static inline void uuid_unparse_lower(u8 *uuid, char *out)
+{
+       sprintf(out, "%plU", uuid);
+}
+#else
+#include <uuid/uuid.h>
+#endif
+
 #endif /* _BCACHEFS_UTIL_H */