Files
Reims-Go/create_flow.go
T
Nwflower d42a4f85f0 feat(perf): default to NVMe, guard P-core pinning, add Win11 WHPX nested-virt patch
- Default newly created VMs to NVMe disk controller via reims-ctl set (supported by macOS Recovery, installer, and installed guests)
- Guard P-core affinity pinning with CanSafelyPinPCores (require P-core logical CPUs >= vmCPUs+1) to prevent XNU spinlock stalls on non-HT hybrid CPUs such as Intel Core Ultra 9 285H (6P/6T + 8E), and include logical thread counts in CPU pinning logs
- Add patches/qemu-whpx-nested-virt-nonfatal.patch (registered in patches/README.md & docs/portable-runtime-spec.md) to make WHvSetPartitionProperty(NestedVirtualization) hr=0x80370302 non-fatal so Win11 retains kernel-irqchip=on, and detect the patch in host optimizations and WHPX compat pre-apply
2026-11-28 08:22:01 -07:00

86 lines
2.9 KiB
Go

package main
import (
"context"
"errors"
"fmt"
"strings"
"github.com/Nwflower/reims-go/internal/driver/reims"
"github.com/Nwflower/reims-go/internal/installer"
rt "github.com/Nwflower/reims-go/internal/runtime"
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
)
func (a *App) createVMFlow(opts reims.CreateOpts) error {
if issues := a.ValidateCreate(opts); len(issues) > 0 {
return fmt.Errorf("%s", issues[0].Message)
}
a.mu.Lock()
cfgCopy := *a.cfg
a.mu.Unlock()
active, err := rt.ResolveActive(&cfgCopy)
if err != nil {
return err
}
c := reims.NewClient(&cfgCopy, *active)
// Always defer starting to StartVM so commit-memory checks, Win10 cold-reboot
// QMP wiring, and Win11 WHPX nested-virt fallback apply uniformly.
startAfterCreate := opts.Start
opts.Start = false
ctx, cancel := context.WithCancel(a.baseCtx())
defer cancel()
taskID, w, finishTask := a.ctlTaskWriterWithCancel("vm-create", opts.Name, cancel)
a.emitLog(opts.Name, "Creating VM "+opts.Name+"...")
existingVMs, _ := c.List(ctx)
if removed, rerr := reims.CleanAbortedCreateDir(cfgCopy.XDGDataDir(), opts, existingVMs); rerr != nil {
a.emitLog(opts.Name, "Warning: could not clean unfinished VM directory: "+rerr.Error())
} else if removed != "" {
a.emitLog(opts.Name, "Removed unfinished directory from an earlier interrupted create: "+removed)
}
// Pre-fetch OcBinaryData with an idle-read timeout so slow GitHub links do
// not trigger reims-util's 180s HTTP-200 truncate-and-restart loop.
if installer.ShouldPrefetchOcBinaryData(active.Manifest.UtilCommit, active.Manifest.UtilVersion) {
loggedPrefetch := false
perr := installer.EnsureCachedAsset(ctx, cfgCopy.XDGCacheDir(), installer.OcBinaryDataAsset, nil, func(u installer.Update) {
if !loggedPrefetch && u.Kind == installer.KindStep {
loggedPrefetch = true
a.emitLog(opts.Name, opts.Name+": "+u.Message)
}
tasks.update(taskID, u)
})
if perr != nil {
if errors.Is(perr, context.Canceled) {
finishTask(perr)
a.emitLog(opts.Name, "Create canceled.")
return perr
}
a.emitLog(opts.Name, "Pre-fetch OpenCore resources skipped (reims-ctl will retry): "+perr.Error())
}
}
err = c.Create(ctx, opts, w, w)
if err != nil {
finishTask(err)
a.emitLog(opts.Name, "Create error: "+err.Error())
return err
}
if dc := reims.EffectiveCreateDiskController(opts); dc != "ahci" {
a.emitLog(opts.Name, fmt.Sprintf("Setting disk controller for %s to %s...", opts.Name, strings.ToUpper(dc)))
if serr := c.Set(ctx, reims.SetOpts{Name: opts.Name, DiskController: dc}, w, w); serr != nil {
a.emitLog(opts.Name, fmt.Sprintf("Warning: could not switch disk controller to %s (keeping SATA/AHCI): %v", dc, serr))
}
}
finishTask(nil)
a.emitLog(opts.Name, "VM "+opts.Name+" ready.")
wailsRuntime.EventsEmit(a.ctx, "reims:state-changed", true)
if startAfterCreate {
return a.StartVM(opts.Name)
}
return nil
}