Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions client/models/memory_backend.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 19 additions & 8 deletions client/models/snapshot_load_params.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 32 additions & 2 deletions client/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,25 @@ definitions:
maximum: 32
description: Number of vCPUs (either 1 or an even number)

MemoryBackend:
type: object
required:
- backend_type
- backend_path
properties:
backend_type:
type: string
enum:
- File
- Uffd
backend_path:
type: string
description: Based on 'backend_type' it is either
1) Path to the file that contains the guest memory to be loaded
2) Path to the UDS where a process is listening for a UFFD initialization
control payload and open file descriptor that it can use to serve this
process's guest memory page faults

Metrics:
type: object
description:
Expand Down Expand Up @@ -1090,8 +1109,10 @@ definitions:

SnapshotLoadParams:
type: object
description:
Defines the configuration used for handling snapshot resume. Exactly one of
the two `mem_*` fields must be present in the body of the request.
required:
- mem_file_path
- snapshot_path
properties:
enable_diff_snapshots:
Expand All @@ -1100,7 +1121,16 @@ definitions:
Enable support for incremental (diff) snapshots by tracking dirty guest pages.
mem_file_path:
type: string
description: Path to the file that contains the guest memory to be loaded.
description:
Path to the file that contains the guest memory to be loaded.
This parameter has been deprecated and is only allowed if
`mem_backend` is not present.
mem_backend:
$ref: "#/definitions/MemoryBackend"
description:
Configuration for the backend that handles memory load. If this field
is specified, `mem_file_path` is forbidden. Either `mem_backend` or
`mem_file_path` must be present at a time.
snapshot_path:
type: string
description: Path to the file that contains the microVM state to be loaded.
Expand Down
9 changes: 5 additions & 4 deletions machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ type Config struct {
}

func (cfg *Config) hasSnapshot() bool {
return cfg.Snapshot.MemFilePath != "" || cfg.Snapshot.SnapshotPath != ""
return cfg.Snapshot.GetMemFilePath() != "" || cfg.Snapshot.SnapshotPath != ""
}

// Validate will ensure that the required fields are set and that
Expand Down Expand Up @@ -235,7 +235,7 @@ func (cfg *Config) ValidateLoadSnapshot() error {
return fmt.Errorf("socket %s already exists", cfg.SocketPath)
}

if _, err := os.Stat(cfg.Snapshot.MemFilePath); err != nil {
if _, err := os.Stat(cfg.Snapshot.GetMemFilePath()); err != nil {
return err
}

Expand Down Expand Up @@ -649,7 +649,7 @@ func (m *Machine) startVMM(ctx context.Context) error {
return nil
}

//StopVMM stops the current VMM.
// StopVMM stops the current VMM.
func (m *Machine) StopVMM() error {
return m.stopVMM()
}
Expand Down Expand Up @@ -1171,7 +1171,8 @@ func (m *Machine) CreateSnapshot(ctx context.Context, memFilePath, snapshotPath
// loadSnapshot loads a snapshot of the VM
func (m *Machine) loadSnapshot(ctx context.Context, snapshot *SnapshotConfig) error {
snapshotParams := &models.SnapshotLoadParams{
MemFilePath: &snapshot.MemFilePath,
MemFilePath: snapshot.MemFilePath,
MemBackend: snapshot.MemBackend,
SnapshotPath: &snapshot.SnapshotPath,
EnableDiffSnapshots: snapshot.EnableDiffSnapshots,
ResumeVM: snapshot.ResumeVM,
Expand Down
19 changes: 18 additions & 1 deletion opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package firecracker
import (
"os/exec"

"github.com/firecracker-microvm/firecracker-go-sdk/client/models"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -52,7 +53,9 @@ func WithProcessRunner(cmd *exec.Cmd) Opt {
// to be passed to LoadSnapshot
type WithSnapshotOpt func(*SnapshotConfig)

// WithSnapshot will allow for the machine to start using a given snapshot.
// WithSnapshot will allow for the machine to start using a given snapshot. A
// UFFD socket file path may be used as memFilePath if a MemoryBackendType opt
// is passed setting the backend type to models.MemoryBackendBackendTypeUffd.
func WithSnapshot(memFilePath, snapshotPath string, opts ...WithSnapshotOpt) Opt {
return func(m *Machine) {
m.Cfg.Snapshot.MemFilePath = memFilePath
Expand All @@ -66,3 +69,17 @@ func WithSnapshot(memFilePath, snapshotPath string, opts ...WithSnapshotOpt) Opt
m.Handlers.FcInit = loadSnapshotHandlerList
}
}

// MemoryBackendType sets the memory backend type to the given value.
func MemoryBackendType(typ string) WithSnapshotOpt {
return func(cfg *SnapshotConfig) {
if cfg.MemBackend == nil {
cfg.MemBackend = &models.MemoryBackend{
BackendPath: String(cfg.MemFilePath),
}
}
cfg.MemBackend.BackendType = String(typ)
// Clear MemFilePath since only one of MemFilePath or MemBackend is allowed.
cfg.MemFilePath = ""
}
}
10 changes: 10 additions & 0 deletions snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@

package firecracker

import "github.com/firecracker-microvm/firecracker-go-sdk/client/models"

type SnapshotConfig struct {
MemFilePath string
MemBackend *models.MemoryBackend
SnapshotPath string
EnableDiffSnapshots bool
ResumeVM bool
}

func (cfg *SnapshotConfig) GetMemFilePath() string {
if cfg.MemBackend != nil && cfg.MemBackend.BackendPath != nil {
return *cfg.MemBackend.BackendPath
}
return cfg.MemFilePath
}