Add checks in Create and Update Cgroup methods

This commit is contained in:
Buddha Prakash
2016-07-06 15:08:01 -07:00
parent c0b67b62b2
commit dcfff45ab7
4 changed files with 107 additions and 68 deletions

View File

@@ -18,11 +18,8 @@ package cm
import (
"fmt"
"path"
libcontainercgroups "github.com/opencontainers/runc/libcontainer/cgroups"
cgroupfs "github.com/opencontainers/runc/libcontainer/cgroups/fs"
libcontainerconfigs "github.com/opencontainers/runc/libcontainer/configs"
)
// cgroupSubsystems holds information about the mounted cgroup subsytems
@@ -59,40 +56,3 @@ func getCgroupSubsystems() (*cgroupSubsystems, error) {
mountPoints: mountPoints,
}, nil
}
// getLibcontainerCgroupManager returns libcontainer's cgroups manager
// object with the specified cgroup configuration
func getLibcontainerCgroupManager(cgroupConfig *CgroupConfig, subsystems *cgroupSubsystems) (*cgroupfs.Manager, error) {
// get cgroup name
name := cgroupConfig.Name
// Get map of all cgroup paths on the system for the particular cgroup
cgroupPaths := make(map[string]string, len(subsystems.mountPoints))
for key, val := range subsystems.mountPoints {
cgroupPaths[key] = path.Join(val, name)
}
// Extract the cgroup resource parameters
resourceConfig := cgroupConfig.ResourceParameters
resources := &libcontainerconfigs.Resources{}
resources.AllowAllDevices = true
if resourceConfig.Memory != nil {
resources.Memory = *resourceConfig.Memory
}
if resourceConfig.CpuShares != nil {
resources.CpuShares = *resourceConfig.CpuShares
}
if resourceConfig.CpuQuota != nil {
resources.CpuQuota = *resourceConfig.CpuQuota
}
// Initialize libcontainer's cgroup config
libcontainerCgroupConfig := &libcontainerconfigs.Cgroup{
Name: path.Base(name),
Parent: path.Dir(name),
Resources: resources,
}
return &cgroupfs.Manager{
Cgroups: libcontainerCgroupConfig,
Paths: cgroupPaths,
}, nil
}