]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: bch2_indirect_extent_missing_error() prints path, not just inode number
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 7 Feb 2025 06:33:01 +0000 (01:33 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 15 Mar 2025 01:02:12 +0000 (21:02 -0400)
We want all error messages converted to print paths, not just inode
numbers - users want this information, and it speeds up debugging too.

Auditing and converting all error messages is going to be a big project,
so for the moment we're just doing this incrementally.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/error.c
fs/bcachefs/error.h
fs/bcachefs/reflink.c
fs/bcachefs/snapshot.c
fs/bcachefs/snapshot.h

index 038da6a61f6b553e3fdd2c45381d3947f889e9b1..14cfcfa39590581bbb14fd8ac5096343c3942db1 100644 (file)
@@ -535,7 +535,6 @@ int bch2_inum_err_msg_trans(struct btree_trans *trans, struct printbuf *out, sub
        u32 restart_count = trans->restart_count;
        int ret = 0;
 
-       /* XXX: we don't yet attempt to print paths when we don't know the subvol */
        if (inum.subvol)
                ret = lockrestart_do(trans, bch2_inum_to_path(trans, inum, out));
        if (!inum.subvol || ret)
@@ -562,3 +561,34 @@ void bch2_inum_offset_err_msg(struct bch_fs *c, struct printbuf *out,
 {
        bch2_trans_run(c, bch2_inum_offset_err_msg_trans(trans, out, inum, offset));
 }
+
+int bch2_inum_snap_err_msg_trans(struct btree_trans *trans, struct printbuf *out,
+                                struct bpos pos)
+{
+       u32 restart_count = trans->restart_count;
+       struct bch_fs *c = trans->c;
+       int ret = 0;
+
+       if (!bch2_snapshot_is_leaf(c, pos.snapshot))
+               prt_str(out, "(multiple snapshots) ");
+
+       subvol_inum inum = {
+               .subvol = bch2_snapshot_tree_oldest_subvol(c, pos.snapshot),
+               .inum   = pos.inode,
+       };
+
+       if (inum.subvol)
+               ret = lockrestart_do(trans, bch2_inum_to_path(trans, inum, out));
+       if (!inum.subvol || ret)
+               prt_printf(out, "inum %llu:%u", pos.inode, pos.snapshot);
+
+       return trans_was_restarted(trans, restart_count);
+}
+
+int bch2_inum_snap_offset_err_msg_trans(struct btree_trans *trans, struct printbuf *out,
+                                       struct bpos pos)
+{
+       int ret = bch2_inum_snap_err_msg_trans(trans, out, pos);
+       prt_printf(out, " offset %llu: ", pos.offset << 8);
+       return ret;
+}
index 7acf2a27ca281fd7edefd6ab38c276274a6f7b41..95cf48a31dbf27c00368b2f24a61192e305c0b4e 100644 (file)
@@ -244,4 +244,7 @@ int bch2_inum_offset_err_msg_trans(struct btree_trans *, struct printbuf *, subv
 void bch2_inum_err_msg(struct bch_fs *, struct printbuf *, subvol_inum);
 void bch2_inum_offset_err_msg(struct bch_fs *, struct printbuf *, subvol_inum, u64);
 
+int bch2_inum_snap_err_msg_trans(struct btree_trans *, struct printbuf *, struct bpos);
+int bch2_inum_snap_offset_err_msg_trans(struct btree_trans *, struct printbuf *, struct bpos);
+
 #endif /* _BCACHEFS_ERROR_H */
index 441e648f28b516e8b4a71bc5355e478cffce6805..50118661e64bfc5115dd617ca1de5b6c60004946 100644 (file)
@@ -185,12 +185,21 @@ static int bch2_indirect_extent_missing_error(struct btree_trans *trans,
        BUG_ON(missing_start    < refd_start);
        BUG_ON(missing_end      > refd_end);
 
-       if (fsck_err(trans, reflink_p_to_missing_reflink_v,
-                    "pointer to missing indirect extent\n"
-                    "  %s\n"
-                    "  missing range %llu-%llu",
-                    (bch2_bkey_val_to_text(&buf, c, p.s_c), buf.buf),
-                    missing_start, missing_end)) {
+       struct bpos missing_pos = bkey_start_pos(p.k);
+       missing_pos.offset += missing_start - live_start;
+
+       prt_printf(&buf, "pointer to missing indirect extent in ");
+       ret = bch2_inum_snap_offset_err_msg_trans(trans, &buf, missing_pos);
+       if (ret)
+               goto err;
+
+       prt_printf(&buf, "-%llu\n  ", (missing_pos.offset + (missing_end - missing_start)) << 9);
+       bch2_bkey_val_to_text(&buf, c, p.s_c);
+
+       prt_printf(&buf, "\n  missing reflink btree range %llu-%llu",
+                  missing_start, missing_end);
+
+       if (fsck_err(trans, reflink_p_to_missing_reflink_v, "%s", buf.buf)) {
                struct bkey_i_reflink_p *new = bch2_bkey_make_mut_noupdate_typed(trans, p.s_c, reflink_p);
                ret = PTR_ERR_OR_ZERO(new);
                if (ret)
index ede0b480e7d4b36342c01b6e6dc69a2901b967d9..e7f197896db1737217301c4ee0f30295fd7439bd 100644 (file)
@@ -390,7 +390,7 @@ static u32 bch2_snapshot_tree_next(struct bch_fs *c, u32 id)
        return 0;
 }
 
-static u32 bch2_snapshot_tree_oldest_subvol(struct bch_fs *c, u32 snapshot_root)
+u32 bch2_snapshot_tree_oldest_subvol(struct bch_fs *c, u32 snapshot_root)
 {
        u32 id = snapshot_root;
        u32 subvol = 0, s;
index 00373cf32e7bcfe977b5df8932e808791e39a169..81180181d7c9c68bd4b4ca95840126b996c5a27b 100644 (file)
@@ -105,6 +105,7 @@ static inline u32 bch2_snapshot_nth_parent(struct bch_fs *c, u32 id, u32 n)
        return id;
 }
 
+u32 bch2_snapshot_tree_oldest_subvol(struct bch_fs *, u32);
 u32 bch2_snapshot_skiplist_get(struct bch_fs *, u32);
 
 static inline u32 bch2_snapshot_root(struct bch_fs *c, u32 id)