Implement systemd support for freezer
These PR does a few things. It ensures that the freezer cgroup is joined in the systemd driver. It also provides a public api for setting the freezer state via the cgroups package. Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
cfde39c592
commit
2616e87cad
5 changed files with 118 additions and 68 deletions
|
@ -19,3 +19,7 @@ func Apply(c *cgroups.Cgroup, pid int) (cgroups.ActiveCgroup, error) {
|
|||
func GetPids(c *cgroups.Cgroup) ([]int, error) {
|
||||
return nil, fmt.Errorf("Systemd not supported")
|
||||
}
|
||||
|
||||
func Freeze(c *cgroups.Cgroup, state cgroups.FreezerState) error {
|
||||
return fmt.Errorf("Systemd not supported")
|
||||
}
|
||||
|
|
|
@ -218,6 +218,14 @@ func Apply(c *cgroups.Cgroup, pid int) (cgroups.ActiveCgroup, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// we need to manually join the freezer cgroup in systemd because it does not currently support it
|
||||
// via the dbus api
|
||||
freezerPath, err := joinFreezer(c, pid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res.cleanupDirs = append(res.cleanupDirs, freezerPath)
|
||||
|
||||
if len(cpusetArgs) != 0 {
|
||||
// systemd does not atm set up the cpuset controller, so we must manually
|
||||
// join it. Additionally that is a very finicky controller where each
|
||||
|
@ -227,14 +235,19 @@ func Apply(c *cgroups.Cgroup, pid int) (cgroups.ActiveCgroup, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
initPath, err := cgroups.GetInitCgroupDir("cpuset")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rootPath := filepath.Join(mountpoint, initPath)
|
||||
var (
|
||||
foundCpus bool
|
||||
foundMems bool
|
||||
|
||||
path := filepath.Join(mountpoint, initPath, c.Parent+"-"+c.Name)
|
||||
rootPath = filepath.Join(mountpoint, initPath)
|
||||
path = filepath.Join(mountpoint, initPath, c.Parent+"-"+c.Name)
|
||||
)
|
||||
|
||||
res.cleanupDirs = append(res.cleanupDirs, path)
|
||||
|
||||
|
@ -242,9 +255,6 @@ func Apply(c *cgroups.Cgroup, pid int) (cgroups.ActiveCgroup, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
foundCpus := false
|
||||
foundMems := false
|
||||
|
||||
for _, arg := range cpusetArgs {
|
||||
if arg.File == "cpuset.cpus" {
|
||||
foundCpus = true
|
||||
|
@ -303,6 +313,47 @@ func (c *systemdCgroup) Cleanup() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func joinFreezer(c *cgroups.Cgroup, pid int) (string, error) {
|
||||
path, err := getFreezerPath(c)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(path, 0755); err != nil && !os.IsExist(err) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(filepath.Join(path, "cgroup.procs"), []byte(strconv.Itoa(pid)), 0700); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return path, nil
|
||||
}
|
||||
|
||||
func getFreezerPath(c *cgroups.Cgroup) (string, error) {
|
||||
mountpoint, err := cgroups.FindCgroupMountpoint("freezer")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
initPath, err := cgroups.GetInitCgroupDir("freezer")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return filepath.Join(mountpoint, initPath, fmt.Sprintf("%s-%s", c.Parent, c.Name)), nil
|
||||
|
||||
}
|
||||
|
||||
func Freeze(c *cgroups.Cgroup, state cgroups.FreezerState) error {
|
||||
path, err := getFreezerPath(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(filepath.Join(path, "freezer.state"), []byte(state), 0)
|
||||
}
|
||||
|
||||
func GetPids(c *cgroups.Cgroup) ([]int, error) {
|
||||
unitName := getUnitName(c)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue