Skip to content

Commit

Permalink
feat(cmd/rofl): Pad rootfs partition to allow for growth during upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Jan 17, 2025
1 parent 7f496df commit a460e7c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
16 changes: 16 additions & 0 deletions cmd/rofl/build/artifacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,22 @@ func concatFiles(a, b string) error {
return err
}

// padWithEmptySpace pads the given file with empty space to make it the given size. See
// `appendEmptySpace` for details.
func padWithEmptySpace(fn string, size uint64) error {
fi, err := os.Stat(fn)
if err != nil {
return err
}

currentSize := uint64(fi.Size())
if currentSize >= size {
return nil
}
_, err = appendEmptySpace(fn, size - currentSize, 1)
return err
}

// appendEmptySpace appends empty space to the given file. If the filesystem supports sparse files,
// this should not actually take any extra space.
//
Expand Down
22 changes: 14 additions & 8 deletions cmd/rofl/build/tdx.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,26 +244,32 @@ func tdxBundleComponent(
fmt.Sprintf("oasis.stage2.storage_size=%d", manifest.Resources.Storage.Size*1024*1024),
)
case buildRofl.StorageKindDiskEphemeral, buildRofl.StorageKindDiskPersistent:
// Allocate some space after regular stage2.
const sectorSize = 512
storageSize := manifest.Resources.Storage.Size * 1024 * 1024
storageOffset, err := appendEmptySpace(stage2.fn, storageSize, sectorSize)
if err != nil {
return err
}

var storageMode string
switch storageKind {
case buildRofl.StorageKindDiskPersistent:
// Persistent storage needs to be set up by stage 2.
storageMode = "custom"

// Add some sparse padding to allow for growth of the root partition during upgrades.
// Note that this will not actually take any space so it could be arbitrarily large.
if err := padWithEmptySpace(stage2.fn, 256*1024*1024); err != nil {
return err
}

// TODO: (Oasis Core 25.0+) Set comp.TDX.Stage2Persist = true
case buildRofl.StorageKindDiskEphemeral:
// Ephemeral storage can be set up by stage 1 directly.
storageMode = "disk"
}

// Allocate some space after regular stage2.
const sectorSize = 512
storageSize := manifest.Resources.Storage.Size * 1024 * 1024
storageOffset, err := appendEmptySpace(stage2.fn, storageSize, sectorSize)
if err != nil {
return err
}

comp.TDX.ExtraKernelOptions = append(comp.TDX.ExtraKernelOptions,
fmt.Sprintf("oasis.stage2.storage_mode=%s", storageMode),
fmt.Sprintf("oasis.stage2.storage_size=%d", storageSize/sectorSize),
Expand Down

0 comments on commit a460e7c

Please sign in to comment.