{"modulePath":"github.com/kernel/hypeman","version":"v0.4.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package hypervisor\n\nPackage hypervisor provides an abstraction layer for virtual machine managers. This allows the instances package to work with different hypervisors (e.g., Cloud Hypervisor, QEMU) through a common interface.\n\n## Constants\n\n```go\nconst (\n\t// FeatureSnapshots: snapshot/restore of instance state.\n\tFeatureSnapshots = \"snapshots\"\n\t// FeatureStandby: pause + memory snapshot, with later restore.\n\tFeatureStandby = \"standby\"\n\t// FeatureFork: cloning an instance from a stopped source. Derived from\n\t// the explicit SupportsFork capability, which each backend keeps aligned\n\t// with its VMStarter.PrepareFork implementation. Fork of a standby or\n\t// running source additionally restores/creates snapshots, so clients\n\t// must gate those operations on FeatureStandby as well — vz on macOS 13\n\t// advertises fork (stopped-source clones need no machine-state\n\t// save/restore) without snapshots or standby.\n\tFeatureFork = \"fork\"\n\t// FeaturePause: pause/resume of a running instance.\n\tFeaturePause = \"pause\"\n\t// FeatureHotplugMemory: live memory resize.\n\tFeatureHotplugMemory = \"hotplug-memory\"\n\t// FeatureBalloonControl: runtime balloon target changes.\n\tFeatureBalloonControl = \"balloon-control\"\n\t// FeatureVsock: guest vsock communication.\n\tFeatureVsock = \"vsock\"\n\t// FeatureGPUPassthrough: GPU/PCI device passthrough.\n\tFeatureGPUPassthrough = \"gpu-passthrough\"\n\t// FeatureDiskIOLimit: disk I/O rate limiting.\n\tFeatureDiskIOLimit = \"disk-io-limit\"\n\t// FeatureDiskResize: live disk resize.\n\tFeatureDiskResize = \"disk-resize\"\n)\n```\nStable per-runtime feature IDs derived from Capabilities. These are part of the public capabilities API contract: clients gate behavior on these IDs rather than on hypervisor names. Adding a client-visible Capabilities field means adding its ID here, deriving it in FeatureIDs, and documenting it in the OpenAPI CapabilitiesRuntime schema — HTTP handlers never derive feature lists themselves.\n\n```go\nconst VFIOTermGrace = 5 * time.Second\n```\nVFIOTermGrace allows VFIO teardown to finish after SIGTERM before SIGKILL; SIGKILL during initialization can wedge the VF, while teardown takes 1-2s.\n\n## Variables\n\n```go\nvar (\n\t// ErrHypervisorNotRunning is returned when trying to connect to a hypervisor\n\t// that is not currently running or cannot be reconnected to.\n\tErrHypervisorNotRunning = errors.New(\"hypervisor is not running\")\n\n\t// ErrNotSupported is returned when an operation is not supported by the hypervisor.\n\tErrNotSupported = errors.New(\"operation not supported by this hypervisor\")\n)\n```\nCommon errors\n\n```go\nvar ErrNoOwningProcess = errors.New(\"no owning process found\")\n```\n\n## Functions\n\n```go\nfunc FinishTraceSpan(span trace.Span, err error)\n```\n\n```go\nfunc LockSnapshotSourceAliasMutation() func()\n```\nLockSnapshotSourceAliasMutation serializes the short Firecracker restore window where a snapshotted source guest directory is temporarily replaced by a symlink to the fork being restored.\n\n```go\nfunc LockSnapshotSourceAliasReaders() func()\n```\nLockSnapshotSourceAliasReaders blocks source-directory readers while a snapshot source alias mutation is active.\n\n```go\nfunc ProcessEnv() []string\n```\nProcessEnv returns the environment for a VMM or helper process.\n\n```go\nfunc RegisterCapabilities(t Type, caps Capabilities)\n```\nRegisterCapabilities registers a static capability set for a hypervisor type with no launch check, so registration alone implies launchability.\n\nDeprecated: Use RegisterRuntime, which resolves capabilities per registry read (so configuration applied after init stays truthful) and supports an optional LaunchCheck for host launch prerequisites. RegisterCapabilities is kept so custom backends built against earlier versions of this module keep compiling; it wraps RegisterRuntime with a resolver that returns the given set unchanged.\n\n```go\nfunc RegisterClientFactory(t Type, factory ClientFactory)\n```\nRegisterClientFactory registers a Hypervisor client factory.\n\n```go\nfunc RegisterRuntime(t Type, reg RuntimeRegistration)\n```\nRegisterRuntime registers a hypervisor backend in the capability registry. Backends must register only on platforms where they can genuinely launch VMs: the Linux backends (cloud-hypervisor, firecracker, qemu) register from linux-only files, and vz registers from its darwin-only package. That keeps RegisteredRuntimes truthful without a hand-maintained platform switch.\n\n```go\nfunc RegisterSocketName(t Type, name string)\n```\nRegisterSocketName registers the socket filename for a hypervisor type. Called by each hypervisor implementation's init() function.\n\n```go\nfunc RegisterVsockDialerFactory(t Type, factory VsockDialerFactory)\n```\nRegisterVsockDialerFactory registers a VsockDialer factory for a hypervisor type. Called by each hypervisor implementation's init() function.\n\n```go\nfunc RegisterVsockSocketName(t Type, name string)\n```\nRegisterVsockSocketName registers the vsock socket filename for a hypervisor type.\n\n```go\nfunc ResolveProcessPID(socketPath string) (pid int, err error)\n```\nResolveProcessPID finds the process currently holding the listening Unix socket for the given hypervisor control path, via the socket inode in /proc/net/unix and each process's fd table. The fd scan requires the caller to hold CAP\\_SYS\\_PTRACE (or run as root) so no live owner is missed; an ErrNoOwningProcess result is proof the listener is gone.\n\n```go\nfunc ResolveProcessPIDForOwner(socketPath string, ownerPID int) (pid int, err error)\n```\nResolveProcessPIDForOwner resolves a socket while preferring an expected owner when the socket descriptor is temporarily shared with a child process.\n\n```go\nfunc ShouldTraceHypervisorHTTPSpan(method, path string) bool\n```\n\n```go\nfunc SocketCacheKey(socketPath string) string\n```\nSocketCacheKey returns a cache key that changes when a Unix socket path is recreated, preventing stale state from being reused across VM restarts.\n\n```go\nfunc SocketNameForType(t Type) string\n```\nSocketNameForType returns the socket filename for a hypervisor type. Falls back to type + \".sock\" if not registered.\n\n```go\nfunc StartDetachedTraceSpan(ctx context.Context, tracer trace.Tracer, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)\n```\n\n```go\nfunc StartImplementationSpan(ctx context.Context, hvType Type, name string, attrs ...attribute.KeyValue) (context.Context, trace.Span)\n```\n\n```go\nfunc StartProcessSpan(ctx context.Context, hvType Type) (context.Context, trace.Span)\n```\n\n```go\nfunc TraceAttributesFromContext(ctx context.Context) []attribute.KeyValue\n```\n\n```go\nfunc VZShimPIDs(string) ([]int, error)\n```\nVZShimPIDs finds vz-shim processes, which only run on macOS hosts.\n\n```go\nfunc ValidateBootConfig(cfg VMConfig) error\n```\nValidateBootConfig validates boot and disk fields shared by hypervisor backends.\n\n```go\nfunc ValidateDirectRawConfig(backend string, cfg VMConfig) error\n```\nValidateDirectRawConfig preserves the Linux-only contract of backends that do not implement firmware boot or qcow2 disks.\n\n```go\nfunc VsockSocketNameForType(t Type) string\n```\nVsockSocketNameForType returns the vsock socket filename for a hypervisor type. Falls back to \"vsock.sock\" when a hypervisor doesn't require a custom name.\n\n```go\nfunc WithTraceAttributes(ctx context.Context, attrs ...attribute.KeyValue) context.Context\n```\n\n## Types\n\n```go\ntype BalloonTargetCache struct {\n\t// contains filtered or unexported fields\n}\n```\nBalloonTargetCache keeps the last requested guest-memory target warm across reconnects and Hypeman restarts.\n\n```go\nfunc (c *BalloonTargetCache) Delete(socketPath string)\n```\n\n```go\nfunc (c *BalloonTargetCache) Load(socketPath string) (int64, bool)\n```\n\n```go\nfunc (c *BalloonTargetCache) Store(socketPath string, bytes int64)\n```\n\n```go\ntype BootMode string\n```\n\n```go\nconst (\n\tBootModeDirect BootMode = \"direct\"\n\tBootModeUEFI   BootMode = \"uefi\"\n\tBootModeMacOS  BootMode = \"macos\"\n)\n```\n\n```go\ntype CPUTopology struct {\n\tThreadsPerCore int\n\tCoresPerDie    int\n\tDiesPerPackage int\n\tPackages       int\n}\n```\nCPUTopology defines the virtual CPU topology\n\n```go\ntype Capabilities struct {\n\t// SupportsMacOSBoot indicates the backend can cold-boot an imported macOS disk bundle.\n\tSupportsMacOSBoot bool\n\n\t// SupportsSnapshot indicates if Snapshot/Restore are available\n\tSupportsSnapshot bool\n\n\t// SupportsFork indicates VMStarter.PrepareFork implements instance\n\t// forking, which every fork source state needs. It is explicit rather\n\t// than derived from SupportsSnapshot because the two are independent in\n\t// both directions: a snapshot-capable backend may still reject\n\t// PrepareFork with ErrNotSupported, and a backend can fork a stopped\n\t// source (a disk clone, no machine-state snapshot involved) without\n\t// snapshot support at all — vz does exactly that on macOS 13. Forking a\n\t// standby or running source additionally restores/creates snapshots, so\n\t// those operations require SupportsStandby() as well; SupportsFork alone\n\t// promises only the stopped-source fork.\n\tSupportsFork bool\n\n\t// SupportsHotplugMemory indicates if ResizeMemory is available\n\tSupportsHotplugMemory bool\n\n\t// SupportsBalloonControl indicates if runtime balloon target changes are available.\n\tSupportsBalloonControl bool\n\n\t// SupportsPause indicates if Pause/Resume are available\n\tSupportsPause bool\n\n\t// SupportsVsock indicates if vsock communication is available\n\tSupportsVsock bool\n\n\t// SupportsUEFIBoot indicates if firmware boot is available.\n\tSupportsUEFIBoot bool\n\n\t// SupportsTPM indicates if a software TPM can be attached at boot.\n\tSupportsTPM bool\n\n\t// SupportsGPUPassthrough indicates if PCI device passthrough is available\n\tSupportsGPUPassthrough bool\n\n\t// SupportsDiskIOLimit indicates if disk I/O rate limiting is available\n\tSupportsDiskIOLimit bool\n\n\t// SupportsGracefulVMMShutdown indicates the hypervisor exposes an API to\n\t// ask the VMM process itself to exit cleanly.\n\tSupportsGracefulVMMShutdown bool\n\n\t// SupportsSnapshotBaseReuse indicates snapshots can safely reuse a retained\n\t// on-disk base across restore/standby cycles.\n\tSupportsSnapshotBaseReuse bool\n\n\t// RequiresHostSnapshotVersion means memory snapshots are tied to the\n\t// currently installed host binary; the backend cannot launch a historical\n\t// version selected from instance metadata. Generic lifecycle code therefore\n\t// records the installed version on every cold start and treats a failure to\n\t// detect it as fatal.\n\t//\n\t// For example, qemu-microvm uses the host's qemu-system binary. A standby\n\t// snapshot written by QEMU 8.2 cannot be restored after the host upgrades to\n\t// QEMU 9.0. Firecracker snapshots are also version-sensitive, but Firecracker\n\t// leaves this false because Hypeman can launch the managed binary version\n\t// recorded in instance metadata; Cloud Hypervisor is managed the same way.\n\tRequiresHostSnapshotVersion bool\n\n\t// SupportsConcurrentForkPrepare indicates stopped/standby forks can prepare\n\t// separate target snapshots concurrently from the same source.\n\tSupportsConcurrentForkPrepare bool\n\n\t// SupportsDiskResize indicates if live disk resizing (/vm.resize-disk) is available.\n\t// Cloud Hypervisor v50.0+ only.\n\tSupportsDiskResize bool\n}\n```\nCapabilities indicates which optional features a hypervisor supports. Callers should check these before calling optional methods.\n\n```go\nfunc CapabilitiesForType(t Type) (Capabilities, bool)\n```\nCapabilitiesForType returns the effective capabilities for a hypervisor type, resolved at call time. It reports ok=false for runtimes that cannot run on the current host platform, because such runtimes never register.\n\n```go\nfunc (c Capabilities) FeatureIDs() []string\n```\nFeatureIDs returns the stable feature IDs implied by this capability set, in a fixed deterministic order. Only client-visible features are included; internal lifecycle hints (snapshot base reuse, host snapshot version pinning, graceful VMM shutdown) are implementation details and deliberately have no IDs. The result is always non-nil so it serializes as an empty JSON array rather than null.\n\n```go\nfunc (c Capabilities) SupportsStandby() bool\n```\nSupportsStandby reports whether standby is genuinely available. Standby pauses the VM and then snapshots its memory, so it requires both pause and snapshot support — neither alone is sufficient.\n\n```go\ntype ClientFactory func(socketPath string) (Hypervisor, error)\n```\nClientFactory creates Hypervisor client instances for a hypervisor type.\n\n```go\ntype DiskConfig struct {\n\tPath       string\n\tFormat     DiskFormat\n\tReadonly   bool\n\tParents    []string // vz only: read-only images below Path, base first; Path is their ASIF overlay\n\tIOBps      int64    // Sustained I/O rate limit in bytes/sec (0 = unlimited)\n\tIOBurstBps int64    // Burst I/O rate in bytes/sec (0 = same as IOBps)\n}\n```\nDiskConfig represents a disk attached to the VM\n\n```go\nfunc (d DiskConfig) EffectiveFormat() DiskFormat\n```\nEffectiveFormat preserves raw disks for existing callers.\n\n```go\ntype DiskFormat string\n```\n\n```go\nconst (\n\tDiskFormatRaw   DiskFormat = \"raw\"\n\tDiskFormatQCOW2 DiskFormat = \"qcow2\"\n\t// DiskFormatASIF is an ASIF overlay on its Parents, only for macOS boot disks.\n\tDiskFormatASIF DiskFormat = \"asif\"\n)\n```\n\n```go\ntype FirmwareConfig struct {\n\tCodePath   string\n\tVarsPath   string\n\tSecureBoot bool\n}\n```\nFirmwareConfig describes UEFI firmware files. CodePath is immutable firmware; VarsPath is per-instance writable variable storage.\n\n```go\ntype ForkNetworkConfig struct {\n\tTAPDevice string\n\tIP        string\n\tMAC       string\n\tNetmask   string\n}\n```\nForkNetworkConfig contains network identity fields for fork preparation.\n\n```go\ntype ForkPrepareRequest struct {\n\t// SnapshotConfigPath is optional. When empty, implementations should only\n\t// validate fork support and return without snapshot rewrites.\n\tSnapshotConfigPath string\n\n\tSourceDataDir string\n\tTargetDataDir string\n\n\tVsockCID    int64\n\tVsockSocket string\n\n\tSerialLogPath string\n\tNetwork       *ForkNetworkConfig\n}\n```\nForkPrepareRequest contains hypervisor-specific fork preparation inputs.\n\n```go\ntype ForkPrepareResult struct {\n\t// VsockCIDUpdated indicates whether snapshot state was updated to use\n\t// ForkPrepareRequest.VsockCID.\n\tVsockCIDUpdated bool\n\n\t// RequiresSnapshotSourceAlias indicates the restored fork still depends on\n\t// temporarily aliasing the source data directory during snapshot load.\n\tRequiresSnapshotSourceAlias bool\n}\n```\nForkPrepareResult describes which optional fork rewrites were actually applied.\n\n```go\ntype GuestMemoryConfig struct {\n\tEnableBalloon     bool\n\tFreePageReporting bool\n\tDeflateOnOOM      bool\n\tFreePageHinting   bool\n\t// RequireBalloon controls whether VM startup should fail if balloon setup fails.\n\tRequireBalloon bool\n}\n```\nGuestMemoryConfig contains hypervisor-agnostic guest memory feature toggles.\n\n```go\ntype Hypervisor interface {\n\t// DeleteVM sends a graceful shutdown signal to the guest.\n\tDeleteVM(ctx context.Context) error\n\n\t// Shutdown stops the VMM process gracefully.\n\tShutdown(ctx context.Context) error\n\n\t// GetVMInfo returns current VM state information.\n\tGetVMInfo(ctx context.Context) (*VMInfo, error)\n\n\t// Pause suspends VM execution.\n\t// Check Capabilities().SupportsPause before calling.\n\tPause(ctx context.Context) error\n\n\t// Resume continues VM execution after pause.\n\t// Check Capabilities().SupportsPause before calling.\n\tResume(ctx context.Context) error\n\n\t// Snapshot creates a VM snapshot at the given path.\n\t// Check Capabilities().SupportsSnapshot before calling.\n\tSnapshot(ctx context.Context, destPath string) error\n\n\t// ResizeMemory changes the VM's memory allocation.\n\t// Check Capabilities().SupportsHotplugMemory before calling.\n\tResizeMemory(ctx context.Context, bytes int64) error\n\n\t// ResizeMemoryAndWait changes the VM's memory allocation and waits for it to stabilize.\n\t// This polls until the actual memory size matches the target or stabilizes.\n\t// Check Capabilities().SupportsHotplugMemory before calling.\n\tResizeMemoryAndWait(ctx context.Context, bytes int64, timeout time.Duration) error\n\n\t// SetTargetGuestMemoryBytes adjusts the runtime balloon target so the guest\n\t// sees the requested amount of RAM.\n\t// Check Capabilities().SupportsBalloonControl before calling.\n\tSetTargetGuestMemoryBytes(ctx context.Context, bytes int64) error\n\n\t// GetTargetGuestMemoryBytes returns the current guest-visible RAM target after\n\t// runtime ballooning is applied.\n\t// Check Capabilities().SupportsBalloonControl before calling.\n\tGetTargetGuestMemoryBytes(ctx context.Context) (int64, error)\n\n\t// Capabilities returns what features this hypervisor supports.\n\tCapabilities() Capabilities\n}\n```\nHypervisor defines the interface for VM control operations. A Hypervisor client is returned by VMStarter.StartVM after the VM is running.\n\n```go\nfunc NewClient(hvType Type, socketPath string) (Hypervisor, error)\n```\nNewClient creates a Hypervisor client for the given type and socket.\n\n```go\nfunc WrapHypervisor(hvType Type, hv Hypervisor) Hypervisor\n```\n\n```go\ntype MacOSPlatform struct {\n\tHardwareModelData     []byte\n\tMachineIdentifierData []byte\n\tAuxStoragePath        string\n}\n```\nMacOSPlatform carries the persistent Apple-silicon platform identity. The auxiliary storage belongs to the instance, never to the image template.\n\n```go\ntype NetworkConfig struct {\n\tTAPDevice string\n\tIP        string\n\tMAC       string\n\tNetmask   string\n\t// DownloadBps limits host-\u003eguest bandwidth in bytes/sec (0 = unlimited).\n\t// Hypeman enforces this host-side via TAP shaping for all hypervisors.\n\t// Firecracker also maps it to per-interface API rate limiters.\n\tDownloadBps int64\n\t// UploadBps limits guest-\u003ehost bandwidth in bytes/sec (0 = unlimited).\n\t// Hypeman enforces this host-side via TAP shaping for all hypervisors.\n\t// Firecracker also maps it to per-interface API rate limiters.\n\tUploadBps int64\n}\n```\nNetworkConfig represents a network interface attached to the VM\n\n```go\ntype RegisteredRuntime struct {\n\tType         Type\n\tCapabilities Capabilities\n\n\t// LaunchErr is non-nil when the runtime is supported by this build on\n\t// this platform but its launch prerequisites are not currently met (for\n\t// example QEMU registered on Linux without a system QEMU binary\n\t// installed). Ordinary launches of the runtime will fail while it is\n\t// non-nil.\n\tLaunchErr error\n}\n```\nRegisteredRuntime is one capability-registry entry resolved at read time.\n\n```go\nfunc RegisteredRuntimes() []RegisteredRuntime\n```\nRegisteredRuntimes enumerates every registered runtime, sorted by type name so output is deterministic. Because registration is platform-gated, the result is the set of runtimes the linked backends support on the current host; per-entry Available/LaunchErr additionally reflect whether launch prerequisites are met right now.\n\n```go\nfunc (r RegisteredRuntime) Available() bool\n```\nAvailable reports whether ordinary launches of this runtime can succeed on this host: it is registered for the platform and its launch-prerequisite check passed.\n\n```go\ntype RuntimeRegistration struct {\n\t// Capabilities resolves the runtime's effective capability set. It is\n\t// evaluated on every registry read — never cached at registration time —\n\t// so capabilities that depend on configuration applied after package init\n\t// (for example the configured cloud-hypervisor default version) stay\n\t// truthful. Required.\n\tCapabilities func() Capabilities\n\n\t// LaunchCheck verifies host launch prerequisites that platform-gated\n\t// registration cannot express, such as a required system-installed binary\n\t// (QEMU). nil means registration alone implies launchability (backends\n\t// that ship an embedded VMM binary). The registry invokes it on every\n\t// read; a backend may memoize startup readiness when changing host\n\t// prerequisites requires a process restart.\n\tLaunchCheck func() error\n}\n```\nRuntimeRegistration describes how a hypervisor backend reports itself in the capability registry.\n\n```go\ntype SnapshotSupportValidator interface {\n\tValidateSnapshotSupport(context.Context) error\n}\n```\nSnapshotSupportValidator checks configuration-specific support before pausing.\n\n```go\ntype TPMConfig struct {\n\tSocketPath string\n\tStateDir   string\n}\n```\nTPMConfig describes a per-instance software TPM 2.0 endpoint.\n\n```go\ntype Type string\n```\nType identifies the hypervisor implementation\n\n```go\nconst (\n\t// TypeCloudHypervisor is the Cloud Hypervisor VMM\n\tTypeCloudHypervisor Type = \"cloud-hypervisor\"\n\t// TypeFirecracker is the Firecracker VMM\n\tTypeFirecracker Type = \"firecracker\"\n\t// TypeQEMU is QEMU with its architecture-native standard board.\n\tTypeQEMU Type = \"qemu\"\n\t// TypeQEMUMicroVM is QEMU with the minimal x86 microvm board.\n\tTypeQEMUMicroVM Type = \"qemu-microvm\"\n\t// TypeVZ is the Virtualization.framework VMM (macOS only)\n\tTypeVZ Type = \"vz\"\n)\n```\n\n```go\ntype VMConfig struct {\n\t// Compute resources\n\tVCPUs        int\n\tMemoryBytes  int64\n\tHotplugBytes int64\n\tTopology     *CPUTopology\n\tGuestMemory  GuestMemoryConfig\n\n\t// Storage\n\tDisks []DiskConfig\n\n\t// Network\n\tNetworks []NetworkConfig\n\n\t// Console\n\tSerialLogPath string\n\n\t// Vsock\n\tVsockCID    int64\n\tVsockSocket string\n\n\t// PCI device passthrough (GPU, etc.)\n\tPCIDevices     []string\n\tVGPUDevicePath string\n\n\t// Boot configuration. Empty BootMode preserves the existing direct-kernel\n\t// behavior for Linux callers.\n\tBootMode BootMode\n\tMacOS    *MacOSPlatform\n\tFirmware *FirmwareConfig\n\tTPM      *TPMConfig\n\n\tKernelPath string\n\tInitrdPath string\n\tKernelArgs string\n\n\t// EnableRosetta attaches an Apple Rosetta virtio-fs share (vz on Apple\n\t// silicon only) so the guest can execute x86-64 binaries.\n\tEnableRosetta bool\n}\n```\nVMConfig is the hypervisor-agnostic VM configuration. Each hypervisor implementation translates this to its native format.\n\n```go\nfunc (c VMConfig) EffectiveBootMode() BootMode\n```\nEffectiveBootMode preserves direct Linux kernel boot for existing callers.\n\n```go\ntype VMInfo struct {\n\tState            VMState\n\tMemoryActualSize *int64 // Current actual memory size in bytes (if available)\n}\n```\nVMInfo contains current VM state information\n\n```go\ntype VMStarter interface {\n\t// ValidateConfig performs side-effect-free backend validation. Managers call\n\t// it during preflight; starters must also validate final launch/restore state.\n\tValidateConfig(VMConfig) error\n\n\t// SocketName returns the socket filename for this hypervisor.\n\t// Uses short names to stay within Unix socket path length limits (SUN_LEN ~108 bytes).\n\tSocketName() string\n\n\t// GetBinaryPath returns the path to the hypervisor binary, extracting if needed.\n\tGetBinaryPath(p *paths.Paths, version string) (string, error)\n\n\t// GetVersion returns the default or installed hypervisor version.\n\tGetVersion(p *paths.Paths) (string, error)\n\n\t// ResolveVersion validates an optional requested version and returns the\n\t// concrete binary version to persist for a new VM or snapshot target.\n\tResolveVersion(p *paths.Paths, requested string) (string, error)\n\n\t// StartVM launches the hypervisor process and boots the VM.\n\t// Returns the process ID and a Hypervisor client for subsequent operations.\n\tStartVM(ctx context.Context, p *paths.Paths, version string, socketPath string, config VMConfig) (pid int, hv Hypervisor, err error)\n\n\t// RestoreVM starts the hypervisor and restores VM state from a snapshot.\n\t// Each hypervisor implements its own restore flow:\n\t// - Cloud Hypervisor: starts process, calls Restore API\n\t// - QEMU: would start with -incoming or -loadvm flags (not yet implemented)\n\t// Returns the process ID and a Hypervisor client. The VM is in paused state after restore.\n\tRestoreVM(ctx context.Context, p *paths.Paths, version string, socketPath string, snapshotPath string) (pid int, hv Hypervisor, err error)\n\n\t// PrepareFork allows hypervisors to prepare forked instance state.\n\t// For snapshot-based forks, implementations can rewrite snapshot config with\n\t// fork identity (paths, vsock, network). Hypervisors that don't support fork\n\t// should return ErrNotSupported.\n\tPrepareFork(ctx context.Context, req ForkPrepareRequest) (ForkPrepareResult, error)\n}\n```\nVMStarter handles the full VM startup sequence. Each hypervisor implements its own startup flow: - Cloud Hypervisor: starts process, configures via HTTP API, boots via HTTP API - QEMU: converts config to command-line args, starts process (VM runs immediately)\n\n```go\nfunc WrapVMStarter(hvType Type, starter VMStarter) VMStarter\n```\n\n```go\ntype VMState string\n```\nVMState represents the VM execution state\n\n```go\nconst (\n\t// StateCreated means the VM is configured but not running\n\tStateCreated VMState = \"created\"\n\t// StateRunning means the VM is actively executing\n\tStateRunning VMState = \"running\"\n\t// StatePaused means the VM execution is suspended\n\tStatePaused VMState = \"paused\"\n\t// StateShutdown means the VM has stopped but VMM exists\n\tStateShutdown VMState = \"shutdown\"\n)\n```\n\n```go\ntype VsockDialer interface {\n\t// DialVsock connects to the guest on the specified port.\n\t// Returns a net.Conn that can be used for bidirectional communication.\n\tDialVsock(ctx context.Context, port int) (net.Conn, error)\n\n\t// Key returns a unique identifier for this dialer, used for connection pooling.\n\tKey() string\n}\n```\nVsockDialer provides vsock connectivity to a guest VM. Each hypervisor implements its own connection method: - Cloud Hypervisor: Unix socket file + text handshake protocol - QEMU: Kernel AF\\_VSOCK with CID-based addressing\n\n```go\nfunc NewVsockDialer(hvType Type, vsockSocket string, vsockCID int64) (VsockDialer, error)\n```\nNewVsockDialer creates a VsockDialer for the given hypervisor type. Returns an error if the hypervisor type doesn't have a registered factory.\n\n```go\ntype VsockDialerFactory func(vsockSocket string, vsockCID int64) VsockDialer\n```\nVsockDialerFactory creates VsockDialer instances for a hypervisor type.\n\n","path":"github.com/kernel/hypeman/lib/hypervisor","name":"hypervisor","synopsis":"Package hypervisor provides an abstraction layer for virtual machine managers.","isRedistributable":true}
