From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2 1/6] btrfs-progs: introduce "btrfs rescue fix-data-checksum"
Date: Fri, 30 May 2025 13:10:29 +0200 [thread overview]
Message-ID: <20250530111029.GQ4037@twin.jikos.cz> (raw)
In-Reply-To: <a91001c175a5dd38a8873c6550bf856f1f4c5cde.1747295965.git.wqu@suse.com>
On Thu, May 15, 2025 at 05:30:16PM +0930, Qu Wenruo wrote:
> +static void report_corrupted_blocks(void)
> +{
> + struct corrupted_block *entry;
> +
> + if (list_empty(&corrupted_blocks)) {
> + printf("No data checksum mismatch found\n");
printf(...) -> pr_verbose(LOG_DEFAULT, ...) so the verbosity options are
respected. The semantics is the same as printf, so there's no implicit "\n"
and you can glue the lines as you need.
> + return;
> + }
> +
> + list_for_each_entry(entry, &corrupted_blocks, list) {
> + bool has_printed = false;
> +
> + printf("logical=%llu corrtuped mirrors=", entry->logical);
> + /* Poor man's bitmap print. */
> + for (int i = 0; i < entry->num_mirrors; i++) {
> + if (test_bit(i, entry->error_mirror_bitmap)) {
> + if (has_printed)
> + printf(",");
> + /*
> + * Bit 0 means mirror 1, thus we need to increase
> + * the value by 1.
> + */
> + printf("%d", i + 1);
> + has_printed=true;
> + }
> + }
> + printf("\n");
> + }
> +}
> +static int cmd_rescue_fix_data_checksum(const struct cmd_struct *cmd,
> + int argc, char **argv)
> +{
> + enum btrfs_fix_data_checksum_mode mode = BTRFS_FIX_DATA_CSUMS_READONLY;
> + int ret;
> + optind = 0;
> +
> + while (1) {
> + int c;
> + enum { GETOPT_VAL_DRYRUN = GETOPT_VAL_FIRST, };
The ending "," does not need to be there
> + static const struct option long_options [] = {
> + {"readonly", no_argument, NULL, 'r'},
> + {"NULL", 0, NULL, 0},
> + };
Missing newline
> + c = getopt_long(argc, argv, "r", long_options, NULL);
> + if (c < 0)
> + break;
> + switch (c) {
> + case 'r':
> + mode = BTRFS_FIX_DATA_CSUMS_READONLY;
> + break;
> + default:
> + usage_unknown_option(cmd, argv);
> + }
> + }
> + if (check_argc_min(argc - optind, 1))
> + return 1;
> + ret = btrfs_recover_fix_data_checksum(argv[optind], mode);
> + if (ret < 0) {
> + errno = -ret;
> + error("failed to fix data checksums: %m");
> + }
> + return !!ret;
> +}
> +static DEFINE_SIMPLE_COMMAND(rescue_fix_data_checksum, "fix-data-checksum");
next prev parent reply other threads:[~2025-05-30 11:10 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 [this message]
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
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=20250530111029.GQ4037@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