Add the Checkpointed state

I don't like the current logic in ct.Destroy(). I think ct.Destroy
must destoy ct or return an error.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2015-04-10 15:47:37 +03:00 committed by Michael Crosby
parent f5fad10193
commit 5fb0019c45
4 changed files with 20 additions and 9 deletions

View File

@ -21,6 +21,9 @@ const (
// The container exists, but all its processes are paused.
Paused
// The container exists, but its state is saved on disk
Checkpointed
// The container does not exist.
Destroyed
)

View File

@ -223,12 +223,6 @@ func newPipe() (parent *os.File, child *os.File, err error) {
func (c *linuxContainer) Destroy() error {
c.m.Lock()
defer c.m.Unlock()
// Since the state.json and CRIU image files are in the c.root
// directory, we should not remove it after checkpoint. Also,
// when CRIU exits after restore, we should not kill the processes.
if _, err := os.Stat(filepath.Join(c.root, "checkpoint")); err == nil {
return nil
}
status, err := c.currentStatus()
if err != nil {
return err
@ -569,10 +563,14 @@ func (c *linuxContainer) updateState(process parentProcess) error {
return err
}
defer f.Close()
os.RemoveAll(filepath.Join(c.root, "checkpoint"))
return json.NewEncoder(f).Encode(state)
}
func (c *linuxContainer) currentStatus() (Status, error) {
if _, err := os.Stat(filepath.Join(c.root, "checkpoint")); err == nil {
return Checkpointed, nil
}
if c.initProcess == nil {
return Destroyed, nil
}

View File

@ -93,10 +93,17 @@ func execAction(context *cli.Context) {
}
}
if created {
if err := container.Destroy(); err != nil {
status, err := container.Status()
if err != nil {
tty.Close()
fatal(err)
}
if status != libcontainer.Checkpointed {
if err := container.Destroy(); err != nil {
tty.Close()
fatal(err)
}
}
}
tty.Close()
os.Exit(utils.ExitStatus(status.Sys().(syscall.WaitStatus)))

View File

@ -53,8 +53,11 @@ var restoreCommand = cli.Command{
fatal(err)
}
}
if err := container.Destroy(); err != nil {
fatal(err)
ctStatus, err := container.Status()
if ctStatus == libcontainer.Destroyed {
if err := container.Destroy(); err != nil {
fatal(err)
}
}
os.Exit(utils.ExitStatus(status.Sys().(syscall.WaitStatus)))
},