daemon: build the work disk fresh instead of cloning the seed file
Old flow on every 'banger vm run' that hit the seeded path: CopyFilePreferClone the seed file (FICLONE attempt + io.Copy + fsync fallback), then e2fsck -fp + resize2fs to grow the FS to the spec size. On filesystems without reflink support that meant pushing 512+ MiB through the kernel followed by a full filesystem check and resize, even though the seed only carries a few KB of dotfiles — minWorkSeedBytes is 512 MiB but the actual payload is tiny. That is the minute-long stall on the 'cloning work seed' stage users see today. Replace the copy with a sized fresh ext4: truncate to WorkDiskSizeBytes, mkfs.ext4 -F -E root_owner=0:0, debugfs rdump to extract the seed's contents, then ingest each file via the sudoless ext4 toolkit (MkdirExt4 / WriteExt4FileOwned, root:root, mode preserved). Sub-second regardless of seed size or requested work-disk size; no fsck or resize needed because the FS is created at its final size from the start. Also drop the now-implementation-pinned TestEnsureWorkDiskClonesSeedImageAndResizes — its premise (a scripted e2fsck/resize2fs sequence) no longer reflects the code, and smoke covers the new flow end to end. Stage label changed from 'cloning work seed' to 'applying work seed' to match what actually happens. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
6c37fec17b
commit
a3a51e06c4
3 changed files with 57 additions and 54 deletions
|
|
@ -16,44 +16,6 @@ import (
|
|||
"banger/internal/model"
|
||||
)
|
||||
|
||||
func TestEnsureWorkDiskClonesSeedImageAndResizes(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
vmDir := t.TempDir()
|
||||
seedPath := filepath.Join(t.TempDir(), "root.work-seed.ext4")
|
||||
if err := os.WriteFile(seedPath, []byte("seed-data"), 0o644); err != nil {
|
||||
t.Fatalf("WriteFile(seed): %v", err)
|
||||
}
|
||||
workDiskPath := filepath.Join(vmDir, "root.ext4")
|
||||
runner := &scriptedRunner{
|
||||
t: t,
|
||||
steps: []runnerStep{
|
||||
{call: runnerCall{name: "e2fsck", args: []string{"-p", "-f", workDiskPath}}},
|
||||
{call: runnerCall{name: "resize2fs", args: []string{workDiskPath}}},
|
||||
},
|
||||
}
|
||||
d := &Daemon{runner: runner}
|
||||
wireServices(d)
|
||||
vm := testVM("seeded", "image-seeded", "172.16.0.60")
|
||||
vm.Runtime.WorkDiskPath = workDiskPath
|
||||
vm.Spec.WorkDiskSizeBytes = 2 * 1024 * 1024
|
||||
image := testImage("image-seeded")
|
||||
image.WorkSeedPath = seedPath
|
||||
|
||||
if _, err := d.vm.ensureWorkDisk(context.Background(), &vm, image); err != nil {
|
||||
t.Fatalf("ensureWorkDisk: %v", err)
|
||||
}
|
||||
runner.assertExhausted()
|
||||
|
||||
info, err := os.Stat(workDiskPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Stat(work disk): %v", err)
|
||||
}
|
||||
if info.Size() != vm.Spec.WorkDiskSizeBytes {
|
||||
t.Fatalf("work disk size = %d, want %d", info.Size(), vm.Spec.WorkDiskSizeBytes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTapPoolWarmsAndReusesIdleTap(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package daemon
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
|
@ -92,23 +91,16 @@ func (s *VMService) ensureWorkDisk(ctx context.Context, vm *model.VMRecord, imag
|
|||
return workDiskPreparation{}, nil
|
||||
}
|
||||
if exists(image.WorkSeedPath) {
|
||||
vmCreateStage(ctx, "prepare_work_disk", "cloning work seed")
|
||||
if err := system.CopyFilePreferClone(image.WorkSeedPath, vm.Runtime.WorkDiskPath); err != nil {
|
||||
vmCreateStage(ctx, "prepare_work_disk", "applying work seed")
|
||||
// Old flow used CopyFilePreferClone + (e2fsck + resize2fs).
|
||||
// On filesystems without reflink support that meant pushing
|
||||
// every byte of a 512+ MiB seed through the kernel followed
|
||||
// by a full fsck/resize, even though the seed itself only
|
||||
// holds a few KB of dotfiles. mkfs + ingest runs in roughly
|
||||
// a second regardless of seed or work-disk size.
|
||||
if err := system.MaterializeWorkDisk(ctx, s.runner, image.WorkSeedPath, vm.Runtime.WorkDiskPath, vm.Spec.WorkDiskSizeBytes); err != nil {
|
||||
return workDiskPreparation{}, err
|
||||
}
|
||||
seedInfo, err := os.Stat(image.WorkSeedPath)
|
||||
if err != nil {
|
||||
return workDiskPreparation{}, err
|
||||
}
|
||||
if vm.Spec.WorkDiskSizeBytes < seedInfo.Size() {
|
||||
return workDiskPreparation{}, fmt.Errorf("requested work disk size %d is smaller than seed image %d", vm.Spec.WorkDiskSizeBytes, seedInfo.Size())
|
||||
}
|
||||
if vm.Spec.WorkDiskSizeBytes > seedInfo.Size() {
|
||||
vmCreateStage(ctx, "prepare_work_disk", "resizing work disk")
|
||||
if err := system.ResizeExt4Image(ctx, s.runner, vm.Runtime.WorkDiskPath, vm.Spec.WorkDiskSizeBytes); err != nil {
|
||||
return workDiskPreparation{}, err
|
||||
}
|
||||
}
|
||||
return workDiskPreparation{ClonedFromSeed: true}, nil
|
||||
}
|
||||
// No seed: build an empty work disk. `-E root_owner=0:0` stamps
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue