@@ -452,6 +452,10 @@ type CheckpointOpts struct {
452
452
// EmptyNamespaces creates a namespace for the container but does not save its properties
453
453
// Provide the namespaces you wish to be checkpointed without their settings on restore
454
454
EmptyNamespaces []string
455
+ // LazyPages uses userfaultfd to lazily restore memory pages
456
+ LazyPages bool
457
+ // StatusFile is the file criu writes \0 to once lazy-pages is ready
458
+ StatusFile * os.File
455
459
}
456
460
457
461
type CgroupMode string
@@ -493,6 +497,9 @@ func (o *CheckpointOpts) args() (out []string) {
493
497
for _ , ns := range o .EmptyNamespaces {
494
498
out = append (out , "--empty-ns" , ns )
495
499
}
500
+ if o .LazyPages {
501
+ out = append (out , "--lazy-pages" )
502
+ }
496
503
return out
497
504
}
498
505
@@ -511,13 +518,23 @@ func PreDump(args []string) []string {
511
518
// Checkpoint allows you to checkpoint a container using criu
512
519
func (r * Runc ) Checkpoint (context context.Context , id string , opts * CheckpointOpts , actions ... CheckpointAction ) error {
513
520
args := []string {"checkpoint" }
521
+ extraFiles := []* os.File {}
514
522
if opts != nil {
515
523
args = append (args , opts .args ()... )
524
+ if opts .StatusFile != nil {
525
+ // pass the status file to the child process
526
+ extraFiles = []* os.File {opts .StatusFile }
527
+ // set status-fd to 3 as this will be the file descriptor
528
+ // of the first file passed with cmd.ExtraFiles
529
+ args = append (args , "--status-fd" , "3" )
530
+ }
516
531
}
517
532
for _ , a := range actions {
518
533
args = a (args )
519
534
}
520
- return r .runOrError (r .command (context , append (args , id )... ))
535
+ cmd := r .command (context , append (args , id )... )
536
+ cmd .ExtraFiles = extraFiles
537
+ return r .runOrError (cmd )
521
538
}
522
539
523
540
type RestoreOpts struct {
0 commit comments