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.
|
// The container exists, but all its processes are paused.
|
||||||
Paused
|
Paused
|
||||||
|
|
||||||
|
// The container exists, but its state is saved on disk
|
||||||
|
Checkpointed
|
||||||
|
|
||||||
// The container does not exist.
|
// The container does not exist.
|
||||||
Destroyed
|
Destroyed
|
||||||
)
|
)
|
||||||
|
|
|
@ -223,12 +223,6 @@ func newPipe() (parent *os.File, child *os.File, err error) {
|
||||||
func (c *linuxContainer) Destroy() error {
|
func (c *linuxContainer) Destroy() error {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
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()
|
status, err := c.currentStatus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -569,10 +563,14 @@ func (c *linuxContainer) updateState(process parentProcess) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
os.RemoveAll(filepath.Join(c.root, "checkpoint"))
|
||||||
return json.NewEncoder(f).Encode(state)
|
return json.NewEncoder(f).Encode(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *linuxContainer) currentStatus() (Status, error) {
|
func (c *linuxContainer) currentStatus() (Status, error) {
|
||||||
|
if _, err := os.Stat(filepath.Join(c.root, "checkpoint")); err == nil {
|
||||||
|
return Checkpointed, nil
|
||||||
|
}
|
||||||
if c.initProcess == nil {
|
if c.initProcess == nil {
|
||||||
return Destroyed, nil
|
return Destroyed, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,11 +93,18 @@ func execAction(context *cli.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if created {
|
if created {
|
||||||
|
status, err := container.Status()
|
||||||
|
if err != nil {
|
||||||
|
tty.Close()
|
||||||
|
fatal(err)
|
||||||
|
}
|
||||||
|
if status != libcontainer.Checkpointed {
|
||||||
if err := container.Destroy(); err != nil {
|
if err := container.Destroy(); err != nil {
|
||||||
tty.Close()
|
tty.Close()
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
tty.Close()
|
tty.Close()
|
||||||
os.Exit(utils.ExitStatus(status.Sys().(syscall.WaitStatus)))
|
os.Exit(utils.ExitStatus(status.Sys().(syscall.WaitStatus)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,12 @@ var restoreCommand = cli.Command{
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ctStatus, err := container.Status()
|
||||||
|
if ctStatus == libcontainer.Destroyed {
|
||||||
if err := container.Destroy(); err != nil {
|
if err := container.Destroy(); err != nil {
|
||||||
fatal(err)
|
fatal(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
os.Exit(utils.ExitStatus(status.Sys().(syscall.WaitStatus)))
|
os.Exit(utils.ExitStatus(status.Sys().(syscall.WaitStatus)))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue