Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit 97de9a4

Browse files
committed
Update cgroups paths in state to be a map with cgroup type as key and path as value.
Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <[email protected]> (github: vishh)
1 parent ad16526 commit 97de9a4

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

cgroups/cgroups.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ type Cgroup struct {
3737

3838
type ActiveCgroup interface {
3939
Cleanup() error
40-
Paths() ([]string, error)
40+
Paths() (map[string]string, error)
4141
}

cgroups/fs/apply_raw.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ func (raw *data) parent(subsystem string) (string, error) {
153153
return filepath.Join(raw.root, subsystem, initPath), nil
154154
}
155155

156-
func (raw *data) Paths() ([]string, error) {
157-
var paths []string
156+
func (raw *data) Paths() (map[string]string, error) {
157+
paths := make(map[string]string)
158158
for sysname := range subsystems {
159159
path, err := raw.path(sysname)
160160
if err != nil {
161161
return nil, err
162162
}
163-
paths = append(paths, path)
163+
paths[sysname] = path
164164
}
165165
return paths, nil
166166
}

cgroups/systemd/apply_systemd.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
type systemdCgroup struct {
2424
cleanupDirs []string
25+
cgroup *cgroups.Cgroup
2526
}
2627

2728
type subsystem interface {
@@ -100,6 +101,7 @@ func Apply(c *cgroups.Cgroup, pid int) (cgroups.ActiveCgroup, error) {
100101
res systemdCgroup
101102
)
102103

104+
res.cgroup = c
103105
// First set up things not supported by systemd
104106

105107
// -1 disables memorySwap
@@ -320,8 +322,22 @@ func writeFile(dir, file, data string) error {
320322
return ioutil.WriteFile(filepath.Join(dir, file), []byte(data), 0700)
321323
}
322324

323-
func (c *systemdCgroup) Paths() ([]string, error) {
324-
return c.cleanupDirs, nil
325+
func (c *systemdCgroup) Paths() (map[string]string, error) {
326+
paths := make(map[string]string)
327+
for sysname := range subsystems {
328+
subsystemPath, err := getSubsystemPath(c.cgroup, sysname)
329+
if err != nil {
330+
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem
331+
if err == cgroups.ErrNotFound {
332+
continue
333+
}
334+
335+
return nil, err
336+
}
337+
paths[sysname] = subsystemPath
338+
}
339+
340+
return paths, nil
325341
}
326342

327343
func (c *systemdCgroup) Cleanup() error {

cgroups/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func pathExists(path string) bool {
175175
return true
176176
}
177177

178-
func EnterPid(cgroupPaths []string, pid int) error {
178+
func EnterPid(cgroupPaths map[string]string, pid int) error {
179179
for _, path := range cgroupPaths {
180180
if pathExists(path) {
181181
if err := ioutil.WriteFile(filepath.Join(path, "cgroup.procs"),

state.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ type State struct {
1919
// Network runtime state.
2020
NetworkState network.NetworkState `json:"network_state,omitempty"`
2121

22-
// Path to all the cgroup dirs.
23-
CgroupPaths []string `json:"cgroup_paths,omitempty"`
22+
// Path to all the cgroups setup for a container. Key is cgroup subsystem name.
23+
CgroupPaths map[string]string `json:"cgroup_paths,omitempty"`
2424
}
2525

2626
// The running state of the container.

0 commit comments

Comments
 (0)