Skip to content

Commit fcafd25

Browse files
committed
common: remove Cgroups v1 support
Removes all conditionals for IsCgroup2UnifiedMode and cgroupv2.Enabled and assumes Cgroups v2. Also removes `cgroup2` and `additionalControllers` from CgroupControl struct and all the conditionals resulting from it. pkg/cgroups.IsCgroup2UnifiedMode is being retained as it will be used in the dependent tools as a single check for v1/v2. Fixes: RUN-3567 (partly) Signed-off-by: Lokesh Mandvekar <[email protected]>
1 parent 26b2444 commit fcafd25

File tree

13 files changed

+121
-583
lines changed

13 files changed

+121
-583
lines changed

common/pkg/cgroups/blkio_linux.go

Lines changed: 30 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
package cgroups
44

55
import (
6-
"bufio"
7-
"errors"
8-
"fmt"
9-
"os"
106
"path/filepath"
117
"strconv"
128
"strings"
@@ -26,23 +22,16 @@ func getBlkioHandler() *linuxBlkioHandler {
2622

2723
// Apply set the specified constraints.
2824
func (c *linuxBlkioHandler) Apply(ctr *CgroupControl, res *cgroups.Resources) error {
29-
if ctr.cgroup2 {
30-
man, err := fs2.NewManager(ctr.config, filepath.Join(cgroupRoot, ctr.config.Path))
31-
if err != nil {
32-
return err
33-
}
34-
return man.Set(res)
25+
man, err := fs2.NewManager(ctr.config, filepath.Join(cgroupRoot, ctr.config.Path))
26+
if err != nil {
27+
return err
3528
}
36-
path := filepath.Join(cgroupRoot, Blkio, ctr.config.Path)
37-
return c.Blkio.Set(path, res)
29+
return man.Set(res)
3830
}
3931

4032
// Create the cgroup.
4133
func (c *linuxBlkioHandler) Create(ctr *CgroupControl) (bool, error) {
42-
if ctr.cgroup2 {
43-
return false, nil
44-
}
45-
return ctr.createCgroupDirectory(Blkio)
34+
return false, nil
4635
}
4736

4837
// Destroy the cgroup.
@@ -54,94 +43,45 @@ func (c *linuxBlkioHandler) Destroy(ctr *CgroupControl) error {
5443
func (c *linuxBlkioHandler) Stat(ctr *CgroupControl, m *cgroups.Stats) error {
5544
var ioServiceBytesRecursive []cgroups.BlkioStatEntry
5645

57-
if ctr.cgroup2 {
58-
// more details on the io.stat file format:X https://facebookmicrosites.github.io/cgroup2/docs/io-controller.html
59-
values, err := readCgroup2MapFile(ctr, "io.stat")
46+
// more details on the io.stat file format:X https://facebookmicrosites.github.io/cgroup2/docs/io-controller.html
47+
values, err := readCgroup2MapFile(ctr, "io.stat")
48+
if err != nil {
49+
return err
50+
}
51+
for k, v := range values {
52+
d := strings.Split(k, ":")
53+
if len(d) != 2 {
54+
continue
55+
}
56+
minor, err := strconv.ParseUint(d[0], 10, 0)
6057
if err != nil {
6158
return err
6259
}
63-
for k, v := range values {
64-
d := strings.Split(k, ":")
65-
if len(d) != 2 {
66-
continue
67-
}
68-
minor, err := strconv.ParseUint(d[0], 10, 0)
69-
if err != nil {
70-
return err
71-
}
72-
major, err := strconv.ParseUint(d[1], 10, 0)
73-
if err != nil {
74-
return err
75-
}
76-
77-
for _, item := range v {
78-
d := strings.Split(item, "=")
79-
if len(d) != 2 {
80-
continue
81-
}
82-
op := d[0]
83-
84-
// Accommodate the cgroup v1 naming
85-
switch op {
86-
case "rbytes":
87-
op = "read"
88-
case "wbytes":
89-
op = "write"
90-
}
91-
92-
value, err := strconv.ParseUint(d[1], 10, 0)
93-
if err != nil {
94-
return err
95-
}
96-
97-
entry := cgroups.BlkioStatEntry{
98-
Op: op,
99-
Major: major,
100-
Minor: minor,
101-
Value: value,
102-
}
103-
ioServiceBytesRecursive = append(ioServiceBytesRecursive, entry)
104-
}
105-
}
106-
} else {
107-
BlkioRoot := ctr.getCgroupv1Path(Blkio)
108-
109-
p := filepath.Join(BlkioRoot, "blkio.throttle.io_service_bytes_recursive")
110-
f, err := os.Open(p)
60+
major, err := strconv.ParseUint(d[1], 10, 0)
11161
if err != nil {
112-
if errors.Is(err, os.ErrNotExist) {
113-
return nil
114-
}
115-
return fmt.Errorf("open %s: %w", p, err)
62+
return err
11663
}
117-
defer f.Close()
11864

119-
scanner := bufio.NewScanner(f)
120-
for scanner.Scan() {
121-
line := scanner.Text()
122-
parts := strings.Fields(line)
123-
if len(parts) < 3 {
124-
continue
125-
}
126-
d := strings.Split(parts[0], ":")
65+
for _, item := range v {
66+
d := strings.Split(item, "=")
12767
if len(d) != 2 {
12868
continue
12969
}
130-
minor, err := strconv.ParseUint(d[0], 10, 0)
131-
if err != nil {
132-
return err
133-
}
134-
major, err := strconv.ParseUint(d[1], 10, 0)
135-
if err != nil {
136-
return err
70+
op := d[0]
71+
72+
// Accommodate the cgroup v1 naming
73+
switch op {
74+
case "rbytes":
75+
op = "read"
76+
case "wbytes":
77+
op = "write"
13778
}
13879

139-
op := parts[1]
140-
141-
value, err := strconv.ParseUint(parts[2], 10, 0)
80+
value, err := strconv.ParseUint(d[1], 10, 0)
14281
if err != nil {
14382
return err
14483
}
84+
14585
entry := cgroups.BlkioStatEntry{
14686
Op: op,
14787
Major: major,
@@ -150,9 +90,6 @@ func (c *linuxBlkioHandler) Stat(ctr *CgroupControl, m *cgroups.Stats) error {
15090
}
15191
ioServiceBytesRecursive = append(ioServiceBytesRecursive, entry)
15292
}
153-
if err := scanner.Err(); err != nil {
154-
return fmt.Errorf("parse %s: %w", p, err)
155-
}
15693
}
15794
m.BlkioStats.IoServiceBytesRecursive = ioServiceBytesRecursive
15895
return nil

0 commit comments

Comments
 (0)