Skip to content

Commit 1afa908

Browse files
Add container_snapshot_path to load snapshot request
Forward the `container_snapshot_path` parameter of the firecracker load snapshot request. Signed-off-by: Georgiy Lebedev <[email protected]>
1 parent 57869b1 commit 1afa908

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

client/models/snapshot_load_params.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/swagger.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ definitions:
11881188
the two `mem_*` fields must be present in the body of the request.
11891189
required:
11901190
- snapshot_path
1191+
- container_snapshot_path
11911192
properties:
11921193
enable_diff_snapshots:
11931194
type: boolean
@@ -1212,6 +1213,10 @@ definitions:
12121213
type: boolean
12131214
description:
12141215
When set to true, the vm is also resumed if the snapshot load is successful.
1216+
container_snapshot_path:
1217+
type: string
1218+
description:
1219+
Path to the disk device backing the container snapshot.
12151220

12161221
TokenBucket:
12171222
type: object

machine.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ type Config struct {
172172
}
173173

174174
func (cfg *Config) hasSnapshot() bool {
175-
return cfg.Snapshot.GetMemBackendPath() != "" || cfg.Snapshot.SnapshotPath != ""
175+
return cfg.Snapshot.GetMemBackendPath() != "" || cfg.Snapshot.SnapshotPath != "" || cfg.Snapshot.ContainerSnapshotPath != ""
176176
}
177177

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

246+
if _, err := os.Stat(cfg.Snapshot.ContainerSnapshotPath); err != nil {
247+
return err
248+
}
249+
246250
return nil
247251
}
248252

@@ -1171,11 +1175,12 @@ func (m *Machine) CreateSnapshot(ctx context.Context, memFilePath, snapshotPath
11711175
// loadSnapshot loads a snapshot of the VM
11721176
func (m *Machine) loadSnapshot(ctx context.Context, snapshot *SnapshotConfig) error {
11731177
snapshotParams := &models.SnapshotLoadParams{
1174-
MemFilePath: snapshot.MemFilePath,
1175-
MemBackend: snapshot.MemBackend,
1176-
SnapshotPath: &snapshot.SnapshotPath,
1177-
EnableDiffSnapshots: snapshot.EnableDiffSnapshots,
1178-
ResumeVM: snapshot.ResumeVM,
1178+
MemFilePath: snapshot.MemFilePath,
1179+
MemBackend: snapshot.MemBackend,
1180+
SnapshotPath: &snapshot.SnapshotPath,
1181+
EnableDiffSnapshots: snapshot.EnableDiffSnapshots,
1182+
ResumeVM: snapshot.ResumeVM,
1183+
ContainerSnapshotPath: &snapshot.ContainerSnapshotPath,
11791184
}
11801185

11811186
if _, err := m.client.LoadSnapshot(ctx, snapshotParams); err != nil {

opts.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ type WithSnapshotOpt func(*SnapshotConfig)
6262
// WithSnapshot(
6363
// "", snapshotPath,
6464
// WithMemoryBackend(models.MemoryBackendBackendTypeUffd, "uffd.sock"))
65-
func WithSnapshot(memFilePath, snapshotPath string, opts ...WithSnapshotOpt) Opt {
65+
func WithSnapshot(memFilePath, snapshotPath, ContainerSnapshotPath string, opts ...WithSnapshotOpt) Opt {
6666
return func(m *Machine) {
6767
m.Cfg.Snapshot.MemFilePath = memFilePath
6868
m.Cfg.Snapshot.SnapshotPath = snapshotPath
69+
m.Cfg.Snapshot.ContainerSnapshotPath = ContainerSnapshotPath
6970

7071
for _, opt := range opts {
7172
opt(&m.Cfg.Snapshot)

snapshot.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ package firecracker
1616
import "github.com/firecracker-microvm/firecracker-go-sdk/client/models"
1717

1818
type SnapshotConfig struct {
19-
MemFilePath string
20-
MemBackend *models.MemoryBackend
21-
SnapshotPath string
22-
EnableDiffSnapshots bool
23-
ResumeVM bool
19+
MemFilePath string
20+
MemBackend *models.MemoryBackend
21+
SnapshotPath string
22+
EnableDiffSnapshots bool
23+
ResumeVM bool
24+
ContainerSnapshotPath string
2425
}
2526

2627
// GetMemBackendPath returns the effective memory backend path. If MemBackend

0 commit comments

Comments
 (0)