Skip to content

Commit

Permalink
Merge pull request #62 from ctrox/lazy-checkpoint
Browse files Browse the repository at this point in the history
Add lazy-pages and status-fd options
  • Loading branch information
estesp committed Jul 7, 2020
2 parents 0d18714 + 498d70b commit 23d84c5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion runc.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ type CheckpointOpts struct {
// EmptyNamespaces creates a namespace for the container but does not save its properties
// Provide the namespaces you wish to be checkpointed without their settings on restore
EmptyNamespaces []string
// LazyPages uses userfaultfd to lazily restore memory pages
LazyPages bool
// StatusFile is the file criu writes \0 to once lazy-pages is ready
StatusFile *os.File
}

type CgroupMode string
Expand Down Expand Up @@ -493,6 +497,9 @@ func (o *CheckpointOpts) args() (out []string) {
for _, ns := range o.EmptyNamespaces {
out = append(out, "--empty-ns", ns)
}
if o.LazyPages {
out = append(out, "--lazy-pages")
}
return out
}

Expand All @@ -511,13 +518,23 @@ func PreDump(args []string) []string {
// Checkpoint allows you to checkpoint a container using criu
func (r *Runc) Checkpoint(context context.Context, id string, opts *CheckpointOpts, actions ...CheckpointAction) error {
args := []string{"checkpoint"}
extraFiles := []*os.File{}
if opts != nil {
args = append(args, opts.args()...)
if opts.StatusFile != nil {
// pass the status file to the child process
extraFiles = []*os.File{opts.StatusFile}
// set status-fd to 3 as this will be the file descriptor
// of the first file passed with cmd.ExtraFiles
args = append(args, "--status-fd", "3")
}
}
for _, a := range actions {
args = a(args)
}
return r.runOrError(r.command(context, append(args, id)...))
cmd := r.command(context, append(args, id)...)
cmd.ExtraFiles = extraFiles
return r.runOrError(cmd)
}

type RestoreOpts struct {
Expand Down

0 comments on commit 23d84c5

Please sign in to comment.