Skip to content

Commit

Permalink
Add container_snapshot_path to load snapshot request
Browse files Browse the repository at this point in the history
Forward the `container_snapshot_path` parameter of the firecracker load
snapshot request.

Signed-off-by: Georgiy Lebedev <[email protected]>
  • Loading branch information
CuriousGeorgiy committed Aug 24, 2023
1 parent 6fe5d92 commit abb9daa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
17 changes: 17 additions & 0 deletions client/models/snapshot_load_params.go

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

5 changes: 5 additions & 0 deletions client/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,7 @@ definitions:
the two `mem_*` fields must be present in the body of the request.
required:
- snapshot_path
- container_snapshot_path
properties:
enable_diff_snapshots:
type: boolean
Expand All @@ -1212,6 +1213,10 @@ definitions:
type: boolean
description:
When set to true, the vm is also resumed if the snapshot load is successful.
container_snapshot_path:
type: string
description:
Path to the disk device backing the container snapshot.

TokenBucket:
type: object
Expand Down
17 changes: 11 additions & 6 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.GetMemBackendPath() != "" || cfg.Snapshot.SnapshotPath != ""
return cfg.Snapshot.GetMemBackendPath() != "" || cfg.Snapshot.SnapshotPath != "" || cfg.Snapshot.ContainerSnapshotPath != ""
}

// Validate will ensure that the required fields are set and that
Expand Down Expand Up @@ -243,6 +243,10 @@ func (cfg *Config) ValidateLoadSnapshot() error {
return err
}

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

return nil
}

Expand Down Expand Up @@ -1171,11 +1175,12 @@ 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,
MemBackend: snapshot.MemBackend,
SnapshotPath: &snapshot.SnapshotPath,
EnableDiffSnapshots: snapshot.EnableDiffSnapshots,
ResumeVM: snapshot.ResumeVM,
MemFilePath: snapshot.MemFilePath,
MemBackend: snapshot.MemBackend,
SnapshotPath: &snapshot.SnapshotPath,
EnableDiffSnapshots: snapshot.EnableDiffSnapshots,
ResumeVM: snapshot.ResumeVM,
ContainerSnapshotPath: &snapshot.ContainerSnapshotPath,
}

if _, err := m.client.LoadSnapshot(ctx, snapshotParams); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ type WithSnapshotOpt func(*SnapshotConfig)
// WithSnapshot(
// "", snapshotPath,
// WithMemoryBackend(models.MemoryBackendBackendTypeUffd, "uffd.sock"))
func WithSnapshot(memFilePath, snapshotPath string, opts ...WithSnapshotOpt) Opt {
func WithSnapshot(memFilePath, snapshotPath, ContainerSnapshotPath string, opts ...WithSnapshotOpt) Opt {
return func(m *Machine) {
m.Cfg.Snapshot.MemFilePath = memFilePath
m.Cfg.Snapshot.SnapshotPath = snapshotPath
m.Cfg.Snapshot.ContainerSnapshotPath = ContainerSnapshotPath

for _, opt := range opts {
opt(&m.Cfg.Snapshot)
Expand Down
11 changes: 6 additions & 5 deletions snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ 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
MemFilePath string
MemBackend *models.MemoryBackend
SnapshotPath string
EnableDiffSnapshots bool
ResumeVM bool
ContainerSnapshotPath string
}

// GetMemBackendPath returns the effective memory backend path. If MemBackend
Expand Down

0 comments on commit abb9daa

Please sign in to comment.