mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-12 09:46:25 +08:00
f36ed4b174
Apply and Set are two separate operations, and it doesn't make sense to group the two together (especially considering that the bootstrap process is added to the cgroup as well). The only exception to this is the memory cgroup, which requires the configuration to be set before processes can join. One of the weird cases to deal with is systemd. Systemd sets some of the cgroup configuration options, but not all of them. Because memory is a special case, we need to explicitly set memory in the systemd Apply(). Otherwise, the rest can be safely re-applied in .Set() as usual. Signed-off-by: Aleksa Sarai <asarai@suse.com>
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
// +build linux
|
|
|
|
package fs
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
|
)
|
|
|
|
type FreezerGroup struct {
|
|
}
|
|
|
|
func (s *FreezerGroup) Name() string {
|
|
return "freezer"
|
|
}
|
|
|
|
func (s *FreezerGroup) Apply(d *cgroupData) error {
|
|
_, err := d.join("freezer")
|
|
if err != nil && !cgroups.IsNotFound(err) {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *FreezerGroup) Set(path string, cgroup *configs.Cgroup) error {
|
|
switch cgroup.Resources.Freezer {
|
|
case configs.Frozen, configs.Thawed:
|
|
if err := writeFile(path, "freezer.state", string(cgroup.Resources.Freezer)); err != nil {
|
|
return err
|
|
}
|
|
|
|
for {
|
|
state, err := readFile(path, "freezer.state")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if strings.TrimSpace(state) == string(cgroup.Resources.Freezer) {
|
|
break
|
|
}
|
|
time.Sleep(1 * time.Millisecond)
|
|
}
|
|
case configs.Undefined:
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("Invalid argument '%s' to freezer.state", string(cgroup.Resources.Freezer))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *FreezerGroup) Remove(d *cgroupData) error {
|
|
return removePath(d.path("freezer"))
|
|
}
|
|
|
|
func (s *FreezerGroup) GetStats(path string, stats *cgroups.Stats) error {
|
|
return nil
|
|
}
|