diff --git a/libcontainer/cgroups/fs/io_v2.go b/libcontainer/cgroups/fs/io_v2.go index 35cda0876..477f7325b 100644 --- a/libcontainer/cgroups/fs/io_v2.go +++ b/libcontainer/cgroups/fs/io_v2.go @@ -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) { diff --git a/libcontainer/cgroups/utils.go b/libcontainer/cgroups/utils.go index 67b40c72d..dbcc58f5b 100644 --- a/libcontainer/cgroups/utils.go +++ b/libcontainer/cgroups/utils.go @@ -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