Skip to content

btrfs-progs: introduce "btrfs rescue fix-data-checksum"

Qu Wenruo linux-btrfs 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest6 patches 11 repliesIn review
  2. v13 patches 0 repliesSuperseded

Changes in v2 from the cover letter

- Rename the subcommand to "fix-data-checksum" It's better to use full name in the command name

- Remove unused members inside corrupted_block
The old @extent_bytenr and @extent_len is no longer needed, even for the future file-deletion action.

- Fix the bitmap size off-by-1 bug
We must use the bit 0 to represent mirror 1, or the bitmap size will exceed num_mirrors.

- Introduce -i|--interactive mode
Will ask the user for the action on the corrupted block, including:

* Ignore
The default behavior if no command is provided

* Use specified mirror to update the data checksum item The user must input a number inside range [1, num_mirrors].

- Introduce -m|--mirror <num> mode
Use specified mirror for all corrupted blocks.
The value <num> must be >= 1. And if the value is larger than the actual max mirror number, the real mirror number will be num % (num_mirror + 1).

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6btrfs-progs: introduce "btrfs rescue fix-data-checksum"Documentation/btrfs-rescue.rst Makefile cmds/rescue-fix-data-checksum.c +2 more+363 -11 reply
2/6btrfs-progs: fix a bug in btrfs_find_item()kernel-shared/ctree.c+14 -31 reply
3/6btrfs-progs: fix-data-checksum: show affected filescmds/rescue-fix-data-checksum.c+56 -31 reply
4/6btrfs-progs: fix-data-checksum: introduce interactive modeDocumentation/btrfs-rescue.rst cmds/rescue-fix-data-checksum.c cmds/rescue.c +1 more+78 -41 reply
5/6btrfs-progs: fix-data-checksum: update csum items to fix csum mismatchcmds/rescue-fix-data-checksum.c kernel-shared/file-item.c kernel-shared/file-item.h+114 -122 replies
6/6btrfs-progs: fix-data-checksum: introduce -m|--mirror optionDocumentation/btrfs-rescue.rst cmds/rescue-fix-data-checksum.c cmds/rescue.c +1 more+35 -70 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/6] btrfs-progs: introduce "btrfs rescue fix-data-checksum"

[CHANGELOG]
v2:
- Rename the subcommand to "fix-data-checksum" It's better to use full name in the command name

- Remove unused members inside corrupted_block
The old @extent_bytenr and @extent_len is no longer needed, even for the future file-deletion action.

- Fix the bitmap size off-by-1 bug
We must use the bit 0 to represent mirror 1, or the bitmap size will exceed num_mirrors.

- Introduce -i|--interactive mode
Will ask the user for the action on the corrupted block, including:

* Ignore
The default behavior if no command is provided

* Use specified mirror to update the data checksum item The user must input a number inside range [1, num_mirrors].

- Introduce -m|--mirror <num> mode
Use specified mirror for all corrupted blocks.
The value <num> must be >= 1. And if the value is larger than the actual max mirror number, the real mirror number will be num % (num_mirror + 1).

We have a long history of data csum mismatch, caused by direct IO and buffered being modified during writeback.

Although the problem is worked around in v6.15 (and being backported), for the affected fs there is no good way to fix them, other than complex manually find out which files are affected and delete them.

This series introduce the initial implementation of "btrfs rescue fix-data-checksum", which is designed to fix such problem by either:

- Update the csum items using the data from specified copy

The subcommand has 3 modes so far:

- Readonly mode
Only report all corrupted blocks and affected files, no repair is done.

- Interactive mode
Ask for what to do, including

* Ignore (the default)
* Use certain mirror to update the checksum item

- Mirror mode
Use specified mirror to update the checksum item, the batch mode of the interactive one.

In the future, there will be one more mode:

- Delete mode
Delete all involved files.

There are still some points to address before implementing this mode.

Qu Wenruo (6):
btrfs-progs: introduce "btrfs rescue fix-data-checksum"
btrfs-progs: fix a bug in btrfs_find_item()
btrfs-progs: fix-data-checksum: show affected files
btrfs-progs: fix-data-checksum: introduce interactive mode
btrfs-progs: fix-data-checksum: update csum items to fix csum mismatch
btrfs-progs: fix-data-checksum: introduce -m|--mirror option

 Documentation/btrfs-rescue.rst  |  28 ++
 Makefile                        |   2 +-
 cmds/rescue-fix-data-checksum.c | 511 ++++++++++++++++++++++++++++++++
 cmds/rescue.c                   |  65 ++++
 cmds/rescue.h                   |  10 +
 kernel-shared/ctree.c           |  17 +-
 kernel-shared/file-item.c       |   2 +-
 kernel-shared/file-item.h       |   5 +
 8 files changed, 635 insertions(+), 5 deletions(-)
 create mode 100644 cmds/rescue-fix-data-checksum.c

--
2.49.0