Skip to content

Commit

Permalink
checkpoint: let criu set work-dir defaultly
Browse files Browse the repository at this point in the history
Dump/restrore logs are very useful when process fails.
New runc puts these files in c.root, which will be deleted
when container exits. So if checkpinting/restoring failed,
we can not get these logs and analyze why.

Signed-off-by: Liu Hua <weldonliu@tencent.com>
  • Loading branch information
Liu Hua committed Jun 15, 2021
1 parent 4e50d1c commit de742d4
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,20 +974,6 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
return err
}

if criuOpts.WorkDirectory == "" {
criuOpts.WorkDirectory = filepath.Join(c.root, "criu.work")
}

if err := os.Mkdir(criuOpts.WorkDirectory, 0700); err != nil && !os.IsExist(err) {
return err
}

workDir, err := os.Open(criuOpts.WorkDirectory)
if err != nil {
return err
}
defer workDir.Close()

imageDir, err := os.Open(criuOpts.ImagesDirectory)
if err != nil {
return err
Expand All @@ -996,7 +982,6 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {

rpcOpts := criurpc.CriuOpts{
ImagesDirFd: proto.Int32(int32(imageDir.Fd())),
WorkDirFd: proto.Int32(int32(workDir.Fd())),
LogLevel: proto.Int32(4),
LogFile: proto.String("dump.log"),
Root: proto.String(c.config.Rootfs),
Expand All @@ -1014,6 +999,19 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
LazyPages: proto.Bool(criuOpts.LazyPages),
}

// if criuOpts.WorkDirectory is not set. let criu set it.
if criuOpts.WorkDirectory != "" {
if err := os.Mkdir(criuOpts.WorkDirectory, 0700); err != nil && !os.IsExist(err) {
return err
}
workDir, err := os.Open(criuOpts.WorkDirectory)
if err != nil {
return err
}
defer workDir.Close()
rpcOpts.WorkDirFd = proto.Int32(int32(workDir.Fd()))
}

c.handleCriuConfigurationFile(&rpcOpts)

// If the container is running in a network namespace and has
Expand Down Expand Up @@ -1307,7 +1305,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
return err
}
if criuOpts.WorkDirectory == "" {
criuOpts.WorkDirectory = filepath.Join(c.root, "criu.work")
criuOpts.WorkDirectory = criuOpts.ImagesDirectory
}
// Since a container can be C/R'ed multiple times,
// the work directory may already exist.
Expand Down

0 comments on commit de742d4

Please sign in to comment.