m/p/erofs: handle metadata alignment correctly
allocateMetadata has an alignment argument but doesn't pass that down
to findBlocks, instead opting to hardcode it to 32.
Pass down the alignment argument and add support for zero alignment to
findBlocks.
This does not cause any functional changes as this function was only
ever called with 32 alignment and once at the zero position with 0
alignment, but the zero position is aligned to every possible
alignment anyways.
Change-Id: Iad44e2a5ae5a99cf9449bba3ec88116e0e009b64
Reviewed-on: https://review.monogon.dev/c/monogon/+/2987
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/pkg/erofs/erofs.go b/metropolis/pkg/erofs/erofs.go
index 3e4ce89..ab87115 100644
--- a/metropolis/pkg/erofs/erofs.go
+++ b/metropolis/pkg/erofs/erofs.go
@@ -78,7 +78,7 @@
panic("cannot allocate a metadata object bigger than BlockSize bytes")
}
sizeU16 := uint16(size)
- pos, ok := w.metadataBlocksFree.findBlock(sizeU16, 32)
+ pos, ok := w.metadataBlocksFree.findBlock(sizeU16, alignment)
if !ok {
blockNumber, err := w.allocateBlocks(1)
if err != nil {
@@ -250,7 +250,10 @@
// metadata block it returns false as the second return value.
func (m metadataBlocksMeta) findBlock(size uint16, alignment uint16) (int64, bool) {
for i, blockMeta := range m {
- freeBytesAligned := blockMeta.freeBytes - (blockMeta.freeBytes % alignment)
+ freeBytesAligned := blockMeta.freeBytes
+ if alignment > 0 {
+ freeBytesAligned = blockMeta.freeBytes - (blockMeta.freeBytes % alignment)
+ }
if freeBytesAligned > size {
m[i] = metadataBlockMeta{
blockNumber: blockMeta.blockNumber,