@@ -463,6 +463,22 @@ type Param struct {
463463 Value string
464464}
465465
466+ // FileBackedMemoryConfig describes guest memory that is backed by a host file.
467+ // It is a generic primitive used by features such as VM templating, live
468+ // migration and checkpoint/restore. The hypervisor layer only needs to know
469+ // where the backing file lives and whether it should be mapped shared or
470+ // private; it does not need to know which higher-level feature requested it.
471+ type FileBackedMemoryConfig struct {
472+ // Path is the host path of the memory backing file.
473+ Path string
474+
475+ // Shared selects the mapping mode for the backing file: MAP_SHARED when
476+ // true (e.g. a template source whose memory is shared with clones) and
477+ // MAP_PRIVATE/Copy-On-Write when false (e.g. a clone restored from a
478+ // template or a migration target that needs its own private memory).
479+ Shared bool
480+ }
481+
466482// HypervisorConfig is the hypervisor configuration.
467483// nolint: govet
468484type HypervisorConfig struct {
@@ -514,13 +530,12 @@ type HypervisorConfig struct {
514530 // emulated.
515531 HypervisorMachineType string
516532
517- // MemoryPath is the memory file path of VM memory. Used when either BootToBeTemplate or
518- // BootFromTemplate is true.
519- MemoryPath string
520-
521- // DevicesStatePath is the VM device state file path. Used when either BootToBeTemplate or
522- // BootFromTemplate is true.
523- DevicesStatePath string
533+ // FileBackedMemory describes file-backed guest memory. When non-nil the
534+ // guest memory is backed by the file at Path and mapped either MAP_SHARED
535+ // (Shared=true, e.g. a template source) or MAP_PRIVATE/Copy-On-Write
536+ // (Shared=false, e.g. a clone restored from a template or a migration
537+ // target). When nil the guest uses standard anonymous memory.
538+ FileBackedMemory * FileBackedMemoryConfig
524539
525540 // EntropySource is the path to a host source of
526541 // entropy (/dev/random, /dev/urandom or real hardware RNG device)
@@ -561,10 +576,20 @@ type HypervisorConfig struct {
561576 // VMid is "" if the hypervisor is not created by the factory.
562577 VMid string
563578
564- // VMStorePath is the location on disk where VM information will persist
579+ // VMStorePath is the root directory (typically /run/vc/vm, supplied by the
580+ // persist driver's RunVMStoragePath()) under which each VM's VMM runtime
581+ // artifacts live at <VMStorePath>/<id>: the hypervisor's control sockets
582+ // (e.g. Cloud Hypervisor's API and hybrid-vsock sockets, QEMU's QMP and
583+ // console sockets), QEMU's pid file, and the config.json/state.json files
584+ // copied in when restoring a VM from a snapshot.
565585 VMStorePath string
566586
567- // VMStorePath is the location on disk where runtime information will persist
587+ // RunStorePath is the root directory (typically /run/vc/sbs, supplied by
588+ // the persist driver's RunStoragePath()) under which each sandbox's
589+ // persisted state lives at <RunStorePath>/<id>: the sandbox and container
590+ // state written by the persist driver. (A guest memory dump reads this
591+ // state and copies it into the dump, but the dump itself — vmcore and
592+ // hypervisor metadata — is written under GuestMemoryDumpPath, not here.)
568593 RunStorePath string
569594
570595 // SELinux label for the VM
@@ -831,12 +856,6 @@ type HypervisorConfig struct {
831856 // Enable SEV-SNP guests on AMD machines capable of both
832857 SevSnpGuest bool
833858
834- // BootToBeTemplate used to indicate if the VM is created to be a template VM
835- BootToBeTemplate bool
836-
837- // BootFromTemplate used to indicate if the VM should be created from a template VM
838- BootFromTemplate bool
839-
840859 // DisableVhostNet is used to indicate if host supports vhost_net
841860 DisableVhostNet bool
842861
@@ -894,24 +913,6 @@ type VcpuThreadIDs struct {
894913 vcpus map [int ]int
895914}
896915
897- func (conf * HypervisorConfig ) CheckTemplateConfig () error {
898- if conf .BootToBeTemplate && conf .BootFromTemplate {
899- return fmt .Errorf ("Cannot set both 'to be' and 'from' vm tempate" )
900- }
901-
902- if conf .BootToBeTemplate || conf .BootFromTemplate {
903- if conf .MemoryPath == "" {
904- return fmt .Errorf ("Missing MemoryPath for vm template" )
905- }
906-
907- if conf .BootFromTemplate && conf .DevicesStatePath == "" {
908- return fmt .Errorf ("Missing DevicesStatePath to Load from vm template" )
909- }
910- }
911-
912- return nil
913- }
914-
915916// AddKernelParam allows the addition of new kernel parameters to an existing
916917// hypervisor configuration.
917918func (conf * HypervisorConfig ) AddKernelParam (p Param ) error {
@@ -1311,7 +1312,16 @@ type Hypervisor interface {
13111312 // just perform cleanup.
13121313 StopVM (ctx context.Context , waitOnly bool ) error
13131314 PauseVM (ctx context.Context ) error
1314- SaveVM () error
1315+ // SaveVM snapshots the running VM into snapshotDir. It is a pure
1316+ // hypervisor operation: the caller chooses the destination and is
1317+ // responsible for any feature-specific post-processing (e.g. template
1318+ // memory-sharing adjustments).
1319+ SaveVM (snapshotDir string ) error
1320+ // RestoreVM brings up a VM by restoring it from a snapshot previously
1321+ // written to snapshotDir. The restored VM is left in a paused state; the
1322+ // caller decides when to ResumeVM and what post-restore housekeeping to
1323+ // perform (e.g. reseeding the RNG, syncing the guest clock).
1324+ RestoreVM (ctx context.Context , snapshotDir string ) error
13151325 ResumeVM (ctx context.Context ) error
13161326 AddDevice (ctx context.Context , devInfo interface {}, devType DeviceType ) error
13171327 HotplugAddDevice (ctx context.Context , devInfo interface {}, devType DeviceType ) (interface {}, error )
0 commit comments