Merge pull request #2414 from kolyshkin/criu-notif

use lazy-pages ready notification for criu >= 3.15
This commit is contained in:
Akihiro Suda 2020-06-16 09:31:12 +09:00 committed by GitHub
commit 601fa557c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 9 deletions

View File

@ -974,7 +974,11 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
return fmt.Errorf("invalid --status-fd argument %d: not writable", fd) return fmt.Errorf("invalid --status-fd argument %d: not writable", fd)
} }
rpcOpts.StatusFd = proto.Int32(int32(fd)) if c.checkCriuVersion(31500) != nil {
// For criu 3.15+, use notifications (see case "status-ready"
// in criuNotifications). Otherwise, rely on criu status fd.
rpcOpts.StatusFd = proto.Int32(int32(fd))
}
} }
} }
@ -1579,23 +1583,24 @@ func (c *linuxContainer) criuNotifications(resp *criurpc.CriuResp, process *Proc
if notify == nil { if notify == nil {
return fmt.Errorf("invalid response: %s", resp.String()) return fmt.Errorf("invalid response: %s", resp.String())
} }
logrus.Debugf("notify: %s\n", notify.GetScript()) script := notify.GetScript()
switch { logrus.Debugf("notify: %s\n", script)
case notify.GetScript() == "post-dump": switch script {
case "post-dump":
f, err := os.Create(filepath.Join(c.root, "checkpoint")) f, err := os.Create(filepath.Join(c.root, "checkpoint"))
if err != nil { if err != nil {
return err return err
} }
f.Close() f.Close()
case notify.GetScript() == "network-unlock": case "network-unlock":
if err := unlockNetwork(c.config); err != nil { if err := unlockNetwork(c.config); err != nil {
return err return err
} }
case notify.GetScript() == "network-lock": case "network-lock":
if err := lockNetwork(c.config); err != nil { if err := lockNetwork(c.config); err != nil {
return err return err
} }
case notify.GetScript() == "setup-namespaces": case "setup-namespaces":
if c.config.Hooks != nil { if c.config.Hooks != nil {
s, err := c.currentOCIState() s, err := c.currentOCIState()
if err != nil { if err != nil {
@ -1608,7 +1613,7 @@ func (c *linuxContainer) criuNotifications(resp *criurpc.CriuResp, process *Proc
} }
} }
} }
case notify.GetScript() == "post-restore": case "post-restore":
pid := notify.GetPid() pid := notify.GetPid()
p, err := os.FindProcess(int(pid)) p, err := os.FindProcess(int(pid))
@ -1638,7 +1643,7 @@ func (c *linuxContainer) criuNotifications(resp *criurpc.CriuResp, process *Proc
logrus.Error(err) logrus.Error(err)
} }
} }
case notify.GetScript() == "orphan-pts-master": case "orphan-pts-master":
scm, err := unix.ParseSocketControlMessage(oob) scm, err := unix.ParseSocketControlMessage(oob)
if err != nil { if err != nil {
return err return err
@ -1655,6 +1660,16 @@ func (c *linuxContainer) criuNotifications(resp *criurpc.CriuResp, process *Proc
if err := utils.SendFd(process.ConsoleSocket, master.Name(), master.Fd()); err != nil { if err := utils.SendFd(process.ConsoleSocket, master.Name(), master.Fd()); err != nil {
return err return err
} }
case "status-ready":
if opts.StatusFd != -1 {
// write \0 to status fd to notify that lazy page server is ready
_, err := unix.Write(opts.StatusFd, []byte{0})
if err != nil {
logrus.Warnf("can't write \\0 to status fd: %v", err)
}
_ = unix.Close(opts.StatusFd)
opts.StatusFd = -1
}
} }
return nil return nil
} }