Skip to content

Commit

Permalink
Merge pull request #1110 from avagin/cpt-in-userns
Browse files Browse the repository at this point in the history
checkpoint: handle config.Devices and config.MaskPaths
  • Loading branch information
hqhq authored Jan 10, 2017
2 parents 11f6c37 + 040fb73 commit db99936
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,29 @@ func (c *linuxContainer) addCriuDumpMount(req *criurpc.CriuReq, m *configs.Mount
req.Opts.ExtMnt = append(req.Opts.ExtMnt, extMnt)
}

func (c *linuxContainer) addMaskPaths(req *criurpc.CriuReq) error {
for _, path := range c.config.MaskPaths {
fi, err := os.Stat(fmt.Sprintf("/proc/%d/root/%s", c.initProcess.pid(), path))
if err != nil {
if os.IsNotExist(err) {
continue
}
return err
}
if fi.IsDir() {
continue
}

extMnt := &criurpc.ExtMountMap{
Key: proto.String(path),
Val: proto.String("/dev/null"),
}
req.Opts.ExtMnt = append(req.Opts.ExtMnt, extMnt)
}

return nil
}

func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
c.m.Lock()
defer c.m.Unlock()
Expand Down Expand Up @@ -655,6 +678,15 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
}
}

if err := c.addMaskPaths(req); err != nil {
return err
}

for _, node := range c.config.Devices {
m := &configs.Mount{Destination: node.Path, Source: node.Path}
c.addCriuDumpMount(req, m)
}

// Write the FD info to a file in the image directory

fdsJSON, err := json.Marshal(c.initProcess.externalDescriptors())
Expand Down Expand Up @@ -792,6 +824,16 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
}
}

if len(c.config.MaskPaths) > 0 {
m := &configs.Mount{Destination: "/dev/null", Source: "/dev/null"}
c.addCriuRestoreMount(req, m)
}

for _, node := range c.config.Devices {
m := &configs.Mount{Destination: node.Path, Source: node.Path}
c.addCriuRestoreMount(req, m)
}

if criuOpts.EmptyNs&syscall.CLONE_NEWNET == 0 {
c.restoreNetwork(req, criuOpts)
}
Expand Down

0 comments on commit db99936

Please sign in to comment.