cr: handle criu notifications in a separate function

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2015-04-10 18:03:23 +03:00 committed by Michael Crosby
parent 522f7b36ff
commit 65f9b1bd84
1 changed files with 33 additions and 33 deletions

View File

@ -5,7 +5,6 @@ package libcontainer
import (
"encoding/json"
"fmt"
"math"
"os"
"os/exec"
"path/filepath"
@ -447,8 +446,6 @@ func (c *linuxContainer) Restore(process *Process, imagePath string) error {
return err
}
var pid int32 = math.MinInt32
buf := make([]byte, 10*4096)
for true {
n, err := criuClient.Read(buf)
@ -476,31 +473,8 @@ func (c *linuxContainer) Restore(process *Process, imagePath string) error {
t = resp.GetType()
switch {
case t == criurpc.CriuReqType_NOTIFY:
notify := resp.GetNotify()
if notify == nil {
return fmt.Errorf("invalid response: %s", resp.String())
}
if notify.GetScript() == "setup-namespaces" {
pid = notify.GetPid()
}
if notify.GetScript() == "post-restore" {
// In many case, restore from the images can be done only once.
// If we want to create snapshots, we need to snapshot the file system.
os.RemoveAll(imagePath)
r, err := newRestoredProcess(int(pid))
if err != nil {
return err
}
// TODO: crosbymichael restore previous process information by saving the init process information in
// the container's state file or separate process state files.
if err := c.updateState(r); err != nil {
return err
}
process.ops = r
if err := c.criuNotifications(resp, process, imagePath); err != nil {
return err
}
t = criurpc.CriuReqType_NOTIFY
@ -518,11 +492,7 @@ func (c *linuxContainer) Restore(process *Process, imagePath string) error {
}
continue
case t == criurpc.CriuReqType_RESTORE:
restore := resp.GetRestore()
if restore != nil {
pid = restore.GetPid()
break
}
break;
default:
return fmt.Errorf("unable to parse the response %s", resp.String())
}
@ -543,6 +513,36 @@ func (c *linuxContainer) Restore(process *Process, imagePath string) error {
return nil
}
func (c *linuxContainer) criuNotifications(resp *criurpc.CriuResp, process *Process, imagePath string) error {
notify := resp.GetNotify()
if notify == nil {
return fmt.Errorf("invalid response: %s", resp.String())
}
switch {
case notify.GetScript() == "post-restore":
// In many case, restore from the images can be done only once.
// If we want to create snapshots, we need to snapshot the file system.
os.RemoveAll(imagePath)
pid := notify.GetPid()
r, err := newRestoredProcess(int(pid))
if err != nil {
return err
}
// TODO: crosbymichael restore previous process information by saving the init process information in
// the container's state file or separate process state files.
if err := c.updateState(r); err != nil {
return err
}
process.ops = r
break
}
return nil
}
func (c *linuxContainer) updateState(process parentProcess) error {
c.initProcess = process
state, err := c.currentState()