Skip to content

Commit fe1cce6

Browse files
author
John Howard
committed
Windows: Refactor state struct
Signed-off-by: John Howard <jhoward@microsoft.com>
1 parent 97929bd commit fe1cce6

File tree

6 files changed

+47
-22
lines changed

6 files changed

+47
-22
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux freebsd
2+
13
package configs
24

35
import (
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package configs
2+
3+
// All current tests are for Unix-specific functionality

libcontainer/container.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ const (
3030
Destroyed
3131
)
3232

33-
// State represents a running container's state
34-
type State struct {
33+
// BaseState represents the platform agnostic pieces relating to a
34+
// running container's state
35+
type BaseState struct {
3536
// ID is the container ID.
3637
ID string `json:"id"`
3738

@@ -41,19 +42,8 @@ type State struct {
4142
// InitProcessStartTime is the init process start time.
4243
InitProcessStartTime string `json:"init_process_start"`
4344

44-
// Path to all the cgroups setup for a container. Key is cgroup subsystem name
45-
// with the value as the path.
46-
CgroupPaths map[string]string `json:"cgroup_paths"`
47-
48-
// NamespacePaths are filepaths to the container's namespaces. Key is the namespace type
49-
// with the value as the path.
50-
NamespacePaths map[configs.NamespaceType]string `json:"namespace_paths"`
51-
5245
// Config is the container's configuration.
5346
Config configs.Config `json:"config"`
54-
55-
// Container's standard descriptors (std{in,out,err}), needed for checkpoint and restore
56-
ExternalDescriptors []string `json:"external_descriptors,omitempty"`
5747
}
5848

5949
// A libcontainer container object.

libcontainer/container_linux.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ type linuxContainer struct {
3434
m sync.Mutex
3535
}
3636

37+
// State represents a running container's state
38+
type State struct {
39+
BaseState
40+
41+
// Platform specific fields below here
42+
43+
// Path to all the cgroups setup for a container. Key is cgroup subsystem name
44+
// with the value as the path.
45+
CgroupPaths map[string]string `json:"cgroup_paths"`
46+
47+
// NamespacePaths are filepaths to the container's namespaces. Key is the namespace type
48+
// with the value as the path.
49+
NamespacePaths map[configs.NamespaceType]string `json:"namespace_paths"`
50+
51+
// Container's standard descriptors (std{in,out,err}), needed for checkpoint and restore
52+
ExternalDescriptors []string `json:"external_descriptors,omitempty"`
53+
}
54+
3755
// ID returns the container's unique ID
3856
func (c *linuxContainer) ID() string {
3957
return c.id
@@ -899,13 +917,15 @@ func (c *linuxContainer) currentState() (*State, error) {
899917
return nil, newSystemError(err)
900918
}
901919
state := &State{
902-
ID: c.ID(),
903-
Config: *c.config,
904-
InitProcessPid: c.initProcess.pid(),
905-
InitProcessStartTime: startTime,
906-
CgroupPaths: c.cgroupManager.GetPaths(),
907-
NamespacePaths: make(map[configs.NamespaceType]string),
908-
ExternalDescriptors: c.initProcess.externalDescriptors(),
920+
BaseState: BaseState{
921+
ID: c.ID(),
922+
Config: *c.config,
923+
InitProcessPid: c.initProcess.pid(),
924+
InitProcessStartTime: startTime,
925+
},
926+
CgroupPaths: c.cgroupManager.GetPaths(),
927+
NamespacePaths: make(map[configs.NamespaceType]string),
928+
ExternalDescriptors: c.initProcess.externalDescriptors(),
909929
}
910930
for _, ns := range c.config.Namespaces {
911931
state.NamespacePaths[ns.Type] = ns.GetPath(c.initProcess.pid())

libcontainer/container_windows.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package libcontainer
2+
3+
// State represents a running container's state
4+
type State struct {
5+
BaseState
6+
7+
// Platform specific fields below here
8+
}

libcontainer/factory_linux_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ func TestFactoryLoadContainer(t *testing.T) {
137137
Rootfs: "/mycontainer/root",
138138
}
139139
expectedState = &State{
140-
InitProcessPid: 1024,
141-
Config: *expectedConfig,
140+
BaseState: BaseState{
141+
InitProcessPid: 1024,
142+
Config: *expectedConfig,
143+
},
142144
}
143145
)
144146
if err := os.Mkdir(filepath.Join(root, id), 0700); err != nil {

0 commit comments

Comments
 (0)