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:
parent
f5fad10193
commit
5fb0019c45
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -93,11 +93,18 @@ func execAction(context *cli.Context) {
|
|||
}
|
||||
}
|
||||
if created {
|
||||
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)))
|
||||
}
|
||||
|
|
|
@ -53,9 +53,12 @@ var restoreCommand = cli.Command{
|
|||
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)))
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue