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 <vishnuk@google.com> (github: vishh)
This commit is contained in:
parent
ad16526d7f
commit
97de9a45f9
|
@ -37,5 +37,5 @@ type Cgroup struct {
|
|||
|
||||
type ActiveCgroup interface {
|
||||
Cleanup() error
|
||||
Paths() ([]string, error)
|
||||
Paths() (map[string]string, error)
|
||||
}
|
||||
|
|
|
@ -153,14 +153,14 @@ func (raw *data) parent(subsystem string) (string, error) {
|
|||
return filepath.Join(raw.root, subsystem, initPath), nil
|
||||
}
|
||||
|
||||
func (raw *data) Paths() ([]string, error) {
|
||||
var paths []string
|
||||
func (raw *data) Paths() (map[string]string, error) {
|
||||
paths := make(map[string]string)
|
||||
for sysname := range subsystems {
|
||||
path, err := raw.path(sysname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
paths = append(paths, path)
|
||||
paths[sysname] = path
|
||||
}
|
||||
return paths, nil
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
type systemdCgroup struct {
|
||||
cleanupDirs []string
|
||||
cgroup *cgroups.Cgroup
|
||||
}
|
||||
|
||||
type subsystem interface {
|
||||
|
@ -100,6 +101,7 @@ func Apply(c *cgroups.Cgroup, pid int) (cgroups.ActiveCgroup, error) {
|
|||
res systemdCgroup
|
||||
)
|
||||
|
||||
res.cgroup = c
|
||||
// First set up things not supported by systemd
|
||||
|
||||
// -1 disables memorySwap
|
||||
|
@ -320,8 +322,22 @@ func writeFile(dir, file, data string) error {
|
|||
return ioutil.WriteFile(filepath.Join(dir, file), []byte(data), 0700)
|
||||
}
|
||||
|
||||
func (c *systemdCgroup) Paths() ([]string, error) {
|
||||
return c.cleanupDirs, nil
|
||||
func (c *systemdCgroup) Paths() (map[string]string, error) {
|
||||
paths := make(map[string]string)
|
||||
for sysname := range subsystems {
|
||||
subsystemPath, err := getSubsystemPath(c.cgroup, sysname)
|
||||
if err != nil {
|
||||
// Don't fail if a cgroup hierarchy was not found, just skip this subsystem
|
||||
if err == cgroups.ErrNotFound {
|
||||
continue
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
paths[sysname] = subsystemPath
|
||||
}
|
||||
|
||||
return paths, nil
|
||||
}
|
||||
|
||||
func (c *systemdCgroup) Cleanup() error {
|
||||
|
|
|
@ -175,7 +175,7 @@ func pathExists(path string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func EnterPid(cgroupPaths []string, pid int) error {
|
||||
func EnterPid(cgroupPaths map[string]string, pid int) error {
|
||||
for _, path := range cgroupPaths {
|
||||
if pathExists(path) {
|
||||
if err := ioutil.WriteFile(filepath.Join(path, "cgroup.procs"),
|
||||
|
|
4
state.go
4
state.go
|
@ -19,8 +19,8 @@ type State struct {
|
|||
// Network runtime state.
|
||||
NetworkState network.NetworkState `json:"network_state,omitempty"`
|
||||
|
||||
// Path to all the cgroup dirs.
|
||||
CgroupPaths []string `json:"cgroup_paths,omitempty"`
|
||||
// Path to all the cgroups setup for a container. Key is cgroup subsystem name.
|
||||
CgroupPaths map[string]string `json:"cgroup_paths,omitempty"`
|
||||
}
|
||||
|
||||
// The running state of the container.
|
||||
|
|
Loading…
Reference in New Issue