From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2 3/6] btrfs-progs: fix-data-checksum: show affected files
Date: Fri, 30 May 2025 13:14:06 +0200 [thread overview]
Message-ID: <20250530111406.GS4037@twin.jikos.cz> (raw)
In-Reply-To: <6112e51519a5914c181dd1e5deb07bf165e15c72.1747295965.git.wqu@suse.com>
On Thu, May 15, 2025 at 05:30:18PM +0930, Qu Wenruo wrote:
> Previously "btrfs rescue fix-data-checksum" only show affected logical
> bytenr, which is not helpful to determine which files are affected.
>
> Enhance the output by also outputting the affected subvolumes (in
> numeric form), and the file paths inside that subvolume.
>
> The example looks like this:
>
> logical=13631488 corrtuped mirrors=1 affected files:
> (subvolume 5)/foo
> (subvolume 5)/dir/bar
> logical=13635584 corrtuped mirrors=1 affected files:
> (subvolume 5)/foo
> (subvolume 5)/dir/bar
>
> Although the end result is still not perfect, it's still much easier to
> find out which files are affected.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> cmds/rescue-fix-data-checksum.c | 59 +++++++++++++++++++++++++++++++--
> 1 file changed, 56 insertions(+), 3 deletions(-)
>
> diff --git a/cmds/rescue-fix-data-checksum.c b/cmds/rescue-fix-data-checksum.c
> index 7e613ba57f76..bf3a65b31c71 100644
> --- a/cmds/rescue-fix-data-checksum.c
> +++ b/cmds/rescue-fix-data-checksum.c
> @@ -18,6 +18,7 @@
> #include "kernel-shared/disk-io.h"
> #include "kernel-shared/ctree.h"
> #include "kernel-shared/volumes.h"
> +#include "kernel-shared/backref.h"
> #include "common/messages.h"
> #include "common/open-utils.h"
> #include "cmds/rescue.h"
> @@ -158,6 +159,49 @@ static int iterate_one_csum_item(struct btrfs_fs_info *fs_info, struct btrfs_pat
> return ret;
> }
>
> +static int print_filenames(u64 ino, u64 offset, u64 rootid, void *ctx)
> +{
> + struct btrfs_fs_info *fs_info = ctx;
> + struct btrfs_root *root;
> + struct btrfs_key key;
> + struct inode_fs_paths *ipath;
> + struct btrfs_path path = { 0 };
> + int ret;
> +
> + key.objectid = rootid;
> + key.type = BTRFS_ROOT_ITEM_KEY;
> + key.offset = (u64)-1;
> +
> + root = btrfs_read_fs_root(fs_info, &key);
> + if (IS_ERR(root)) {
> + ret = PTR_ERR(root);
> + errno = -ret;
> + error("failed to get subvolume %llu: %m", rootid);
> + return ret;
> + }
> + ipath = init_ipath(128 * BTRFS_PATH_NAME_MAX, root, &path);
128 is a magic constant, I've left it like that but we can use the
PATH_MAX and some named definition for the count.
> + if (IS_ERR(ipath)) {
> + ret = PTR_ERR(ipath);
> + errno = -ret;
> + error("failed to initialize ipath: %m");
> + return ret;
> + }
> + ret = paths_from_inode(ino, ipath);
> + if (ret < 0) {
> + errno = -ret;
> + error("failed to resolve root %llu ino %llu to paths: %m", rootid, ino);
> + goto out;
> + }
> + for (int i = 0; i < ipath->fspath->elem_cnt; i++)
> + printf(" (subvolume %llu)/%s\n", rootid, (char *)ipath->fspath->val[i]);
> + if (ipath->fspath->elem_missed)
> + printf(" (subvolume %llu) %d files not printed\n", rootid,
> + ipath->fspath->elem_missed);
> +out:
> + free_ipath(ipath);
> + return ret;
> +}
> +
next prev parent reply other threads:[~2025-05-30 11:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-15 8:00 [PATCH v2 0/6] btrfs-progs: introduce "btrfs rescue fix-data-checksum" Qu Wenruo
2025-05-15 8:00 ` [PATCH v2 1/6] " Qu Wenruo
2025-05-30 11:10 ` David Sterba
2025-05-15 8:00 ` [PATCH v2 2/6] btrfs-progs: fix a bug in btrfs_find_item() Qu Wenruo
2025-05-30 11:11 ` David Sterba
2025-05-15 8:00 ` [PATCH v2 3/6] btrfs-progs: fix-data-checksum: show affected files Qu Wenruo
2025-05-30 11:14 ` David Sterba [this message]
2025-05-15 8:00 ` [PATCH v2 4/6] btrfs-progs: fix-data-checksum: introduce interactive mode Qu Wenruo
2025-05-30 11:18 ` David Sterba
2025-05-15 8:00 ` [PATCH v2 5/6] btrfs-progs: fix-data-checksum: update csum items to fix csum mismatch Qu Wenruo
2025-05-30 11:19 ` David Sterba
2025-05-30 22:23 ` Qu Wenruo
2025-05-15 8:00 ` [PATCH v2 6/6] btrfs-progs: fix-data-checksum: introduce -m|--mirror option Qu Wenruo
2025-05-30 11:07 ` [PATCH v2 0/6] btrfs-progs: introduce "btrfs rescue fix-data-checksum" David Sterba
2025-05-31 16:58 ` Goffredo Baroncelli
2025-05-31 22:07 ` Qu Wenruo
2025-06-02 17:28 ` Goffredo Baroncelli
2025-06-02 22:55 ` Qu Wenruo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250530111406.GS4037@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox