Fix superblock IO error handling and add footer validation#889
Open
xiaoxichen wants to merge 2 commits into
Open
Fix superblock IO error handling and add footer validation#889xiaoxichen wants to merge 2 commits into
xiaoxichen wants to merge 2 commits into
Conversation
Collaborator
Author
|
@JacksonYao287 this is a replacement PR for #866 could you please take a review |
| m_super_blk_in_footer = m_pdev_info.mirror_super_block; | ||
|
|
||
| // Validate footer superblock consistency if mirroring is enabled | ||
| sanity_check(); |
Contributor
There was a problem hiding this comment.
when we first boot and format a single device in homestore
uint32_t DeviceManager::format_single_device(dev_info& dinfo) {
auto pdev_id = populate_pdev_info(dinfo, attr, m_first_blk_hdr.system_uuid,
fblk->this_pdev_hdr);
auto pdev = std::make_unique< PhysicalDev >(dinfo, oflags, fblk->this_pdev_hdr);
// here, after pdev is created , we then write the superblk.
pdev->write_super_block(buf, sb_size, hs_super_blk::first_block_offset());
}
and we will do sanity_check in the constructor of pdev
PhysicalDev::PhysicalDev(const dev_info& dinfo, int oflags,
const pdev_info_header& pinfo) {
// ...
m_super_blk_in_footer = m_pdev_info.mirror_super_block; // HDD → true
// sanity_check() here is called before super_blk is written.
sanity_check();
}
if we get brand new HDD, that`s fine since all the data(footer and header) we read is 0.
however, if we reuse some HDD from the decommissioned clusters, there probably some legacy data on them. so when we read header and footer and then do memcmp, it is probably crash at line 174 since they are probably different legacy data.
Contributor
There was a problem hiding this comment.
LGTM, only this concerning case
8ef07a3 to
7bf160a
Compare
This change improves superblock error handling and integrity checking: - Fail fast on IO errors during superblock read instead of treating them as fresh/unformatted disks - Add footer superblock validation for HDD devices to detect corruption - Check header and footer write errors independently to prevent silent failures - Add comprehensive unit tests covering all error scenarios Changes: - read_first_block(): Now throws std::system_error on IO errors instead of returning garbage data - write_super_block(): Separately validates header and footer writes with independent error checking - sanity_check(): New method that validates footer consistency on HDD devices by comparing header and footer superblocks using full memcmp - Added 6 unit tests covering IO errors, corruption detection, and footer validation scenarios Use release assert instead of exceptions for superblock IO errors Per review feedback, replace exception throws with HS_REL_ASSERT for all superblock IO errors to ensure immediate crash on failure: - read_first_block(): Use HS_REL_ASSERT instead of throwing std::system_error - sanity_check(): Use HS_REL_ASSERT for header/footer read errors and mismatch - Update tests from ASSERT_THROW to ASSERT_DEATH to verify crash behavior
On first boot (format_devices path), all devices have invalid headers on disk when PhysicalDev is constructed — before write_super_block is called. The original code blindly memcmp'd header vs footer on garbage data, causing a crash on HDD devices where mirror_super_block=1. In load_devices, a device with an invalid header goes to pdevs_to_format and then format_single_device. At that point m_first_blk_hdr (and thus m_pdev_info.system_uuid) is already populated from other valid devices in the cluster. So if the footer on disk is valid and its system_uuid matches, it means the footer survived but the header was corrupted — not a fresh device. If the footer uuid does not match (or footer is invalid), it is leftover/garbage data and safe to treat as first boot. New logic: - Header valid: compare header and footer as before - Header invalid, footer valid + uuid matches cluster: header corruption, assert - Otherwise: first boot / leftover data, skip validation
7bf160a to
6dd7079
Compare
Collaborator
Author
|
@JacksonYao287 comment addressed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change improves superblock error handling and integrity checking:
Changes:
Use release assert instead of exceptions for superblock IO errors
Per review feedback, replace exception throws with HS_REL_ASSERT for all superblock IO errors to ensure immediate crash on failure: