m/p/blockdev: fix discard
Fix various problems with discard. Because discard errors are ignored in
osimage, these problems were not noticed.
Discard takes byte offsets, not block offsets, and multiple places were
missing the multiplication with BlockSize.
The BLKDISCARD and BLKZEROOUT ioctls take start and length, not start
and end.
unix.Fallocate already converts errno 0 to nil.
I manually tested that discard now works correctly in the installer.
Change-Id: I52d9e30a087bb6a792396baaefb2d7d09c43abfe
Reviewed-on: https://review.monogon.dev/c/monogon/+/2953
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Vouch-Run-CI: Lorenz Brun <lorenz@monogon.tech>
diff --git a/metropolis/node/build/mkimage/osimage/osimage.go b/metropolis/node/build/mkimage/osimage/osimage.go
index a09f5d1..d0ccaef 100644
--- a/metropolis/node/build/mkimage/osimage/osimage.go
+++ b/metropolis/node/build/mkimage/osimage/osimage.go
@@ -100,7 +100,7 @@
func Create(params *Params) (*efivarfs.LoadOption, error) {
// Discard the entire device, we're going to write new data over it.
// Ignore errors, this is only advisory.
- params.Output.Discard(0, params.Output.BlockCount())
+ params.Output.Discard(0, params.Output.BlockCount()*params.Output.BlockSize())
tbl, err := gpt.New(params.Output)
if err != nil {