package main import ( "fmt" "github.com/Nwflower/reims-go/internal/driver/reims" "github.com/Nwflower/reims-go/internal/host" "github.com/Nwflower/reims-go/internal/i18n" ) // checkStartMemory refuses to start a VM whose guest RAM can't be committed // right now. Without it QEMU exits with "Cannot set up guest memory 'ram'" // (measured 2026-11-28, portable-runtime-spec.md ยง5.1), which says nothing // about what to do. func (a *App) checkStartMemory(c *reims.Client, name string) error { avail, ok := host.CommitAvailGB() if !ok { return nil } d, err := a.GetVMDetail(name) if err != nil { return nil // can't tell; let reims-ctl report its own error } memGB, ok := reims.ParseSizeGB(d.Memory) if !ok { return nil } if memGB+host.StartMarginGB <= avail { return nil } a.mu.Lock() loc := a.cfg.Locale root := a.cfg.DataRoot a.mu.Unlock() rec := host.RecommendedMemoryGB(host.Inspect(root)) return fmt.Errorf("%s", i18n.T(loc, "err.commit_memory", memGB, avail, rec)) }