From: Kent Overstreet Date: Fri, 7 Feb 2025 06:33:01 +0000 (-0500) Subject: bcachefs: bch2_indirect_extent_missing_error() prints path, not just inode number X-Git-Tag: v6.15-rc1~146^2~141 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=45f0e6c838e5d9af3f013adb4ba9aad3bcbcbe3b;p=thirdparty%2Fkernel%2Flinux.git bcachefs: bch2_indirect_extent_missing_error() prints path, not just inode number 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 --- diff --git a/fs/bcachefs/error.c b/fs/bcachefs/error.c index 038da6a61f6b5..14cfcfa395905 100644 --- a/fs/bcachefs/error.c +++ b/fs/bcachefs/error.c @@ -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; +} diff --git a/fs/bcachefs/error.h b/fs/bcachefs/error.h index 7acf2a27ca281..95cf48a31dbf2 100644 --- a/fs/bcachefs/error.h +++ b/fs/bcachefs/error.h @@ -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 */ diff --git a/fs/bcachefs/reflink.c b/fs/bcachefs/reflink.c index 441e648f28b51..50118661e64bf 100644 --- a/fs/bcachefs/reflink.c +++ b/fs/bcachefs/reflink.c @@ -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) diff --git a/fs/bcachefs/snapshot.c b/fs/bcachefs/snapshot.c index ede0b480e7d4b..e7f197896db17 100644 --- a/fs/bcachefs/snapshot.c +++ b/fs/bcachefs/snapshot.c @@ -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; diff --git a/fs/bcachefs/snapshot.h b/fs/bcachefs/snapshot.h index 00373cf32e7bc..81180181d7c9c 100644 --- a/fs/bcachefs/snapshot.h +++ b/fs/bcachefs/snapshot.h @@ -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)