Merge pull request #2160 from AkihiroSuda/cgroup2-no-proc-cgroups
cgroup2: do not parse /proc/cgroups
This commit is contained in:
commit
f04fb9980c
|
@ -17,12 +17,11 @@ type IOGroupV2 struct {
|
|||
}
|
||||
|
||||
func (s *IOGroupV2) Name() string {
|
||||
// for compatibility with v1 blkio controller
|
||||
return "blkio"
|
||||
return "io"
|
||||
}
|
||||
|
||||
func (s *IOGroupV2) Apply(d *cgroupData) error {
|
||||
_, err := d.join("blkio")
|
||||
_, err := d.join("io")
|
||||
if err != nil && !cgroups.IsNotFound(err) {
|
||||
return err
|
||||
}
|
||||
|
@ -62,7 +61,7 @@ func (s *IOGroupV2) Set(path string, cgroup *configs.Cgroup) error {
|
|||
}
|
||||
|
||||
func (s *IOGroupV2) Remove(d *cgroupData) error {
|
||||
return removePath(d.path("blkio"))
|
||||
return removePath(d.path("io"))
|
||||
}
|
||||
|
||||
func readCgroup2MapFile(path string, name string) (map[string][]string, error) {
|
||||
|
|
|
@ -266,6 +266,21 @@ func GetCgroupMounts(all bool) ([]Mount, error) {
|
|||
|
||||
// GetAllSubsystems returns all the cgroup subsystems supported by the kernel
|
||||
func GetAllSubsystems() ([]string, error) {
|
||||
// /proc/cgroups is meaningless for v2
|
||||
// https://github.com/torvalds/linux/blob/v5.3/Documentation/admin-guide/cgroup-v2.rst#deprecated-v1-core-features
|
||||
if IsCgroup2UnifiedMode() {
|
||||
// "pseudo" controllers do not appear in /sys/fs/cgroup/cgroup.controllers.
|
||||
// - devices: implemented in kernel 4.15
|
||||
// - freezer: implemented in kernel 5.2
|
||||
// We assume these are always available, as it is hard to detect availability.
|
||||
pseudo := []string{"devices", "freezer"}
|
||||
data, err := ioutil.ReadFile("/sys/fs/cgroup/cgroup.controllers")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
subsystems := append(pseudo, strings.Fields(string(data))...)
|
||||
return subsystems, nil
|
||||
}
|
||||
f, err := os.Open("/proc/cgroups")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
Loading…
Reference in New Issue