Skip to content

btrfs-progs: print csum values on superblock mismatch #985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

maharmstone
Copy link
Contributor

If in btrfs_check_super() we find that the superblock has a csum mismatch, print the wanted and found values, just as we do for metadata in __csum_tree_block_size().

When hex-editing a btrfs image, it's useful to use btrfs check to calculate what the new csum should be. Unfortunately at present this only works for trees and not for the superblock, meaning you have to use the much more wordy btrfs inspect-internal.

adam900710 and others added 2 commits May 14, 2025 09:47
[BUG]
When a device replace failed, e.g. try to replace a device on a RO
mounted btrfs, the error message is incorrectly broken into two lines:

 [adam@btrfs-vm ~]$ sudo btrfs replace start -fB 1 /dev/test/scratch3  /mnt/btrfs/
 Performing full device TRIM /dev/mapper/test-scratch3 (10.00GiB) ...
 ERROR: ioctl(DEV_REPLACE_START) failed on "/mnt/btrfs/": Read-only file system

 [adam@btrfs-vm ~]$

Note the newline after the "Read-only file system" error message.

[CAUSE]
Inside cmd_replace_start(), if the ioctl failed we need to handle the
error messages different depeneding on start_args.result.

If the result is not BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT we will
append extra info to the error message.

But the initial error message is using error(), which implies a newline.

This results the above incorrectly splitted error message.

[FIX]
Instead of manually appending an extra reason to the existing error
message, just do different output depending on the start_args.result in
the first place.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
If in btrfs_check_super() we find that the superblock has a csum
mismatch, print the wanted and found values, just as we do for metadata
in __csum_tree_block_size().

When hex-editing a btrfs image, it's useful to use btrfs check to
calculate what the new csum should be. Unfortunately at present this
only works for trees and not for the superblock, meaning you have to use
the much more wordy `btrfs inspect-internal`.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
@kdave kdave force-pushed the devel branch 6 times, most recently from ef43ce6 to 3eff852 Compare May 30, 2025 14:14
@kdave
Copy link
Owner

kdave commented May 30, 2025

Printing the expected and found checksum makes sense but I find the reasoning a bit fishy, why do you need to hex-edit images or not want to use the existing inspect tool.

kdave pushed a commit that referenced this pull request May 30, 2025
If in btrfs_check_super() we find that the superblock has a csum
mismatch, print the wanted and found values, just as we do for metadata
in __csum_tree_block_size().

When hex-editing a btrfs image, it's useful to use btrfs check to
calculate what the new csum should be. Unfortunately at present this
only works for trees and not for the superblock, meaning you have to use
the much more wordy `btrfs inspect-internal`.

Pull-request: #985
Signed-off-by: Mark Harmstone <maharmstone@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
@kdave kdave closed this May 30, 2025
@kdave kdave added this to the v6.15 milestone May 30, 2025
@maharmstone
Copy link
Contributor Author

Printing the expected and found checksum makes sense but I find the reasoning a bit fishy, why do you need to hex-edit images or not want to use the existing inspect tool.

Thanks Dave. Creating faulty images for a btrfs-check test was one reason. It's easy to fix the metadata csum because check itself tells you what it should be; for the superblock, not so much.

adam900710 pushed a commit that referenced this pull request Jun 5, 2025
If in btrfs_check_super() we find that the superblock has a csum
mismatch, print the wanted and found values, just as we do for metadata
in __csum_tree_block_size().

When hex-editing a btrfs image, it's useful to use btrfs check to
calculate what the new csum should be. Unfortunately at present this
only works for trees and not for the superblock, meaning you have to use
the much more wordy `btrfs inspect-internal`.

Pull-request: #985
Signed-off-by: Mark Harmstone <maharmstone@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants