Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add container_snapshot_path to load snapshot request #508

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
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
5 changes: 4 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ var loadSnapshotHandlerList = HandlerList{}.Append(
CreateLogFilesHandler,
BootstrapLoggingHandler,
LoadSnapshotHandler,
AddVsocksHandler,
// According to the firecracker OpenAPI specification, creating vsock devices is only a pre-boot request, so adding
// vsocks after loading a snapshot fails. It also seems redundant, since the VM loaded from a snapshot restores
// vsocks anyways (firecracker-microvm/firecracker-go-sdk#506).
// AddVsocksHandler,
)

var defaultValidationHandlerList = HandlerList{}.Append(
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