Skip to content

Commit 2a7fc75

Browse files
committed
common: controllerHandler.Apply replaced by fs2.NewManager
The Update() function previously iterated through handlers calling their Apply() methods. With cgroups v1 removed, all handlers' Apply() implementations were identical - they all called fs2.NewManager().Set(). This commit removes the redundant handler Apply() methods and has Update() call fs2.NewManager().Set() directly. The Update() method now performs the same function more efficiently without the handler indirection. Signed-off-by: Lokesh Mandvekar <[email protected]>
1 parent ddcc4e0 commit 2a7fc75

File tree

6 files changed

+5
-60
lines changed

6 files changed

+5
-60
lines changed

common/pkg/cgroups/blkio_linux.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
package cgroups
44

55
import (
6-
"path/filepath"
76
"strconv"
87
"strings"
98

109
"github.com/opencontainers/cgroups"
1110
"github.com/opencontainers/cgroups/fs"
12-
"github.com/opencontainers/cgroups/fs2"
1311
)
1412

1513
type linuxBlkioHandler struct {
@@ -20,15 +18,6 @@ func getBlkioHandler() *linuxBlkioHandler {
2018
return &linuxBlkioHandler{}
2119
}
2220

23-
// Apply set the specified constraints.
24-
func (c *linuxBlkioHandler) Apply(ctr *CgroupControl, res *cgroups.Resources) error {
25-
man, err := fs2.NewManager(ctr.config, filepath.Join(cgroupRoot, ctr.config.Path))
26-
if err != nil {
27-
return err
28-
}
29-
return man.Set(res)
30-
}
31-
3221
// Stat fills a metrics structure with usage stats for the controller.
3322
func (c *linuxBlkioHandler) Stat(ctr *CgroupControl, m *cgroups.Stats) error {
3423
var ioServiceBytesRecursive []cgroups.BlkioStatEntry

common/pkg/cgroups/cgroups_linux.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
systemdDbus "github.com/coreos/go-systemd/v22/dbus"
2121
"github.com/godbus/dbus/v5"
2222
"github.com/opencontainers/cgroups"
23+
"github.com/opencontainers/cgroups/fs2"
2324
"go.podman.io/storage/pkg/fileutils"
2425
"go.podman.io/storage/pkg/unshare"
2526
"golang.org/x/sys/unix"
@@ -42,7 +43,6 @@ type CgroupControl struct {
4243
}
4344

4445
type controllerHandler interface {
45-
Apply(*CgroupControl, *cgroups.Resources) error
4646
Stat(*CgroupControl, *cgroups.Stats) error
4747
}
4848

@@ -306,12 +306,11 @@ func (c *CgroupControl) DeleteByPath(path string) error {
306306

307307
// Update updates the cgroups.
308308
func (c *CgroupControl) Update(resources *cgroups.Resources) error {
309-
for _, h := range handlers {
310-
if err := h.Apply(c, resources); err != nil {
311-
return err
312-
}
309+
man, err := fs2.NewManager(c.config, filepath.Join(cgroupRoot, c.config.Path))
310+
if err != nil {
311+
return err
313312
}
314-
return nil
313+
return man.Set(resources)
315314
}
316315

317316
// Stat returns usage statistics for the cgroup.

common/pkg/cgroups/cpu_linux.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
package cgroups
44

55
import (
6-
"path/filepath"
76
"strconv"
87

98
"github.com/opencontainers/cgroups"
109
"github.com/opencontainers/cgroups/fs"
11-
"github.com/opencontainers/cgroups/fs2"
1210
)
1311

1412
type linuxCPUHandler struct {
@@ -19,15 +17,6 @@ func getCPUHandler() *linuxCPUHandler {
1917
return &linuxCPUHandler{}
2018
}
2119

22-
// Apply set the specified constraints.
23-
func (c *linuxCPUHandler) Apply(ctr *CgroupControl, res *cgroups.Resources) error {
24-
man, err := fs2.NewManager(ctr.config, filepath.Join(cgroupRoot, ctr.config.Path))
25-
if err != nil {
26-
return err
27-
}
28-
return man.Set(res)
29-
}
30-
3120
// Stat fills a metrics structure with usage stats for the controller.
3221
func (c *linuxCPUHandler) Stat(ctr *CgroupControl, m *cgroups.Stats) error {
3322
cpu := cgroups.CpuStats{}

common/pkg/cgroups/cpuset_linux.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
package cgroups
44

55
import (
6-
"path/filepath"
7-
86
"github.com/opencontainers/cgroups"
97
"github.com/opencontainers/cgroups/fs"
10-
"github.com/opencontainers/cgroups/fs2"
118
)
129

1310
type linuxCpusetHandler struct {
@@ -18,15 +15,6 @@ func getCpusetHandler() *linuxCpusetHandler {
1815
return &linuxCpusetHandler{}
1916
}
2017

21-
// Apply set the specified constraints.
22-
func (c *linuxCpusetHandler) Apply(ctr *CgroupControl, res *cgroups.Resources) error {
23-
man, err := fs2.NewManager(ctr.config, filepath.Join(cgroupRoot, ctr.config.Path))
24-
if err != nil {
25-
return err
26-
}
27-
return man.Set(res)
28-
}
29-
3018
// Stat fills a metrics structure with usage stats for the controller.
3119
func (c *linuxCpusetHandler) Stat(_ *CgroupControl, _ *cgroups.Stats) error {
3220
return nil

common/pkg/cgroups/memory_linux.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/opencontainers/cgroups"
99
"github.com/opencontainers/cgroups/fs"
10-
"github.com/opencontainers/cgroups/fs2"
1110
)
1211

1312
type linuxMemHandler struct {
@@ -18,15 +17,6 @@ func getMemoryHandler() *linuxMemHandler {
1817
return &linuxMemHandler{}
1918
}
2019

21-
// Apply set the specified constraints.
22-
func (c *linuxMemHandler) Apply(ctr *CgroupControl, res *cgroups.Resources) error {
23-
man, err := fs2.NewManager(ctr.config, filepath.Join(cgroupRoot, ctr.config.Path))
24-
if err != nil {
25-
return err
26-
}
27-
return man.Set(res)
28-
}
29-
3020
// Stat fills a metrics structure with usage stats for the controller.
3121
func (c *linuxMemHandler) Stat(ctr *CgroupControl, m *cgroups.Stats) error {
3222
var err error

common/pkg/cgroups/pids_linux.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/opencontainers/cgroups"
99
"github.com/opencontainers/cgroups/fs"
10-
"github.com/opencontainers/cgroups/fs2"
1110
)
1211

1312
type linuxPidHandler struct {
@@ -18,15 +17,6 @@ func getPidsHandler() *linuxPidHandler {
1817
return &linuxPidHandler{}
1918
}
2019

21-
// Apply set the specified constraints.
22-
func (c *linuxPidHandler) Apply(ctr *CgroupControl, res *cgroups.Resources) error {
23-
man, err := fs2.NewManager(ctr.config, filepath.Join(cgroupRoot, ctr.config.Path))
24-
if err != nil {
25-
return err
26-
}
27-
return man.Set(res)
28-
}
29-
3020
// Stat fills a metrics structure with usage stats for the controller.
3121
func (c *linuxPidHandler) Stat(ctr *CgroupControl, m *cgroups.Stats) error {
3222
if ctr.config.Path == "" {

0 commit comments

Comments
 (0)