libcontainer: move State in the configs package

We are going to import the namespaces package into libcontainer,
so libcontainer should not be imported into namespaces.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
This commit is contained in:
Andrey Vagin 2014-12-17 12:30:52 +03:00
parent 7038ddbc8c
commit ce9d63376f
9 changed files with 20 additions and 22 deletions

View File

@ -1,4 +1,4 @@
package libcontainer package configs
import ( import (
"encoding/json" "encoding/json"

View File

@ -21,7 +21,7 @@ type Container interface {
// errors: // errors:
// ContainerDestroyed - Container no longer exists, // ContainerDestroyed - Container no longer exists,
// Systemerror - System error. // Systemerror - System error.
RunState() (RunState, error) RunState() (configs.RunState, error)
// Returns the current config of the container. // Returns the current config of the container.
Config() *configs.Config Config() *configs.Config

View File

@ -19,7 +19,7 @@ type linuxContainer struct {
id string id string
root string root string
config *configs.Config config *configs.Config
state *State state *configs.State
cgroupManager CgroupManager cgroupManager CgroupManager
initArgs []string initArgs []string
} }
@ -32,8 +32,8 @@ func (c *linuxContainer) Config() *configs.Config {
return c.config return c.config
} }
func (c *linuxContainer) RunState() (RunState, error) { func (c *linuxContainer) RunState() (configs.RunState, error) {
return Destroyed, nil // FIXME return a real state return configs.Destroyed, nil // FIXME return a real state
} }
func (c *linuxContainer) Processes() ([]int, error) { func (c *linuxContainer) Processes() ([]int, error) {
@ -61,18 +61,18 @@ func (c *linuxContainer) Stats() (*ContainerStats, error) {
return stats, nil return stats, nil
} }
func (c *linuxContainer) StartProcess(config *ProcessConfig) (int, error) { func (c *linuxContainer) StartProcess(pconfig *ProcessConfig) (int, error) {
state, err := c.RunState() state, err := c.RunState()
if err != nil { if err != nil {
return -1, err return -1, err
} }
if state != Destroyed { if state != configs.Destroyed {
glog.Info("start new container process") glog.Info("start new container process")
panic("not implemented") panic("not implemented")
} }
if err := c.startInitProcess(config); err != nil { if err := c.startInitProcess(pconfig); err != nil {
return -1, err return -1, err
} }
@ -141,7 +141,7 @@ func (c *linuxContainer) Destroy() error {
return err return err
} }
if state != Destroyed { if state != configs.Destroyed {
return newGenericError(nil, ContainerNotStopped) return newGenericError(nil, ContainerNotStopped)
} }

View File

@ -53,7 +53,7 @@ func TestGetContainerStats(t *testing.T) {
}, },
}, },
}, },
state: &State{}, state: &configs.State{},
} }
stats, err := container.Stats() stats, err := container.Stats()

View File

@ -93,7 +93,7 @@ func (l *linuxFactory) Create(id string, config *configs.Config) (Container, err
root: containerRoot, root: containerRoot,
config: config, config: config,
initArgs: l.initArgs, initArgs: l.initArgs,
state: &State{}, state: &configs.State{},
cgroupManager: cgroupManager, cgroupManager: cgroupManager,
}, nil }, nil
} }
@ -144,7 +144,7 @@ func (l *linuxFactory) loadContainerConfig(root string) (*configs.Config, error)
return config, nil return config, nil
} }
func (l *linuxFactory) loadContainerState(root string) (*State, error) { func (l *linuxFactory) loadContainerState(root string) (*configs.State, error) {
f, err := os.Open(filepath.Join(root, stateFilename)) f, err := os.Open(filepath.Join(root, stateFilename))
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
@ -154,7 +154,7 @@ func (l *linuxFactory) loadContainerState(root string) (*State, error) {
} }
defer f.Close() defer f.Close()
var state *State var state *configs.State
if err := json.NewDecoder(f).Decode(&state); err != nil { if err := json.NewDecoder(f).Decode(&state); err != nil {
return nil, newGenericError(err, SystemError) return nil, newGenericError(err, SystemError)
} }

View File

@ -88,7 +88,7 @@ func TestFactoryLoadContainer(t *testing.T) {
expectedConfig = &configs.Config{ expectedConfig = &configs.Config{
RootFs: "/mycontainer/root", RootFs: "/mycontainer/root",
} }
expectedState = &State{ expectedState = &configs.State{
InitPid: 1024, InitPid: 1024,
} }
) )

