Make more cgroup controllers optional

Mark all noop cgroups as optional, after all there is no harm in skipping them.
Make pids cgroup optional because they are not present on Synology NAS.

Closes #6856

PiperOrigin-RevId: 409197613
This commit is contained in:
Fabricio Voznika
2021-11-11 11:24:50 -08:00
committed by gVisor bot
parent 1d536f8139
commit 83eb263b45
2 changed files with 20 additions and 10 deletions
+14 -10
View File
@@ -57,7 +57,7 @@ var controllers = map[string]controller{
"devices": &noop{},
"freezer": &noop{},
"perf_event": &noop{},
"rdma": &noop{isOptional: true},
"rdma": &noop{},
"systemd": &noop{},
}
@@ -599,12 +599,10 @@ type controller interface {
skip(*specs.LinuxResources) error
}
type noop struct {
isOptional bool
}
type noop struct{}
func (n *noop) optional() bool {
return n.isOptional
return true
}
func (*noop) set(*specs.LinuxResources, string) error {
@@ -612,9 +610,6 @@ func (*noop) set(*specs.LinuxResources, string) error {
}
func (n *noop) skip(*specs.LinuxResources) error {
if !n.isOptional {
panic("cgroup controller is not optional")
}
return nil
}
@@ -808,8 +803,17 @@ func (*networkPrio) skip(spec *specs.LinuxResources) error {
return nil
}
type pids struct {
mandatory
type pids struct{}
func (*pids) optional() bool {
return true
}
func (*pids) skip(spec *specs.LinuxResources) error {
if spec != nil && spec.Pids != nil && spec.Pids.Limit > 0 {
return fmt.Errorf("Pids.Limit set but pids cgroup controller not found")
}
return nil
}
func (*pids) set(spec *specs.LinuxResources, path string) error {
+6
View File
@@ -863,6 +863,12 @@ func TestOptional(t *testing.T) {
spec *specs.LinuxResources
err string
}{
{
name: "pids",
ctrlr: &pids{},
spec: &specs.LinuxResources{Pids: &specs.LinuxPids{Limit: 1}},
err: "Pids.Limit set but pids cgroup controller not found",
},
{
name: "net-cls",
ctrlr: &networkClass{},