From e6e2d73eacff8a0b4c6f4cbb9bee5113dcebc282 Mon Sep 17 00:00:00 2001 From: Derek Ray Date: Wed, 11 Oct 2023 10:53:10 +0800 Subject: [PATCH] feat(cgroup1): skip cgroup1 update operation if not configured in LinuxResources Signed-off-by: Derek Ray --- cgroup1/blkio.go | 4 ++++ cgroup1/cpu.go | 4 ++++ cgroup1/cpuset.go | 4 ++++ cgroup1/devices.go | 4 ++++ cgroup1/memory.go | 3 ++- cgroup1/net_cls.go | 4 ++++ cgroup1/pids.go | 4 ++++ cgroup1/rdma.go | 4 ++++ 8 files changed, 30 insertions(+), 1 deletion(-) diff --git a/cgroup1/blkio.go b/cgroup1/blkio.go index 3be884c7..bf4d57c6 100644 --- a/cgroup1/blkio.go +++ b/cgroup1/blkio.go @@ -85,6 +85,10 @@ func (b *blkioController) Create(path string, resources *specs.LinuxResources) e } func (b *blkioController) Update(path string, resources *specs.LinuxResources) error { + if resources == nil || resources.BlockIO == nil { + return nil + } + return b.Create(path, resources) } diff --git a/cgroup1/cpu.go b/cgroup1/cpu.go index e02ca0d8..e6b016ef 100644 --- a/cgroup1/cpu.go +++ b/cgroup1/cpu.go @@ -96,6 +96,10 @@ func (c *cpuController) Create(path string, resources *specs.LinuxResources) err } func (c *cpuController) Update(path string, resources *specs.LinuxResources) error { + if resources == nil || resources.CPU == nil || (resources.CPU.Shares == nil && resources.CPU.Period == nil && resources.CPU.Quota == nil) { + return nil + } + return c.Create(path, resources) } diff --git a/cgroup1/cpuset.go b/cgroup1/cpuset.go index 8338b6a1..cbe44d1a 100644 --- a/cgroup1/cpuset.go +++ b/cgroup1/cpuset.go @@ -82,6 +82,10 @@ func (c *cpusetController) Create(path string, resources *specs.LinuxResources) } func (c *cpusetController) Update(path string, resources *specs.LinuxResources) error { + if resources == nil || resources.CPU == nil || (resources.CPU.Cpus == "" && resources.CPU.Mems == "") { + return nil + } + return c.Create(path, resources) } diff --git a/cgroup1/devices.go b/cgroup1/devices.go index 80d76fa3..5b669581 100644 --- a/cgroup1/devices.go +++ b/cgroup1/devices.go @@ -72,6 +72,10 @@ func (d *devicesController) Create(path string, resources *specs.LinuxResources) } func (d *devicesController) Update(path string, resources *specs.LinuxResources) error { + if resources == nil || resources.Devices == nil { + return nil + } + return d.Create(path, resources) } diff --git a/cgroup1/memory.go b/cgroup1/memory.go index dbf49b5d..936ae348 100644 --- a/cgroup1/memory.go +++ b/cgroup1/memory.go @@ -210,9 +210,10 @@ func (m *memoryController) Create(path string, resources *specs.LinuxResources) } func (m *memoryController) Update(path string, resources *specs.LinuxResources) error { - if resources.Memory == nil { + if resources == nil || resources.Memory == nil { return nil } + g := func(v *int64) bool { return v != nil && *v > 0 } diff --git a/cgroup1/net_cls.go b/cgroup1/net_cls.go index 22b3c95b..1e66f6d6 100644 --- a/cgroup1/net_cls.go +++ b/cgroup1/net_cls.go @@ -57,5 +57,9 @@ func (n *netclsController) Create(path string, resources *specs.LinuxResources) } func (n *netclsController) Update(path string, resources *specs.LinuxResources) error { + if resources == nil || resources.Network == nil { + return nil + } + return n.Create(path, resources) } diff --git a/cgroup1/pids.go b/cgroup1/pids.go index 25421a21..20e107ae 100644 --- a/cgroup1/pids.go +++ b/cgroup1/pids.go @@ -59,6 +59,10 @@ func (p *pidsController) Create(path string, resources *specs.LinuxResources) er } func (p *pidsController) Update(path string, resources *specs.LinuxResources) error { + if resources == nil || resources.Pids == nil { + return nil + } + return p.Create(path, resources) } diff --git a/cgroup1/rdma.go b/cgroup1/rdma.go index 2492ac72..de46e57a 100644 --- a/cgroup1/rdma.go +++ b/cgroup1/rdma.go @@ -78,6 +78,10 @@ func (p *rdmaController) Create(path string, resources *specs.LinuxResources) er } func (p *rdmaController) Update(path string, resources *specs.LinuxResources) error { + if resources == nil || resources.Rdma == nil { + return nil + } + return p.Create(path, resources) }