View File

@ -9,7 +9,6 @@ import (
"os/exec" "os/exec"
"syscall" "syscall"
"github.com/docker/libcontainer"
"github.com/docker/libcontainer/cgroups" "github.com/docker/libcontainer/cgroups"
"github.com/docker/libcontainer/cgroups/fs" "github.com/docker/libcontainer/cgroups/fs"
"github.com/docker/libcontainer/cgroups/systemd" "github.com/docker/libcontainer/cgroups/systemd"
@ -80,17 +79,17 @@ func Exec(container *configs.Config, stdin io.Reader, stdout, stderr io.Writer,
return terminate(err) return terminate(err)
} }
state := &libcontainer.State{ state := &configs.State{
InitPid: command.Process.Pid, InitPid: command.Process.Pid,
InitStartTime: started, InitStartTime: started,
NetworkState: networkState, NetworkState: networkState,
CgroupPaths: cgroupPaths, CgroupPaths: cgroupPaths,
} }
if err := libcontainer.SaveState(dataPath, state); err != nil { if err := configs.SaveState(dataPath, state); err != nil {
return terminate(err) return terminate(err)
} }
defer libcontainer.DeleteState(dataPath) defer configs.DeleteState(dataPath)
// wait for the child process to fully complete and receive an error message // wait for the child process to fully complete and receive an error message
// if one was encoutered // if one was encoutered

View File

@ -12,7 +12,6 @@ import (
"strconv" "strconv"
"syscall" "syscall"
"github.com/docker/libcontainer"
"github.com/docker/libcontainer/apparmor" "github.com/docker/libcontainer/apparmor"
"github.com/docker/libcontainer/cgroups" "github.com/docker/libcontainer/cgroups"
"github.com/docker/libcontainer/configs" "github.com/docker/libcontainer/configs"
@ -22,7 +21,7 @@ import (
// ExecIn reexec's the initPath with the argv 0 rewrite to "nsenter" so that it is able to run the // ExecIn reexec's the initPath with the argv 0 rewrite to "nsenter" so that it is able to run the
// setns code in a single threaded environment joining the existing containers' namespaces. // setns code in a single threaded environment joining the existing containers' namespaces.
func ExecIn(container *configs.Config, state *libcontainer.State, userArgs []string, initPath, action string, func ExecIn(container *configs.Config, state *configs.State, userArgs []string, initPath, action string,
stdin io.Reader, stdout, stderr io.Writer, console string, startCallback func(*exec.Cmd)) (int, error) { stdin io.Reader, stdout, stderr io.Writer, console string, startCallback func(*exec.Cmd)) (int, error) {
args := []string{fmt.Sprintf("nsenter-%s", action), "--nspid", strconv.Itoa(state.InitPid)} args := []string{fmt.Sprintf("nsenter-%s", action), "--nspid", strconv.Itoa(state.InitPid)}
@ -119,6 +118,6 @@ func FinalizeSetns(container *configs.Config, args []string) error {
panic("unreachable") panic("unreachable")
} }
func EnterCgroups(state *libcontainer.State, pid int) error { func EnterCgroups(state *configs.State, pid int) error {
return cgroups.EnterPid(state.CgroupPaths, pid) return cgroups.EnterPid(state.CgroupPaths, pid)
} }

View File

@ -111,7 +111,7 @@ func execAction(context *cli.Context) {
// with the nsenter argument so that the C code can setns an the namespaces that we require. Then that // with the nsenter argument so that the C code can setns an the namespaces that we require. Then that
// code path will drop us into the path that we can do the final setup of the namespace and exec the users // code path will drop us into the path that we can do the final setup of the namespace and exec the users
// application. // application.
func startInExistingContainer(config *configs.Config, state *libcontainer.State, action string, context *cli.Context) (int, error) { func startInExistingContainer(config *configs.Config, state *configs.State, action string, context *cli.Context) (int, error) {
var ( var (
master *os.File master *os.File
console string console string