Skip to content

Commit 6279f94

Browse files
plamenmpetrovamohoste
authored andcommitted
Added support for creating and loading snapshots of VM.
Notes: 1. Uses logging-only branch from ustiugov/firecracker-go-sdk 2. Firecracker logs path is hard-coded. Signed-off-by: Plamen Petrov <[email protected]>
1 parent 1b9dd80 commit 6279f94

File tree

6 files changed

+587
-1
lines changed

6 files changed

+587
-1
lines changed

firecracker-control/local.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,60 @@ func (s *local) ResumeVM(ctx context.Context, req *proto.ResumeVMRequest) (*empt
632632

633633
return resp, nil
634634
}
635+
636+
// CreateSnapshot Creates a snapshot of a VM
637+
func (s *local) CreateSnapshot(ctx context.Context, req *proto.CreateSnapshotRequest) (*empty.Empty, error) {
638+
client, err := s.shimFirecrackerClient(ctx, req.VMID)
639+
if err != nil {
640+
return nil, err
641+
}
642+
643+
defer client.Close()
644+
645+
resp, err := client.CreateSnapshot(ctx, req)
646+
if err != nil {
647+
s.logger.WithError(err).Error()
648+
return nil, err
649+
}
650+
651+
return resp, nil
652+
}
653+
654+
// LoadSnapshot Loads a snapshot of a VM
655+
func (s *local) LoadSnapshot(ctx context.Context, req *proto.LoadSnapshotRequest) (*empty.Empty, error) {
656+
client, err := s.shimFirecrackerClient(ctx, req.VMID)
657+
if err != nil {
658+
return nil, err
659+
}
660+
661+
defer client.Close()
662+
663+
resp, err := client.LoadSnapshot(ctx, req)
664+
if err != nil {
665+
s.logger.WithError(err).Error()
666+
return nil, err
667+
}
668+
669+
return resp, nil
670+
}
671+
672+
// Offload Shuts down a VM started through the firecracker go sdk and deletes
673+
// the corresponding firecracker socket. All of the other resources (shim, other sockets)
674+
// will persist.
675+
func (s *local) Offload(ctx context.Context, req *proto.OffloadRequest) (*empty.Empty, error) {
676+
client, err := s.shimFirecrackerClient(ctx, req.VMID)
677+
if err != nil {
678+
return nil, err
679+
}
680+
681+
defer client.Close()
682+
683+
resp, err := client.Offload(ctx, req)
684+
if err != nil {
685+
s.logger.WithError(err).Error()
686+
return nil, err
687+
}
688+
689+
return resp, nil
690+
}
691+

firecracker-control/service.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,18 @@ func (s *service) UpdateBalloonStats(ctx context.Context, req *proto.UpdateBallo
126126
log.G(ctx).Debug("Updating balloon device statistics polling interval")
127127
return s.local.UpdateBalloonStats(ctx, req)
128128
}
129+
130+
func (s *service) LoadSnapshot(ctx context.Context, req *proto.LoadSnapshotRequest) (*empty.Empty, error) {
131+
log.G(ctx).Debugf("load snapshot request: %+v", req)
132+
return s.local.LoadSnapshot(ctx, req)
133+
}
134+
135+
func (s *service) CreateSnapshot(ctx context.Context, req *proto.CreateSnapshotRequest) (*empty.Empty, error) {
136+
log.G(ctx).Debugf("create snapshot request: %+v", req)
137+
return s.local.CreateSnapshot(ctx, req)
138+
}
139+
140+
func (s *service) Offload(ctx context.Context, req *proto.OffloadRequest) (*empty.Empty, error) {
141+
log.G(ctx).Debugf("offload request: %+v", req)
142+
return s.local.Offload(ctx, req)
143+
}

proto/firecracker.pb.go

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

proto/firecracker.proto

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ enum DriveExposePolicy {
103103
BIND = 1;
104104
}
105105

106+
message CreateSnapshotRequest {
107+
string VMID = 1;
108+
string SnapshotFilePath = 2;
109+
string MemFilePath = 3;
110+
}
111+
112+
message LoadSnapshotRequest {
113+
string VMID = 1;
114+
string SnapshotFilePath = 2;
115+
string MemFilePath = 3;
116+
}
117+
118+
message OffloadRequest {
119+
string VMID = 1;
120+
}
121+
122+
106123
message JailerConfig {
107124
string NetNS = 1;
108125
// List of the physical numbers of the CPUs on which processes in that

0 commit comments

Comments
 (0)