Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgroup1 delete: proceed to the next subsystem when a cgroup is not found #296

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions cgroup1/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func New(path Path, resources *specs.LinuxResources, opts ...InitOpts) (Cgroup,
return nil, err
}
}
subsystems, err := config.hiearchy()
subsystems, err := config.hierarchy()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func Load(path Path, opts ...InitOpts) (Cgroup, error) {
}
}
var activeSubsystems []Subsystem
subsystems, err := config.hiearchy()
subsystems, err := config.hierarchy()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -259,6 +259,10 @@ func (c *cgroup) Delete() error {
// kernel prevents cgroups with running process from being removed, check the tree is empty
procs, err := c.processes(s.Name(), true, cgroupProcs)
if err != nil {
// if the control group does not exist within a subsystem, then proceed to the next subsystem
if errors.Is(err, os.ErrNotExist) {
continue
}
return err
}
if len(procs) > 0 {
Expand Down
7 changes: 7 additions & 0 deletions cgroup1/cgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,13 @@ func TestDelete(t *testing.T) {
t.Error(err)
return
}

err = mock.symLink()
if err != nil {
t.Error(err)
return
}

if err := control.Delete(); err != nil {
t.Error(err)
}
Expand Down
18 changes: 18 additions & 0 deletions cgroup1/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,21 @@ func (m *mockCgroup) delete() error {
func (m *mockCgroup) hierarchy() ([]Subsystem, error) {
return m.subsystems, nil
}

// symLink() creates a symlink between net_cls and net_prio for testing
// On certain Linux systems, there's a symlink from both net_cls and net_prio to "net_cls,net_prio"
// Since we don't have a subsystem defined for "net_cls,net_prio",
// we mock this behavior by creating a symlink directly between net_cls and net_prio
func (m *mockCgroup) symLink() error {
netCLS := filepath.Join(m.root, string(NetCLS))
netPrio := filepath.Join(m.root, string(NetPrio))
// remove netCLS before creating a symlink
if err := os.RemoveAll(netCLS); err != nil {
return err
}
// create symlink between net_cls and net_prio
if err := os.Symlink(netPrio, netCLS); err != nil {
return err
}
return nil
}
6 changes: 3 additions & 3 deletions cgroup1/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ type InitOpts func(*InitConfig) error
type InitConfig struct {
// InitCheck can be used to check initialization errors from the subsystem
InitCheck InitCheck
hiearchy Hierarchy
hierarchy Hierarchy
}

func newInitConfig() *InitConfig {
return &InitConfig{
InitCheck: RequireDevices,
hiearchy: Default,
hierarchy: Default,
}
}

Expand All @@ -66,7 +66,7 @@ func RequireDevices(s Subsystem, _ Path, _ error) error {
// The default list is coming from /proc/self/mountinfo.
func WithHiearchy(h Hierarchy) InitOpts {
return func(c *InitConfig) error {
c.hiearchy = h
c.hierarchy = h
return nil
}
}
2 changes: 1 addition & 1 deletion cgroup1/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Default() ([]Subsystem, error) {
}

// v1MountPoint returns the mount point where the cgroup
// mountpoints are mounted in a single hiearchy
// mountpoints are mounted in a single hierarchy
func v1MountPoint() (string, error) {
f, err := os.Open("/proc/self/mountinfo")
if err != nil {
Expand Down