]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: improve check_inode_hash_info_matches_root() error message
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 6 May 2025 01:15:34 +0000 (21:15 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:47 +0000 (20:14 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/str_hash.c
fs/bcachefs/str_hash.h

index a90bf7b8a2b4b169f39743d4dba0f9019f62720f..55a3a116b5a8aa481611eece2ec6ae4221636ed7 100644 (file)
@@ -157,6 +157,8 @@ static noinline int check_inode_hash_info_matches_root(struct btree_trans *trans
                if (bkey_is_inode(k.k))
                        goto found;
        }
+
+       /* This would've been caught by check_key_has_inode() */
        bch_err(c, "%s(): inum %llu not found", __func__, inum);
        ret = -BCH_ERR_fsck_repair_unimplemented;
        goto err;
@@ -166,20 +168,25 @@ found:;
        if (ret)
                goto err;
 
-       struct bch_hash_info hash2 = bch2_hash_info_init(c, &inode);
-       if (hash_info->type != hash2.type ||
-           memcmp(&hash_info->siphash_key, &hash2.siphash_key, sizeof(hash2.siphash_key))) {
+       struct bch_hash_info hash_root = bch2_hash_info_init(c, &inode);
+       if (hash_info->type != hash_root.type ||
+           memcmp(&hash_info->siphash_key,
+                  &hash_root.siphash_key,
+                  sizeof(hash_root.siphash_key))) {
                ret = repair_inode_hash_info(trans, &inode);
                if (!ret) {
-                       bch_err(c, "inode hash info mismatch with root, but mismatch not found\n"
-                               "%u %llx %llx\n"
-                               "%u %llx %llx",
-                               hash_info->type,
-                               hash_info->siphash_key.k0,
-                               hash_info->siphash_key.k1,
-                               hash2.type,
-                               hash2.siphash_key.k0,
-                               hash2.siphash_key.k1);
+                       struct printbuf buf = PRINTBUF;
+                       prt_printf(&buf, "inode %llu hash info mismatch with root, but mismatch not found\n", inum);
+
+                       prt_printf(&buf, "root snapshot %u ", hash_root.inum_snapshot);
+                       bch2_prt_str_hash_type(&buf, hash_root.type);
+                       prt_printf(&buf, " %llx %llx\n", hash_root.siphash_key.k0, hash_root.siphash_key.k1);
+
+                       prt_printf(&buf, "vs   snapshot %u ", hash_info->inum_snapshot);
+                       bch2_prt_str_hash_type(&buf, hash_info->type);
+                       prt_printf(&buf, " %llx %llx", hash_info->siphash_key.k0, hash_info->siphash_key.k1);
+                       bch_err(c, "%s", buf.buf);
+                       printbuf_exit(&buf);
                        ret = -BCH_ERR_fsck_repair_unimplemented;
                }
        }
index 0c1a00539bd14ac7b2ef384dafdb131c1e4c4dcd..ae3154fb6a9441f0d427fb103e51708820d9c19f 100644 (file)
@@ -32,6 +32,7 @@ bch2_str_hash_opt_to_type(struct bch_fs *c, enum bch_str_hash_opts opt)
 }
 
 struct bch_hash_info {
+       u32                     inum_snapshot;
        u8                      type;
        struct unicode_map      *cf_encoding;
        /*
@@ -45,11 +46,12 @@ static inline struct bch_hash_info
 bch2_hash_info_init(struct bch_fs *c, const struct bch_inode_unpacked *bi)
 {
        struct bch_hash_info info = {
-               .type = INODE_STR_HASH(bi),
+               .inum_snapshot  = bi->bi_snapshot,
+               .type           = INODE_STR_HASH(bi),
 #ifdef CONFIG_UNICODE
-               .cf_encoding = bch2_inode_casefold(c, bi) ? c->cf_encoding : NULL,
+               .cf_encoding    = bch2_inode_casefold(c, bi) ? c->cf_encoding : NULL,
 #endif
-               .siphash_key = { .k0 = bi->bi_hash_seed }
+               .siphash_key    = { .k0 = bi->bi_hash_seed }
        };
 
        if (unlikely(info.type == BCH_STR_HASH_siphash_old)) {