Skip to content

Commit

Permalink
Merge pull request #3029 from liusdu/work
Browse files Browse the repository at this point in the history
checkpoint: set default work-dir to image-path
  • Loading branch information
Mrunal Patel committed Jun 25, 2021
2 parents 51beb5c + 85aabe2 commit 245fe2b
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,20 +971,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, 0o700); 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 @@ -993,7 +979,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 @@ -1011,6 +996,19 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
LazyPages: proto.Bool(criuOpts.LazyPages),
}

// if criuOpts.WorkDirectory is not set, criu default is used.
if criuOpts.WorkDirectory != "" {
if err := os.Mkdir(criuOpts.WorkDirectory, 0o700); 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 @@ -1310,19 +1308,6 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
if err := c.checkCriuVersion(30000); err != nil {
return err
}
if criuOpts.WorkDirectory == "" {
criuOpts.WorkDirectory = filepath.Join(c.root, "criu.work")
}
// Since a container can be C/R'ed multiple times,
// the work directory may already exist.
if err := os.Mkdir(criuOpts.WorkDirectory, 0o700); err != nil && !os.IsExist(err) {
return err
}
workDir, err := os.Open(criuOpts.WorkDirectory)
if err != nil {
return err
}
defer workDir.Close()
if criuOpts.ImagesDirectory == "" {
return errors.New("invalid directory to restore checkpoint")
}
Expand Down Expand Up @@ -1355,7 +1340,6 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
Type: &t,
Opts: &criurpc.CriuOpts{
ImagesDirFd: proto.Int32(int32(imageDir.Fd())),
WorkDirFd: proto.Int32(int32(workDir.Fd())),
EvasiveDevices: proto.Bool(true),
LogLevel: proto.Int32(4),
LogFile: proto.String("restore.log"),
Expand Down Expand Up @@ -1383,6 +1367,19 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
req.Opts.LsmProfile = proto.String(criuOpts.LsmProfile)
}

if criuOpts.WorkDirectory != "" {
// Since a container can be C/R'ed multiple times,
// the work directory may already exist.
if err := os.Mkdir(criuOpts.WorkDirectory, 0o700); err != nil && !os.IsExist(err) {
return err
}
workDir, err := os.Open(criuOpts.WorkDirectory)
if err != nil {
return err
}
defer workDir.Close()
req.Opts.WorkDirFd = proto.Int32(int32(workDir.Fd()))
}
c.handleCriuConfigurationFile(req.Opts)

if err := c.handleRestoringNamespaces(req.Opts, &extraFiles); err != nil {
Expand Down

0 comments on commit 245fe2b

Please sign in to comment.