Fix libcontainer states
Move initialized to created and destoryed to stopped. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
3fe7d7f31e
commit
30f1006b33
|
@ -116,7 +116,8 @@ information is displayed once every 5 seconds.`,
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if status == libcontainer.Destroyed {
|
||||
if status == libcontainer.Stopped {
|
||||
fatalf("container with id %s is not running", container.ID())
|
||||
return fmt.Errorf("container with id %s is not running", container.ID())
|
||||
}
|
||||
var (
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
type Status int
|
||||
|
||||
const (
|
||||
// Created is the status that denotes the container exists but has not been run yet
|
||||
// Created is the status that denotes the container exists but has not been run yet.
|
||||
Created Status = iota
|
||||
|
||||
// Running is the status that denotes the container exists and is running.
|
||||
|
@ -27,15 +27,8 @@ const (
|
|||
// Paused is the status that denotes the container exists, but all its processes are paused.
|
||||
Paused
|
||||
|
||||
// Destroyed is the status that denotes the container does not exist.
|
||||
Destroyed
|
||||
|
||||
// Stopped is the status that denotes the container does not have a created or running process.
|
||||
Stopped
|
||||
|
||||
// Initialized is the status where the container has all the namespaces created but the user
|
||||
// process has not been start.
|
||||
Initialized
|
||||
)
|
||||
|
||||
func (s Status) String() string {
|
||||
|
@ -48,12 +41,8 @@ func (s Status) String() string {
|
|||
return "pausing"
|
||||
case Paused:
|
||||
return "paused"
|
||||
case Destroyed:
|
||||
return "destroyed"
|
||||
case Stopped:
|
||||
return "stopped"
|
||||
case Initialized:
|
||||
return "initialized"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ func (c *linuxContainer) Start(process *Process) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
doInit := status == Destroyed
|
||||
doInit := status == Stopped
|
||||
parent, err := c.newParentProcess(process, doInit)
|
||||
if err != nil {
|
||||
return newSystemErrorWithCause(err, "creating new parent process")
|
||||
|
@ -1038,8 +1038,8 @@ func (c *linuxContainer) refreshState() error {
|
|||
return err
|
||||
}
|
||||
switch t {
|
||||
case Initialized:
|
||||
return c.state.transition(&initializedState{c: c})
|
||||
case Created:
|
||||
return c.state.transition(&createdState{c: c})
|
||||
case Running:
|
||||
return c.state.transition(&runningState{c: c})
|
||||
}
|
||||
|
@ -1070,7 +1070,7 @@ func (c *linuxContainer) runType() (Status, error) {
|
|||
check := []byte("_LIBCONTAINER")
|
||||
for _, v := range bytes.Split(environ, []byte("\x00")) {
|
||||
if bytes.Contains(v, check) {
|
||||
return Initialized, nil
|
||||
return Created, nil
|
||||
}
|
||||
}
|
||||
return Running, nil
|
||||
|
|
|
@ -206,7 +206,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
|
|||
root: containerRoot,
|
||||
created: state.Created,
|
||||
}
|
||||
c.state = &createdState{c: c, s: Created}
|
||||
c.state = &loadedState{c: c}
|
||||
if err := c.refreshState(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ type stoppedState struct {
|
|||
}
|
||||
|
||||
func (b *stoppedState) status() Status {
|
||||
return Destroyed
|
||||
return Stopped
|
||||
}
|
||||
|
||||
func (b *stoppedState) transition(s containerState) error {
|
||||
|
@ -139,25 +139,25 @@ func (r *runningState) destroy() error {
|
|||
return destroy(r.c)
|
||||
}
|
||||
|
||||
type initializedState struct {
|
||||
type createdState struct {
|
||||
c *linuxContainer
|
||||
}
|
||||
|
||||
func (i *initializedState) status() Status {
|
||||
return Initialized
|
||||
func (i *createdState) status() Status {
|
||||
return Created
|
||||
}
|
||||
|
||||
func (i *initializedState) transition(s containerState) error {
|
||||
func (i *createdState) transition(s containerState) error {
|
||||
switch s.(type) {
|
||||
case *runningState:
|
||||
i.c.state = s
|
||||
case *initializedState:
|
||||
case *createdState:
|
||||
return nil
|
||||
}
|
||||
return newStateTransitionError(i, s)
|
||||
}
|
||||
|
||||
func (i *initializedState) destroy() error {
|
||||
func (i *createdState) destroy() error {
|
||||
return destroy(i.c)
|
||||
}
|
||||
|
||||
|
@ -226,23 +226,23 @@ func (r *restoredState) destroy() error {
|
|||
return destroy(r.c)
|
||||
}
|
||||
|
||||
// createdState is used whenever a container is restored, loaded, or setting additional
|
||||
// loadedState is used whenever a container is restored, loaded, or setting additional
|
||||
// processes inside and it should not be destroyed when it is exiting.
|
||||
type createdState struct {
|
||||
type loadedState struct {
|
||||
c *linuxContainer
|
||||
s Status
|
||||
}
|
||||
|
||||
func (n *createdState) status() Status {
|
||||
func (n *loadedState) status() Status {
|
||||
return n.s
|
||||
}
|
||||
|
||||
func (n *createdState) transition(s containerState) error {
|
||||
func (n *loadedState) transition(s containerState) error {
|
||||
n.c.state = s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *createdState) destroy() error {
|
||||
func (n *loadedState) destroy() error {
|
||||
if err := n.c.refreshState(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue