discover: fix sysfs end-of-partition calculation#7
Open
eriknordmark wants to merge 1 commit into
Open
Conversation
The sysfs branch of findDisks computed each partition's last-byte position as `size - start + 1`, which is meaningless arithmetic — the sysfs `size` attribute is the partition's length in sectors, so the inclusive last LBA is `start + size - 1`. The disk-image branch a few dozen lines up uses the correct formula already. partitionData.end flows into calculateResizes (calculate.go:48/53/ 54/63/67/69/106/131/133/134) and run_helpers.go:150 where it participates in every free-space and shrink-target computation, so the wrong end on the sysfs path produced silently wrong layouts whenever partitionresizer is run against a real block device rather than a disk image. Disk-image-only test fixtures hid it from CI. Extend TestFindDisks/all to assert pd.end so the regression is covered. Signed-off-by: eriknordmark <erik@zededa.com> Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
The sysfs branch of
findDisks(discover.go:175) computed each partition's last-byte position assize - start + 1. That's not the right formula for anything; the sysfssizeattribute is the partition's length in sectors, so the inclusive last LBA isstart + size - 1. The disk-image branch a few dozen lines up (discover.go:78) already uses the correct formula:Impact
partitionData.endflows into:calculate.go:48,:53,:54,:63,:67,:69,:106,:131,:133,:134— every free-space and grow-target computation incalculateResizes.run_helpers.go:150— the shrink-target end inplanResizes.So whenever partitionresizer runs against a real block device (which routes through sysfs) rather than a disk image (which routes through the GPT-table branch), the resize plan is computed against silently wrong partition geometry. The disk-image-only test fixtures (
testdata/disk.img,testdata/diskfull.img) hid this from CI.Fix
One-line change:
end := size - start + 1→end := start + size - 1, with a comment explaining the formula matches the disk-image branch.Extend
TestFindDisks/allto assertpd.endso this regression can't slip back through.Test plan
Signed-off-by: eriknordmark erik@zededa.com