Share redaction and GPU log diagnosis outside the macOS client, move snapshot validation to the driver contract, and delete superseded App storage implementations.
67 lines
2.1 KiB
Go
67 lines
2.1 KiB
Go
package driver
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
// DiskSnapshot is a driver-neutral restore point description.
|
|
type DiskSnapshot struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
VMStateBytes int64 `json:"vm_state_bytes"`
|
|
}
|
|
|
|
// DiskResizeResult describes a virtual-disk expansion and the guest follow-up command.
|
|
type DiskResizeResult struct {
|
|
Path string `json:"path"`
|
|
OldVirtualBytes uint64 `json:"old_virtual_bytes"`
|
|
NewVirtualBytes uint64 `json:"new_virtual_bytes"`
|
|
GuestExpandCmd string `json:"guest_expand_cmd"`
|
|
}
|
|
|
|
// DiskCompactResult describes host space reclaimed by rewriting a disk.
|
|
type DiskCompactResult struct {
|
|
Path string `json:"path"`
|
|
BeforeBytes uint64 `json:"before_bytes"`
|
|
AfterBytes uint64 `json:"after_bytes"`
|
|
ReclaimedBytes uint64 `json:"reclaimed_bytes"`
|
|
}
|
|
|
|
// ValidateSnapshotName checks a restore-point tag without assuming a disk engine.
|
|
func ValidateSnapshotName(snapName string) (string, error) {
|
|
snapName = strings.TrimSpace(snapName)
|
|
if snapName == "" {
|
|
return "", fmt.Errorf("snapshot name is required")
|
|
}
|
|
if len([]rune(snapName)) > 64 {
|
|
return "", fmt.Errorf("snapshot name must be 64 characters or fewer")
|
|
}
|
|
for _, r := range snapName {
|
|
if r < 0x20 || r == 0x7f || r == 34 || r == 39 || r == 96 || r == 92 {
|
|
return "", fmt.Errorf("snapshot name contains invalid characters")
|
|
}
|
|
}
|
|
return snapName, nil
|
|
}
|
|
|
|
// SnapshotDriver exposes driver-owned restore points.
|
|
type SnapshotDriver interface {
|
|
ListSnapshots(context.Context, string) ([]DiskSnapshot, error)
|
|
RunSnapshot(context.Context, string, string, string, io.Writer, io.Writer) error
|
|
}
|
|
|
|
// CloneDriver creates a copy-on-write VM from a stopped source VM.
|
|
type CloneDriver interface {
|
|
CloneCoW(context.Context, string, string, io.Writer, io.Writer) error
|
|
}
|
|
|
|
// DiskDriver exposes online-safe orchestration around driver-owned disk images.
|
|
type DiskDriver interface {
|
|
ResizeDisk(context.Context, string, string, io.Writer, io.Writer) (DiskResizeResult, error)
|
|
CompactDisk(context.Context, string, io.Writer, io.Writer) (DiskCompactResult, error)
|
|
}
|