Skip to content

Commit 3a80903

Browse files
committed
Add support for memory backend
- Pull in upstream swagger definitions for SnapshotLoadParams and MemoryBackend - Run `go generate` - Update Snapshot config to allow setting MemBackend - Forward the MemBackend through to the Firecracker client Signed-off-by: Brandon Duffany <[email protected]>
1 parent aa97886 commit 3a80903

File tree

6 files changed

+206
-13
lines changed

6 files changed

+206
-13
lines changed

client/models/memory_backend.go

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

client/models/snapshot_load_params.go

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

client/swagger.yaml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,25 @@ definitions:
953953
maximum: 32
954954
description: Number of vCPUs (either 1 or an even number)
955955

956+
MemoryBackend:
957+
type: object
958+
required:
959+
- backend_type
960+
- backend_path
961+
properties:
962+
backend_type:
963+
type: string
964+
enum:
965+
- File
966+
- Uffd
967+
backend_path:
968+
type: string
969+
description: Based on 'backend_type' it is either
970+
1) Path to the file that contains the guest memory to be loaded
971+
2) Path to the UDS where a process is listening for a UFFD initialization
972+
control payload and open file descriptor that it can use to serve this
973+
process's guest memory page faults
974+
956975
Metrics:
957976
type: object
958977
description:
@@ -1090,8 +1109,10 @@ definitions:
10901109

10911110
SnapshotLoadParams:
10921111
type: object
1112+
description:
1113+
Defines the configuration used for handling snapshot resume. Exactly one of
1114+
the two `mem_*` fields must be present in the body of the request.
10931115
required:
1094-
- mem_file_path
10951116
- snapshot_path
10961117
properties:
10971118
enable_diff_snapshots:
@@ -1100,7 +1121,16 @@ definitions:
11001121
Enable support for incremental (diff) snapshots by tracking dirty guest pages.
11011122
mem_file_path:
11021123
type: string
1103-
description: Path to the file that contains the guest memory to be loaded.
1124+
description:
1125+
Path to the file that contains the guest memory to be loaded.
1126+
This parameter has been deprecated and is only allowed if
1127+
`mem_backend` is not present.
1128+
mem_backend:
1129+
$ref: "#/definitions/MemoryBackend"
1130+
description:
1131+
Configuration for the backend that handles memory load. If this field
1132+
is specified, `mem_file_path` is forbidden. Either `mem_backend` or
1133+
`mem_file_path` must be present at a time.
11041134
snapshot_path:
11051135
type: string
11061136
description: Path to the file that contains the microVM state to be loaded.

machine.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ func (m *Machine) startVMM(ctx context.Context) error {
649649
return nil
650650
}
651651

652-
//StopVMM stops the current VMM.
652+
// StopVMM stops the current VMM.
653653
func (m *Machine) StopVMM() error {
654654
return m.stopVMM()
655655
}
@@ -1171,7 +1171,8 @@ func (m *Machine) CreateSnapshot(ctx context.Context, memFilePath, snapshotPath
11711171
// loadSnapshot loads a snapshot of the VM
11721172
func (m *Machine) loadSnapshot(ctx context.Context, snapshot *SnapshotConfig) error {
11731173
snapshotParams := &models.SnapshotLoadParams{
1174-
MemFilePath: &snapshot.MemFilePath,
1174+
MemFilePath: snapshot.MemFilePath,
1175+
MemBackend: snapshot.MemBackend,
11751176
SnapshotPath: &snapshot.SnapshotPath,
11761177
EnableDiffSnapshots: snapshot.EnableDiffSnapshots,
11771178
ResumeVM: snapshot.ResumeVM,

opts.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package firecracker
1616
import (
1717
"os/exec"
1818

19+
"github.com/firecracker-microvm/firecracker-go-sdk/client/models"
1920
"github.com/sirupsen/logrus"
2021
)
2122

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

55-
// WithSnapshot will allow for the machine to start using a given snapshot.
56+
// WithSnapshot will allow for the machine to start using a given snapshot. A
57+
// UFFD socket file path may be used as memFilePath if a MemoryBackendType opt
58+
// is passed setting the backend type to models.MemoryBackendBackendTypeUffd.
5659
func WithSnapshot(memFilePath, snapshotPath string, opts ...WithSnapshotOpt) Opt {
5760
return func(m *Machine) {
5861
m.Cfg.Snapshot.MemFilePath = memFilePath
@@ -66,3 +69,17 @@ func WithSnapshot(memFilePath, snapshotPath string, opts ...WithSnapshotOpt) Opt
6669
m.Handlers.FcInit = loadSnapshotHandlerList
6770
}
6871
}
72+
73+
// MemoryBackendType sets the memory backend type to the given value.
74+
func MemoryBackendType(typ string) WithSnapshotOpt {
75+
return func(cfg *SnapshotConfig) {
76+
if cfg.MemBackend == nil {
77+
cfg.MemBackend = &models.MemoryBackend{
78+
BackendPath: String(cfg.MemFilePath),
79+
}
80+
}
81+
cfg.MemBackend.BackendType = String(typ)
82+
// Clear MemFilePath since only one of MemFilePath or MemBackend is allowed.
83+
cfg.MemFilePath = ""
84+
}
85+
}

snapshot.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313

1414
package firecracker
1515

16+
import "github.com/firecracker-microvm/firecracker-go-sdk/client/models"
17+
1618
type SnapshotConfig struct {
1719
MemFilePath string
20+
MemBackend *models.MemoryBackend
1821
SnapshotPath string
1922
EnableDiffSnapshots bool
2023
ResumeVM bool

0 commit comments

Comments
 (0)