@@ -41,14 +41,12 @@ import (
4141
4242const snapshotsDir = "/fccd/snapshots"
4343
44- // TODO: interface for orchestrator
45-
4644type coordinator struct {
4745 sync.Mutex
4846 orch * ctriface.Orchestrator
4947 nextID uint64
5048 isSparseSnaps bool
51- isDeduplicatedSnaps bool
49+ isFullLocal bool
5250
5351 activeInstances map [string ]* FuncInstance
5452 snapshotManager * snapshotting.SnapshotManager
@@ -64,15 +62,15 @@ func withoutOrchestrator() coordinatorOption {
6462 }
6563}
6664
67- func newFirecrackerCoordinator (orch * ctriface.Orchestrator , snapsCapacityMiB int64 , isSparseSnaps bool , isDeduplicatedSnaps bool , opts ... coordinatorOption ) * coordinator {
65+ func newFirecrackerCoordinator (orch * ctriface.Orchestrator , snapsCapacityMiB int64 , isSparseSnaps bool , isFullLocal bool , opts ... coordinatorOption ) * coordinator {
6866 c := & coordinator {
6967 activeInstances : make (map [string ]* FuncInstance ),
7068 orch : orch ,
7169 isSparseSnaps : isSparseSnaps ,
72- isDeduplicatedSnaps : isDeduplicatedSnaps ,
70+ isFullLocal : isFullLocal ,
7371 }
7472
75- if isDeduplicatedSnaps {
73+ if isFullLocal {
7674 c .snapshotManager = snapshotting .NewSnapshotManager (deduplicated .NewSnapshotManager (snapshotsDir , snapsCapacityMiB ))
7775 } else {
7876 c .snapshotManager = snapshotting .NewSnapshotManager (regular .NewRegularSnapshotManager (snapshotsDir ))
@@ -88,26 +86,25 @@ func newFirecrackerCoordinator(orch *ctriface.Orchestrator, snapsCapacityMiB int
8886func (c * coordinator ) startVM (ctx context.Context , image string , revision string , memSizeMib , vCPUCount uint32 ) (* FuncInstance , error ) {
8987 if c .orch != nil && c .orch .GetSnapshotsEnabled () {
9088 id := image
91- if c .isDeduplicatedSnaps {
89+ if c .isFullLocal {
9290 id = revision
9391 }
9492
9593 // Check if snapshot is available
9694 if snap , err := c .snapshotManager .AcquireSnapshot (id ); err == nil {
9795 if snap .MemSizeMib != memSizeMib || snap .VCPUCount != vCPUCount {
98- return nil , errors .New ("Please create a new revision when updating uVM memory size or vCPU count" )
96+ return nil , errors .New ("uVM memory size or vCPU count in the snapshot do not match the requested ones." )
97+ }
98+
99+ vmID := ""
100+ if c .isFullLocal {
101+ vmID = strconv .Itoa (int (atomic .AddUint64 (& c .nextID , 1 )))
99102 } else {
100- vmID := ""
101- if c .isDeduplicatedSnaps {
102- vmID = strconv .Itoa (int (atomic .AddUint64 (& c .nextID , 1 )))
103- } else {
104- vmID = snap .GetId ()
105- }
106-
107- return c .orchStartVMSnapshot (ctx , snap , memSizeMib , vCPUCount , vmID )
103+ vmID = snap .GetId ()
108104 }
109- } else {
110- return c .orchStartVM (ctx , image , revision , memSizeMib , vCPUCount )
105+
106+ return c .orchStartVMSnapshot (ctx , snap , memSizeMib , vCPUCount , vmID )
107+
111108 }
112109 }
113110
@@ -134,7 +131,7 @@ func (c *coordinator) stopVM(ctx context.Context, containerID string) error {
134131 }
135132
136133 id := fi .vmID
137- if c .isDeduplicatedSnaps {
134+ if c .isFullLocal {
138135 id = fi .revisionId
139136 }
140137
@@ -148,7 +145,7 @@ func (c *coordinator) stopVM(ctx context.Context, containerID string) error {
148145 }
149146 }
150147
151- if c .isDeduplicatedSnaps {
148+ if c .isFullLocal {
152149 return c .orchStopVM (ctx , fi )
153150 } else {
154151 return c .orchOffloadVM (ctx , fi )
@@ -201,7 +198,7 @@ func (c *coordinator) orchStartVM(ctx context.Context, image, revision string, m
201198
202199 if ! c .withoutOrchestrator {
203200 trackDirtyPages := c .isSparseSnaps
204- resp , _ , err = c .orch .StartVM (ctxTimeout , vmID , image , memSizeMib , vCPUCount , trackDirtyPages )
201+ resp , _ , err = c .orch .StartVM (ctxTimeout , vmID , image , memSizeMib , vCPUCount , trackDirtyPages , c . isFullLocal )
205202 if err != nil {
206203 logger .WithError (err ).Error ("coordinator failed to start VM" )
207204 }
@@ -233,7 +230,7 @@ func (c *coordinator) orchStartVMSnapshot(ctx context.Context, snap *snapshottin
233230 ctxTimeout , cancel := context .WithTimeout (ctx , time .Second * 30 )
234231 defer cancel ()
235232
236- resp , _ , err = c .orch .LoadSnapshot (ctxTimeout , vmID , snap )
233+ resp , _ , err = c .orch .LoadSnapshot (ctxTimeout , vmID , snap , c . isFullLocal )
237234 if err != nil {
238235 logger .WithError (err ).Error ("failed to load VM" )
239236 return nil , err
@@ -260,20 +257,18 @@ func (c *coordinator) orchCreateSnapshot(ctx context.Context, fi *FuncInstance)
260257 )
261258
262259 id := fi .vmID
263- if c .isDeduplicatedSnaps {
260+ if c .isFullLocal {
264261 id = fi .revisionId
265262 }
266263
267264 removeContainerSnaps , snap , err := c .snapshotManager .InitSnapshot (id , fi .image , fi .coldStartTimeMs , fi .memSizeMib , fi .vCPUCount , c .isSparseSnaps )
268265
269266 if err != nil {
270- if fmt .Sprint (err ) == "There is not enough free space available" {
271- fi .logger .Info (fmt .Sprintf ("There is not enough space available for snapshots of %s" , fi .revisionId ))
272- }
267+ fi .logger .Warn (fmt .Sprint (err ))
273268 return nil
274269 }
275270
276- if c .isDeduplicatedSnaps && removeContainerSnaps != nil {
271+ if c .isFullLocal && removeContainerSnaps != nil {
277272 for _ , cleanupSnapId := range * removeContainerSnaps {
278273 if err := c .orch .CleanupSnapshot (ctx , cleanupSnapId ); err != nil {
279274 return errors .Wrap (err , "removing devmapper revision snapshot" )
@@ -292,7 +287,7 @@ func (c *coordinator) orchCreateSnapshot(ctx context.Context, fi *FuncInstance)
292287 return nil
293288 }
294289
295- err = c .orch .CreateSnapshot (ctxTimeout , fi .vmID , snap )
290+ err = c .orch .CreateSnapshot (ctxTimeout , fi .vmID , snap , c . isFullLocal )
296291 if err != nil {
297292 fi .logger .WithError (err ).Error ("failed to create snapshot" )
298293 return nil
@@ -306,26 +301,26 @@ func (c *coordinator) orchCreateSnapshot(ctx context.Context, fi *FuncInstance)
306301 return nil
307302}
308303
309- func (c * coordinator ) orchStopVM (ctx context.Context , fi * FuncInstance ) error {
304+ func (c * coordinator ) orchOffloadVM (ctx context.Context , fi * FuncInstance ) error {
310305 if c .withoutOrchestrator {
311306 return nil
312307 }
313308
314- if err := c .orch .StopSingleVM (ctx , fi .vmID ); err != nil {
315- fi .logger .WithError (err ).Error ("failed to stop VM for instance " )
309+ if err := c .orch .OffloadVM (ctx , fi .vmID , c . isFullLocal ); err != nil {
310+ fi .logger .WithError (err ).Error ("failed to offload VM" )
316311 return err
317312 }
318313
319314 return nil
320315}
321316
322- func (c * coordinator ) orchOffloadVM (ctx context.Context , fi * FuncInstance ) error {
317+ func (c * coordinator ) orchStopVM (ctx context.Context , fi * FuncInstance ) error {
323318 if c .withoutOrchestrator {
324319 return nil
325320 }
326321
327- if err := c .orch .OffloadVM (ctx , fi .vmID ); err != nil {
328- fi .logger .WithError (err ).Error ("failed to offload VM" )
322+ if err := c .orch .StopSingleVM (ctx , fi .vmID , c . isFullLocal ); err != nil {
323+ fi .logger .WithError (err ).Error ("failed to stop VM for instance " )
329324 return err
330325 }
331326
0 commit comments