Share redaction and GPU log diagnosis outside the macOS client, move snapshot validation to the driver contract, and delete superseded App storage implementations.
69 lines
2.6 KiB
Go
69 lines
2.6 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/Nwflower/reims-go/internal/driver"
|
|
)
|
|
|
|
// ResizeVMDisk expands a stopped VM's virtual disk through its owning driver.
|
|
func (a *App) ResizeVMDisk(name, newSize string) (driver.DiskResizeResult, error) {
|
|
return a.ResizeVMDiskWithDriver("", name, newSize)
|
|
}
|
|
func (a *App) ResizeVMDiskWithDriver(driverID, name, newSize string) (driver.DiskResizeResult, error) {
|
|
a.mu.Lock()
|
|
svc := a.lifecycleSvc
|
|
a.mu.Unlock()
|
|
if svc == nil {
|
|
return driver.DiskResizeResult{}, errors.New("driver lifecycle is not initialized")
|
|
}
|
|
ref := driver.VMRef{DriverID: driverID, Name: name}
|
|
taskCtx, cancel := context.WithCancel(a.baseCtx())
|
|
defer cancel()
|
|
_, w, finishTask := a.ctlTaskWriterWithCancel("vm-disk-resize", ref.Key(), cancel)
|
|
a.emitVMLogForDriver(driverID, name, fmt.Sprintf("Resizing disk for %s (%s)...", name, strings.TrimSpace(newSize)))
|
|
res, err := svc.ResizeDisk(taskCtx, ref, newSize, w, w)
|
|
if err != nil {
|
|
finishTask(err)
|
|
a.emitVMLogForDriver(driverID, name, "Disk resize error: "+err.Error())
|
|
return driver.DiskResizeResult{}, err
|
|
}
|
|
finishTask(nil)
|
|
a.emitVMLogForDriver(driverID, name, fmt.Sprintf("Expanded disk for %s: %.0f GB -> %.0f GB", name, float64(res.OldVirtualBytes)/float64(1<<30), float64(res.NewVirtualBytes)/float64(1<<30)))
|
|
a.wakePoll()
|
|
a.emitLifecycleStateChanged()
|
|
return res, nil
|
|
}
|
|
|
|
// CompactVMDisk reclaims unused host space through the owning driver.
|
|
func (a *App) CompactVMDisk(name string) (driver.DiskCompactResult, error) {
|
|
return a.CompactVMDiskWithDriver("", name)
|
|
}
|
|
func (a *App) CompactVMDiskWithDriver(driverID, name string) (driver.DiskCompactResult, error) {
|
|
a.mu.Lock()
|
|
svc := a.lifecycleSvc
|
|
a.mu.Unlock()
|
|
if svc == nil {
|
|
return driver.DiskCompactResult{}, errors.New("driver lifecycle is not initialized")
|
|
}
|
|
ref := driver.VMRef{DriverID: driverID, Name: name}
|
|
taskCtx, cancel := context.WithCancel(a.baseCtx())
|
|
defer cancel()
|
|
_, w, finishTask := a.ctlTaskWriterWithCancel("vm-disk-compact", ref.Key(), cancel)
|
|
a.emitVMLogForDriver(driverID, name, fmt.Sprintf("Compacting disk for %s to reclaim unused space...", name))
|
|
res, err := svc.CompactDisk(taskCtx, ref, w, w)
|
|
if err != nil {
|
|
finishTask(err)
|
|
a.emitVMLogForDriver(driverID, name, "Disk compact error: "+err.Error())
|
|
return driver.DiskCompactResult{}, err
|
|
}
|
|
finishTask(nil)
|
|
a.emitVMLogForDriver(driverID, name, fmt.Sprintf("Compacted disk for %s: %.2f GB -> %.2f GB (reclaimed %.2f GB)", name, float64(res.BeforeBytes)/float64(1<<30), float64(res.AfterBytes)/float64(1<<30), float64(res.ReclaimedBytes)/float64(1<<30)))
|
|
a.wakePoll()
|
|
a.emitLifecycleStateChanged()
|
|
return res, nil
|
|
}
|