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:
parent
7038ddbc8c
commit
ce9d63376f
|
@ -1,4 +1,4 @@
|
|||
package libcontainer
|
||||
package configs
|
||||
|
||||
import (
|
||||
"encoding/json"
|
|
@ -21,7 +21,7 @@ type Container interface {
|
|||
// errors:
|
||||
// ContainerDestroyed - Container no longer exists,
|
||||
// Systemerror - System error.
|
||||
RunState() (RunState, error)
|
||||
RunState() (configs.RunState, error)
|
||||
|
||||
// Returns the current config of the container.
|
||||
Config() *configs.Config
|
||||
|
|
|
@ -19,7 +19,7 @@ type linuxContainer struct {
|
|||
id string
|
||||
root string
|
||||
config *configs.Config
|
||||
state *State
|
||||
state *configs.State
|
||||
cgroupManager CgroupManager
|
||||
initArgs []string
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ func (c *linuxContainer) Config() *configs.Config {
|
|||
return c.config
|
||||
}
|
||||
|
||||
func (c *linuxContainer) RunState() (RunState, error) {
|
||||
return Destroyed, nil // FIXME return a real state
|
||||
func (c *linuxContainer) RunState() (configs.RunState, error) {
|
||||
return configs.Destroyed, nil // FIXME return a real state
|
||||
}
|
||||
|
||||
func (c *linuxContainer) Processes() ([]int, error) {
|
||||
|
@ -61,18 +61,18 @@ func (c *linuxContainer) Stats() (*ContainerStats, error) {
|
|||
return stats, nil
|
||||
}
|
||||
|
||||
func (c *linuxContainer) StartProcess(config *ProcessConfig) (int, error) {
|
||||
func (c *linuxContainer) StartProcess(pconfig *ProcessConfig) (int, error) {
|
||||
state, err := c.RunState()
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
if state != Destroyed {
|
||||
if state != configs.Destroyed {
|
||||
glog.Info("start new container process")
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
if err := c.startInitProcess(config); err != nil {
|
||||
if err := c.startInitProcess(pconfig); err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ func (c *linuxContainer) Destroy() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if state != Destroyed {
|
||||
if state != configs.Destroyed {
|
||||
return newGenericError(nil, ContainerNotStopped)
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ func TestGetContainerStats(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
state: &State{},
|
||||
state: &configs.State{},
|
||||
}
|
||||
|
||||
stats, err := container.Stats()
|
||||
|
|
|
@ -93,7 +93,7 @@ func (l *linuxFactory) Create(id string, config *configs.Config) (Container, err
|
|||
root: containerRoot,
|
||||
config: config,
|
||||
initArgs: l.initArgs,
|
||||
state: &State{},
|
||||
state: &configs.State{},
|
||||
cgroupManager: cgroupManager,
|
||||
}, nil
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ func (l *linuxFactory) loadContainerConfig(root string) (*configs.Config, error)
|
|||
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))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
|
@ -154,7 +154,7 @@ func (l *linuxFactory) loadContainerState(root string) (*State, error) {
|
|||
}
|
||||
defer f.Close()
|
||||
|
||||
var state *State
|
||||
var state *configs.State
|
||||
if err := json.NewDecoder(f).Decode(&state); err != nil {
|
||||
return nil, newGenericError(err, SystemError)
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ func TestFactoryLoadContainer(t *testing.T) {
|
|||
expectedConfig = &configs.Config{
|
||||
RootFs: "/mycontainer/root",
|
||||
}
|
||||
expectedState = &State{
|
||||
expectedState = &configs.State{
|
||||
InitPid: 1024,
|
||||
}
|
||||
)
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"os/exec"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/libcontainer"
|
||||
"github.com/docker/libcontainer/cgroups"
|
||||
"github.com/docker/libcontainer/cgroups/fs"
|
||||
"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)
|
||||
}
|
||||
|
||||
state := &libcontainer.State{
|
||||
state := &configs.State{
|
||||
InitPid: command.Process.Pid,
|
||||
InitStartTime: started,
|
||||
NetworkState: networkState,
|
||||
CgroupPaths: cgroupPaths,
|
||||
}
|
||||
|
||||
if err := libcontainer.SaveState(dataPath, state); err != nil {
|
||||
if err := configs.SaveState(dataPath, state); err != nil {
|
||||
return terminate(err)
|
||||
}
|
||||
defer libcontainer.DeleteState(dataPath)
|
||||
defer configs.DeleteState(dataPath)
|
||||
|
||||
// wait for the child process to fully complete and receive an error message
|
||||
// if one was encoutered
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/libcontainer"
|
||||
"github.com/docker/libcontainer/apparmor"
|
||||
"github.com/docker/libcontainer/cgroups"
|
||||
"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
|
||||
// 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) {
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
func EnterCgroups(state *libcontainer.State, pid int) error {
|
||||
func EnterCgroups(state *configs.State, pid int) error {
|
||||
return cgroups.EnterPid(state.CgroupPaths, pid)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
// code path will drop us into the path that we can do the final setup of the namespace and exec the users
|
||||
// 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 (
|
||||
master *os.File
|
||||
console string
|
||||
|
|
Loading…
Reference in New Issue