diff --git a/libcontainer/configs/config_test.go b/libcontainer/configs/config_unix_test.go similarity index 99% rename from libcontainer/configs/config_test.go rename to libcontainer/configs/config_unix_test.go index 385e3775..27d07d4e 100644 --- a/libcontainer/configs/config_test.go +++ b/libcontainer/configs/config_unix_test.go @@ -1,3 +1,5 @@ +// +build linux freebsd + package configs import ( diff --git a/libcontainer/configs/config_windows_test.go b/libcontainer/configs/config_windows_test.go new file mode 100644 index 00000000..1a0c8fa2 --- /dev/null +++ b/libcontainer/configs/config_windows_test.go @@ -0,0 +1,3 @@ +package configs + +// All current tests are for Unix-specific functionality diff --git a/libcontainer/container.go b/libcontainer/container.go index a24b71b8..f1305b38 100644 --- a/libcontainer/container.go +++ b/libcontainer/container.go @@ -30,8 +30,9 @@ const ( Destroyed ) -// State represents a running container's state -type State struct { +// BaseState represents the platform agnostic pieces relating to a +// running container's state +type BaseState struct { // ID is the container ID. ID string `json:"id"` @@ -41,19 +42,8 @@ type State struct { // InitProcessStartTime is the init process start time. InitProcessStartTime string `json:"init_process_start"` - // Path to all the cgroups setup for a container. Key is cgroup subsystem name - // with the value as the path. - CgroupPaths map[string]string `json:"cgroup_paths"` - - // NamespacePaths are filepaths to the container's namespaces. Key is the namespace type - // with the value as the path. - NamespacePaths map[configs.NamespaceType]string `json:"namespace_paths"` - // Config is the container's configuration. Config configs.Config `json:"config"` - - // Container's standard descriptors (std{in,out,err}), needed for checkpoint and restore - ExternalDescriptors []string `json:"external_descriptors,omitempty"` } // A libcontainer container object. diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 40bdcd86..af95a6e1 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -36,6 +36,24 @@ type linuxContainer struct { criuVersion int } +// State represents a running container's state +type State struct { + BaseState + + // Platform specific fields below here + + // Path to all the cgroups setup for a container. Key is cgroup subsystem name + // with the value as the path. + CgroupPaths map[string]string `json:"cgroup_paths"` + + // NamespacePaths are filepaths to the container's namespaces. Key is the namespace type + // with the value as the path. + NamespacePaths map[configs.NamespaceType]string `json:"namespace_paths"` + + // Container's standard descriptors (std{in,out,err}), needed for checkpoint and restore + ExternalDescriptors []string `json:"external_descriptors,omitempty"` +} + // ID returns the container's unique ID func (c *linuxContainer) ID() string { return c.id @@ -917,13 +935,15 @@ func (c *linuxContainer) currentState() (*State, error) { return nil, newSystemError(err) } state := &State{ - ID: c.ID(), - Config: *c.config, - InitProcessPid: c.initProcess.pid(), - InitProcessStartTime: startTime, - CgroupPaths: c.cgroupManager.GetPaths(), - NamespacePaths: make(map[configs.NamespaceType]string), - ExternalDescriptors: c.initProcess.externalDescriptors(), + BaseState: BaseState{ + ID: c.ID(), + Config: *c.config, + InitProcessPid: c.initProcess.pid(), + InitProcessStartTime: startTime, + }, + CgroupPaths: c.cgroupManager.GetPaths(), + NamespacePaths: make(map[configs.NamespaceType]string), + ExternalDescriptors: c.initProcess.externalDescriptors(), } for _, ns := range c.config.Namespaces { state.NamespacePaths[ns.Type] = ns.GetPath(c.initProcess.pid()) diff --git a/libcontainer/container_windows.go b/libcontainer/container_windows.go new file mode 100644 index 00000000..0b1f6d89 --- /dev/null +++ b/libcontainer/container_windows.go @@ -0,0 +1,8 @@ +package libcontainer + +// State represents a running container's state +type State struct { + BaseState + + // Platform specific fields below here +} diff --git a/libcontainer/factory_linux_test.go b/libcontainer/factory_linux_test.go index 89f52f11..dccc8db4 100644 --- a/libcontainer/factory_linux_test.go +++ b/libcontainer/factory_linux_test.go @@ -137,8 +137,10 @@ func TestFactoryLoadContainer(t *testing.T) { Rootfs: "/mycontainer/root", } expectedState = &State{ - InitProcessPid: 1024, - Config: *expectedConfig, + BaseState: BaseState{ + InitProcessPid: 1024, + Config: *expectedConfig, + }, } ) if err := os.Mkdir(filepath.Join(root, id), 0700); err != nil {