Skip to content

Commit 8fa6424

Browse files
authored
Merge pull request #296 from singholt/main
cgroup1 delete: proceed to the next subsystem when a cgroup is not found
2 parents f4638b4 + 280dc07 commit 8fa6424

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

cgroup1/cgroup.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func New(path Path, resources *specs.LinuxResources, opts ...InitOpts) (Cgroup,
4141
return nil, err
4242
}
4343
}
44-
subsystems, err := config.hiearchy()
44+
subsystems, err := config.hierarchy()
4545
if err != nil {
4646
return nil, err
4747
}
@@ -79,7 +79,7 @@ func Load(path Path, opts ...InitOpts) (Cgroup, error) {
7979
}
8080
}
8181
var activeSubsystems []Subsystem
82-
subsystems, err := config.hiearchy()
82+
subsystems, err := config.hierarchy()
8383
if err != nil {
8484
return nil, err
8585
}
@@ -259,6 +259,10 @@ func (c *cgroup) Delete() error {
259259
// kernel prevents cgroups with running process from being removed, check the tree is empty
260260
procs, err := c.processes(s.Name(), true, cgroupProcs)
261261
if err != nil {
262+
// if the control group does not exist within a subsystem, then proceed to the next subsystem
263+
if errors.Is(err, os.ErrNotExist) {
264+
continue
265+
}
262266
return err
263267
}
264268
if len(procs) > 0 {

cgroup1/cgroup_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,13 @@ func TestDelete(t *testing.T) {
459459
t.Error(err)
460460
return
461461
}
462+
463+
err = mock.symLink()
464+
if err != nil {
465+
t.Error(err)
466+
return
467+
}
468+
462469
if err := control.Delete(); err != nil {
463470
t.Error(err)
464471
}

cgroup1/mock_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,21 @@ func (m *mockCgroup) delete() error {
7373
func (m *mockCgroup) hierarchy() ([]Subsystem, error) {
7474
return m.subsystems, nil
7575
}
76+
77+
// symLink() creates a symlink between net_cls and net_prio for testing
78+
// On certain Linux systems, there's a symlink from both net_cls and net_prio to "net_cls,net_prio"
79+
// Since we don't have a subsystem defined for "net_cls,net_prio",
80+
// we mock this behavior by creating a symlink directly between net_cls and net_prio
81+
func (m *mockCgroup) symLink() error {
82+
netCLS := filepath.Join(m.root, string(NetCLS))
83+
netPrio := filepath.Join(m.root, string(NetPrio))
84+
// remove netCLS before creating a symlink
85+
if err := os.RemoveAll(netCLS); err != nil {
86+
return err
87+
}
88+
// create symlink between net_cls and net_prio
89+
if err := os.Symlink(netPrio, netCLS); err != nil {
90+
return err
91+
}
92+
return nil
93+
}

cgroup1/opts.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ type InitOpts func(*InitConfig) error
3636
type InitConfig struct {
3737
// InitCheck can be used to check initialization errors from the subsystem
3838
InitCheck InitCheck
39-
hiearchy Hierarchy
39+
hierarchy Hierarchy
4040
}
4141

4242
func newInitConfig() *InitConfig {
4343
return &InitConfig{
4444
InitCheck: RequireDevices,
45-
hiearchy: Default,
45+
hierarchy: Default,
4646
}
4747
}
4848

@@ -66,7 +66,7 @@ func RequireDevices(s Subsystem, _ Path, _ error) error {
6666
// The default list is coming from /proc/self/mountinfo.
6767
func WithHiearchy(h Hierarchy) InitOpts {
6868
return func(c *InitConfig) error {
69-
c.hiearchy = h
69+
c.hierarchy = h
7070
return nil
7171
}
7272
}

cgroup1/v1.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func Default() ([]Subsystem, error) {
4545
}
4646

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

0 commit comments

Comments
 (0)