From df39686c935f2a6a2cde59db8607c7f7855fd286 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Tue, 8 Sep 2015 12:02:08 +0300 Subject: [PATCH] c/r: create cgroups to restore a container Here are two reasons: * If we use systemd, we need to ask it to create cgroups * If a container is restored with another ID, we need to change paths to cgroups. Signed-off-by: Andrey Vagin --- libcontainer/container_linux.go | 36 ++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 9210ec6a..79d41768 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -411,7 +411,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { return err } - err = c.criuSwrk(nil, req, criuOpts) + err = c.criuSwrk(nil, req, criuOpts, false) if err != nil { return err } @@ -504,6 +504,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error { FileLocks: proto.Bool(criuOpts.FileLocks), }, } + for _, m := range c.config.Mounts { switch m.Device { case "bind": @@ -561,14 +562,36 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error { } } - err = c.criuSwrk(process, req, criuOpts) + err = c.criuSwrk(process, req, criuOpts, true) if err != nil { return err } return nil } -func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts *CriuOpts) error { +func (c *linuxContainer) criuApplyCgroups(pid int, req *criurpc.CriuReq) error { + if err := c.cgroupManager.Apply(pid); err != nil { + return err + } + + path := fmt.Sprintf("/proc/%d/cgroup", pid) + cgroupsPaths, err := cgroups.ParseCgroupFile(path) + if err != nil { + return err + } + + for c, p := range cgroupsPaths { + cgroupRoot := &criurpc.CgroupRoot{ + Ctrl: proto.String(c), + Path: proto.String(p), + } + req.Opts.CgRoot = append(req.Opts.CgRoot, cgroupRoot) + } + + return nil +} + +func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts *CriuOpts, applyCgroups bool) error { fds, err := syscall.Socketpair(syscall.AF_LOCAL, syscall.SOCK_SEQPACKET|syscall.SOCK_CLOEXEC, 0) if err != nil { return err @@ -602,6 +625,13 @@ func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts * } }() + if applyCgroups { + err := c.criuApplyCgroups(cmd.Process.Pid, req) + if err != nil { + return err + } + } + var extFds []string if process != nil { extFds, err = getPipeFds(cmd.Process.Pid)