Skip to content

cgroup2: v2 subsystems should not call WriteCgroupProc() #2157

@AkihiroSuda

Description

@AkihiroSuda

func (s *CpuGroupV2) ApplyDir(path string, cgroup *configs.Cgroup, pid int) error {
// This might happen if we have no cpu cgroup mounted.
// Just do nothing and don't fail.
if path == "" {
return nil
}
if err := os.MkdirAll(path, 0755); err != nil {
return err
}
return cgroups.WriteCgroupProc(path, pid)
}

v2 subsystems should not call WriteCgroupProc(), because it should be managed by Manager rather than each of subsystems for unified mode

#2148 (comment)

The subsystem interface should be modified like this:

diff --git a/libcontainer/cgroups/fs/apply_raw.go b/libcontainer/cgroups/fs/apply_raw.go
index 512fd700..66ab43ec 100644
--- a/libcontainer/cgroups/fs/apply_raw.go
+++ b/libcontainer/cgroups/fs/apply_raw.go
@@ -58,20 +58,24 @@ func (s subsystemSet) Get(name string) (subsystem, error) {
 }
 
 type subsystem interface {
        // Name returns the name of the subsystem.
        Name() string
        // Returns the stats, as 'stats', corresponding to the cgroup under 'path'.
        GetStats(path string, stats *cgroups.Stats) error
+       // Set the cgroup represented by cgroup.
+       Set(path string, cgroup *configs.Cgroup) error
+}
+
+type subsystemV1 interface {
+       subsystem
        // Removes the cgroup represented by 'cgroupData'.
        Remove(*cgroupData) error
        // Creates and joins the cgroup represented by 'cgroupData'.
        Apply(*cgroupData) error
-       // Set the cgroup represented by cgroup.
-       Set(path string, cgroup *configs.Cgroup) error
 }
 
 type Manager struct {
        mu       sync.Mutex
        Cgroups  *configs.Cgroup
        Rootless bool // ignore permission-related errors
        Paths    map[string]string

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions