From 83eb263b454882a20e4a8920ac2e082cf9d78001 Mon Sep 17 00:00:00 2001 From: Fabricio Voznika Date: Thu, 11 Nov 2021 11:22:03 -0800 Subject: [PATCH] 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 --- runsc/cgroup/cgroup.go | 24 ++++++++++++++---------- runsc/cgroup/cgroup_test.go | 6 ++++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/runsc/cgroup/cgroup.go b/runsc/cgroup/cgroup.go index 0eb5821a9..df1fc03cb 100644 --- a/runsc/cgroup/cgroup.go +++ b/runsc/cgroup/cgroup.go @@ -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 { diff --git a/runsc/cgroup/cgroup_test.go b/runsc/cgroup/cgroup_test.go index 1447078a0..abd10756b 100644 --- a/runsc/cgroup/cgroup_test.go +++ b/runsc/cgroup/cgroup_test.go @@ -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{},