Fix libcontainer states

Move initialized to created and destoryed to stopped.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2016-05-13 17:01:12 -07:00
parent 3fe7d7f31e
commit 30f1006b33
5 changed files with 20 additions and 30 deletions

View File

@ -116,7 +116,8 @@ information is displayed once every 5 seconds.`,
if err != nil { if err != nil {
return err 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()) return fmt.Errorf("container with id %s is not running", container.ID())
} }
var ( var (

View File

@ -15,7 +15,7 @@ import (
type Status int type Status int
const ( 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 Created Status = iota
// Running is the status that denotes the container exists and is running. // 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 is the status that denotes the container exists, but all its processes are paused.
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 is the status that denotes the container does not have a created or running process.
Stopped 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 { func (s Status) String() string {
@ -48,12 +41,8 @@ func (s Status) String() string {
return "pausing" return "pausing"
case Paused: case Paused:
return "paused" return "paused"
case Destroyed:
return "destroyed"
case Stopped: case Stopped:
return "stopped" return "stopped"
case Initialized:
return "initialized"
default: default:
return "unknown" return "unknown"
} }

View File

@ -181,7 +181,7 @@ func (c *linuxContainer) Start(process *Process) error {
if err != nil { if err != nil {
return err return err
} }
doInit := status == Destroyed doInit := status == Stopped
parent, err := c.newParentProcess(process, doInit) parent, err := c.newParentProcess(process, doInit)
if err != nil { if err != nil {
return newSystemErrorWithCause(err, "creating new parent process") return newSystemErrorWithCause(err, "creating new parent process")
@ -1038,8 +1038,8 @@ func (c *linuxContainer) refreshState() error {
return err return err
} }
switch t { switch t {
case Initialized: case Created:
return c.state.transition(&initializedState{c: c}) return c.state.transition(&createdState{c: c})
case Running: case Running:
return c.state.transition(&runningState{c: c}) return c.state.transition(&runningState{c: c})
} }
@ -1070,7 +1070,7 @@ func (c *linuxContainer) runType() (Status, error) {
check := []byte("_LIBCONTAINER") check := []byte("_LIBCONTAINER")
for _, v := range bytes.Split(environ, []byte("\x00")) { for _, v := range bytes.Split(environ, []byte("\x00")) {
if bytes.Contains(v, check) { if bytes.Contains(v, check) {
return Initialized, nil return Created, nil
} }
} }
return Running, nil return Running, nil

View File

@ -206,7 +206,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
root: containerRoot, root: containerRoot,
created: state.Created, created: state.Created,
} }
c.state = &createdState{c: c, s: Created} c.state = &loadedState{c: c}
if err := c.refreshState(); err != nil { if err := c.refreshState(); err != nil {
return nil, err return nil, err
} }

View File

@ -77,7 +77,7 @@ type stoppedState struct {
} }
func (b *stoppedState) status() Status { func (b *stoppedState) status() Status {
return Destroyed return Stopped
} }
func (b *stoppedState) transition(s containerState) error { func (b *stoppedState) transition(s containerState) error {
@ -139,25 +139,25 @@ func (r *runningState) destroy() error {
return destroy(r.c) return destroy(r.c)
} }
type initializedState struct { type createdState struct {
c *linuxContainer c *linuxContainer
} }
func (i *initializedState) status() Status { func (i *createdState) status() Status {
return Initialized return Created
} }
func (i *initializedState) transition(s containerState) error { func (i *createdState) transition(s containerState) error {
switch s.(type) { switch s.(type) {
case *runningState: case *runningState:
i.c.state = s i.c.state = s
case *initializedState: case *createdState:
return nil return nil
} }
return newStateTransitionError(i, s) return newStateTransitionError(i, s)
} }
func (i *initializedState) destroy() error { func (i *createdState) destroy() error {
return destroy(i.c) return destroy(i.c)
} }
@ -226,23 +226,23 @@ func (r *restoredState) destroy() error {
return destroy(r.c) 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. // processes inside and it should not be destroyed when it is exiting.
type createdState struct { type loadedState struct {
c *linuxContainer c *linuxContainer
s Status s Status
} }
func (n *createdState) status() Status { func (n *loadedState) status() Status {
return n.s return n.s
} }
func (n *createdState) transition(s containerState) error { func (n *loadedState) transition(s containerState) error {
n.c.state = s n.c.state = s
return nil return nil
} }
func (n *createdState) destroy() error { func (n *loadedState) destroy() error {
if err := n.c.refreshState(); err != nil { if err := n.c.refreshState(); err != nil {
return err return err
} }