Skip to content

Commit 04041f2

Browse files
committed
libct/cgroups/*: switch from configs to cgroups
Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent ae477f1 commit 04041f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+240
-282
lines changed

libcontainer/cgroups/devices/systemd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import (
1111
"github.com/godbus/dbus/v5"
1212
"github.com/sirupsen/logrus"
1313

14-
"github.com/opencontainers/runc/libcontainer/configs"
14+
"github.com/opencontainers/runc/libcontainer/cgroups"
1515
"github.com/opencontainers/runc/libcontainer/devices"
1616
)
1717

1818
// systemdProperties takes the configured device rules and generates a
1919
// corresponding set of systemd properties to configure the devices correctly.
20-
func systemdProperties(r *configs.Resources, sdVer int) ([]systemdDbus.Property, error) {
20+
func systemdProperties(r *cgroups.Resources, sdVer int) ([]systemdDbus.Property, error) {
2121
if r.SkipDevices {
2222
return nil, nil
2323
}

libcontainer/cgroups/devices/systemd_test.go

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

1111
"github.com/opencontainers/runc/libcontainer/cgroups"
1212
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
13-
"github.com/opencontainers/runc/libcontainer/configs"
1413
"github.com/opencontainers/runc/libcontainer/devices"
1514
)
1615

@@ -28,11 +27,11 @@ func TestPodSkipDevicesUpdate(t *testing.T) {
2827
}
2928

3029
podName := "system-runc_test_pod" + t.Name() + ".slice"
31-
podConfig := &configs.Cgroup{
30+
podConfig := &cgroups.Cgroup{
3231
Systemd: true,
3332
Parent: "system.slice",
3433
Name: podName,
35-
Resources: &configs.Resources{
34+
Resources: &cgroups.Resources{
3635
PidsLimit: 42,
3736
Memory: 32 * 1024 * 1024,
3837
SkipDevices: true,
@@ -47,11 +46,11 @@ func TestPodSkipDevicesUpdate(t *testing.T) {
4746
t.Fatal(err)
4847
}
4948

50-
containerConfig := &configs.Cgroup{
49+
containerConfig := &cgroups.Cgroup{
5150
Parent: podName,
5251
ScopePrefix: "test",
5352
Name: "PodSkipDevicesUpdate",
54-
Resources: &configs.Resources{
53+
Resources: &cgroups.Resources{
5554
Devices: []*devices.Rule{
5655
// Allow access to /dev/null.
5756
{
@@ -124,10 +123,10 @@ func testSkipDevices(t *testing.T, skipDevices bool, expected []string) {
124123
t.Skip("Test requires root.")
125124
}
126125

127-
podConfig := &configs.Cgroup{
126+
podConfig := &cgroups.Cgroup{
128127
Parent: "system.slice",
129128
Name: "system-runc_test_pods.slice",
130-
Resources: &configs.Resources{
129+
Resources: &cgroups.Resources{
131130
SkipDevices: skipDevices,
132131
},
133132
}
@@ -140,11 +139,11 @@ func testSkipDevices(t *testing.T, skipDevices bool, expected []string) {
140139
t.Fatal(err)
141140
}
142141

143-
config := &configs.Cgroup{
142+
config := &cgroups.Cgroup{
144143
Parent: "system-runc_test_pods.slice",
145144
ScopePrefix: "test",
146145
Name: "SkipDevices",
147-
Resources: &configs.Resources{
146+
Resources: &cgroups.Resources{
148147
Devices: []*devices.Rule{
149148
// Allow access to /dev/full only.
150149
{
@@ -262,7 +261,7 @@ func BenchmarkFindDeviceGroup(b *testing.B) {
262261
}
263262
}
264263

265-
func newManager(t *testing.T, config *configs.Cgroup) (m cgroups.Manager) {
264+
func newManager(t *testing.T, config *cgroups.Cgroup) (m cgroups.Manager) {
266265
t.Helper()
267266
var err error
268267

libcontainer/cgroups/devices/v1.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import (
77

88
"github.com/moby/sys/userns"
99
"github.com/opencontainers/runc/libcontainer/cgroups"
10-
"github.com/opencontainers/runc/libcontainer/configs"
1110
"github.com/opencontainers/runc/libcontainer/devices"
1211
)
1312

1413
var testingSkipFinalCheck bool
1514

16-
func setV1(path string, r *configs.Resources) error {
15+
func setV1(path string, r *cgroups.Resources) error {
1716
if userns.RunningInUserNS() || r.SkipDevices {
1817
return nil
1918
}

libcontainer/cgroups/devices/v1_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/opencontainers/runc/libcontainer/cgroups"
1111
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
12-
"github.com/opencontainers/runc/libcontainer/configs"
1312
"github.com/opencontainers/runc/libcontainer/devices"
1413
)
1514

@@ -35,7 +34,7 @@ func TestSetV1Allow(t *testing.T) {
3534
}
3635
}
3736

38-
r := &configs.Resources{
37+
r := &cgroups.Resources{
3938
Devices: []*devices.Rule{
4039
{
4140
Type: devices.CharDevice,

libcontainer/cgroups/devices/v2.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/moby/sys/userns"
77
"golang.org/x/sys/unix"
88

9-
"github.com/opencontainers/runc/libcontainer/configs"
9+
"github.com/opencontainers/runc/libcontainer/cgroups"
1010
"github.com/opencontainers/runc/libcontainer/devices"
1111
)
1212

@@ -27,7 +27,7 @@ func isRWM(perms devices.Permissions) bool {
2727

2828
// This is similar to the logic applied in crun for handling errors from bpf(2)
2929
// <https://github.com/containers/crun/blob/0.17/src/libcrun/cgroup.c#L2438-L2470>.
30-
func canSkipEBPFError(r *configs.Resources) bool {
30+
func canSkipEBPFError(r *cgroups.Resources) bool {
3131
// If we're running in a user namespace we can ignore eBPF rules because we
3232
// usually cannot use bpf(2), as well as rootless containers usually don't
3333
// have the necessary privileges to mknod(2) device inodes or access
@@ -51,7 +51,7 @@ func canSkipEBPFError(r *configs.Resources) bool {
5151
return true
5252
}
5353

54-
func setV2(dirPath string, r *configs.Resources) error {
54+
func setV2(dirPath string, r *cgroups.Resources) error {
5555
if r.SkipDevices {
5656
return nil
5757
}

libcontainer/cgroups/fs/blkio.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99

1010
"github.com/opencontainers/runc/libcontainer/cgroups"
11-
"github.com/opencontainers/runc/libcontainer/configs"
1211
)
1312

1413
type BlkioGroup struct {
@@ -20,11 +19,11 @@ func (s *BlkioGroup) Name() string {
2019
return "blkio"
2120
}
2221

23-
func (s *BlkioGroup) Apply(path string, _ *configs.Resources, pid int) error {
22+
func (s *BlkioGroup) Apply(path string, _ *cgroups.Resources, pid int) error {
2423
return apply(path, pid)
2524
}
2625

27-
func (s *BlkioGroup) Set(path string, r *configs.Resources) error {
26+
func (s *BlkioGroup) Set(path string, r *cgroups.Resources) error {
2827
s.detectWeightFilenames(path)
2928
if r.BlkioWeight != 0 {
3029
if err := cgroups.WriteFile(path, s.weightFilename, strconv.FormatUint(uint64(r.BlkioWeight), 10)); err != nil {

libcontainer/cgroups/fs/blkio_test.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/opencontainers/runc/libcontainer/cgroups"
88
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
9-
"github.com/opencontainers/runc/libcontainer/configs"
109
)
1110

1211
const (
@@ -184,7 +183,7 @@ func TestBlkioSetWeight(t *testing.T) {
184183
weightFilename: strconv.Itoa(weightBefore),
185184
})
186185
// Apply new configuration
187-
r := &configs.Resources{
186+
r := &cgroups.Resources{
188187
BlkioWeight: weightAfter,
189188
}
190189
blkio := &BlkioGroup{}
@@ -224,10 +223,10 @@ func TestBlkioSetWeightDevice(t *testing.T) {
224223
weightDeviceFilename: weightDeviceBefore,
225224
})
226225
// Apply new configuration
227-
wd := configs.NewWeightDevice(8, 0, 500, 0)
226+
wd := cgroups.NewWeightDevice(8, 0, 500, 0)
228227
weightDeviceAfter := wd.WeightString()
229-
r := &configs.Resources{
230-
BlkioWeightDevice: []*configs.WeightDevice{wd},
228+
r := &cgroups.Resources{
229+
BlkioWeightDevice: []*cgroups.WeightDevice{wd},
231230
}
232231
blkio := &BlkioGroup{}
233232
if err := blkio.Set(path, r); err != nil {
@@ -255,8 +254,8 @@ func TestBlkioSetMultipleWeightDevice(t *testing.T) {
255254
weightDeviceBefore = "8:0 400"
256255
)
257256

258-
wd1 := configs.NewWeightDevice(8, 0, 500, 0)
259-
wd2 := configs.NewWeightDevice(8, 16, 500, 0)
257+
wd1 := cgroups.NewWeightDevice(8, 0, 500, 0)
258+
wd2 := cgroups.NewWeightDevice(8, 16, 500, 0)
260259
// we cannot actually set and check both because normal os.WriteFile
261260
// when writing to cgroup file will overwrite the whole file content instead
262261
// of updating it as the kernel is doing. Just check the second device
@@ -272,8 +271,8 @@ func TestBlkioSetMultipleWeightDevice(t *testing.T) {
272271
blkio.weightDeviceFilename: weightDeviceBefore,
273272
})
274273

275-
r := &configs.Resources{
276-
BlkioWeightDevice: []*configs.WeightDevice{wd1, wd2},
274+
r := &cgroups.Resources{
275+
BlkioWeightDevice: []*cgroups.WeightDevice{wd1, wd2},
277276
}
278277
if err := blkio.Set(path, r); err != nil {
279278
t.Fatal(err)
@@ -745,15 +744,15 @@ func TestBlkioSetThrottleReadBpsDevice(t *testing.T) {
745744
throttleBefore = `8:0 1024`
746745
)
747746

748-
td := configs.NewThrottleDevice(8, 0, 2048)
747+
td := cgroups.NewThrottleDevice(8, 0, 2048)
749748
throttleAfter := td.String()
750749

751750
writeFileContents(t, path, map[string]string{
752751
"blkio.throttle.read_bps_device": throttleBefore,
753752
})
754753

755-
r := &configs.Resources{
756-
BlkioThrottleReadBpsDevice: []*configs.ThrottleDevice{td},
754+
r := &cgroups.Resources{
755+
BlkioThrottleReadBpsDevice: []*cgroups.ThrottleDevice{td},
757756
}
758757
blkio := &BlkioGroup{}
759758
if err := blkio.Set(path, r); err != nil {
@@ -776,15 +775,15 @@ func TestBlkioSetThrottleWriteBpsDevice(t *testing.T) {
776775
throttleBefore = `8:0 1024`
777776
)
778777

779-
td := configs.NewThrottleDevice(8, 0, 2048)
778+
td := cgroups.NewThrottleDevice(8, 0, 2048)
780779
throttleAfter := td.String()
781780

782781
writeFileContents(t, path, map[string]string{
783782
"blkio.throttle.write_bps_device": throttleBefore,
784783
})
785784

786-
r := &configs.Resources{
787-
BlkioThrottleWriteBpsDevice: []*configs.ThrottleDevice{td},
785+
r := &cgroups.Resources{
786+
BlkioThrottleWriteBpsDevice: []*cgroups.ThrottleDevice{td},
788787
}
789788
blkio := &BlkioGroup{}
790789
if err := blkio.Set(path, r); err != nil {
@@ -807,15 +806,15 @@ func TestBlkioSetThrottleReadIOpsDevice(t *testing.T) {
807806
throttleBefore = `8:0 1024`
808807
)
809808

810-
td := configs.NewThrottleDevice(8, 0, 2048)
809+
td := cgroups.NewThrottleDevice(8, 0, 2048)
811810
throttleAfter := td.String()
812811

813812
writeFileContents(t, path, map[string]string{
814813
"blkio.throttle.read_iops_device": throttleBefore,
815814
})
816815

817-
r := &configs.Resources{
818-
BlkioThrottleReadIOPSDevice: []*configs.ThrottleDevice{td},
816+
r := &cgroups.Resources{
817+
BlkioThrottleReadIOPSDevice: []*cgroups.ThrottleDevice{td},
819818
}
820819
blkio := &BlkioGroup{}
821820
if err := blkio.Set(path, r); err != nil {
@@ -838,15 +837,15 @@ func TestBlkioSetThrottleWriteIOpsDevice(t *testing.T) {
838837
throttleBefore = `8:0 1024`
839838
)
840839

841-
td := configs.NewThrottleDevice(8, 0, 2048)
840+
td := cgroups.NewThrottleDevice(8, 0, 2048)
842841
throttleAfter := td.String()
843842

844843
writeFileContents(t, path, map[string]string{
845844
"blkio.throttle.write_iops_device": throttleBefore,
846845
})
847846

848-
r := &configs.Resources{
849-
BlkioThrottleWriteIOPSDevice: []*configs.ThrottleDevice{td},
847+
r := &cgroups.Resources{
848+
BlkioThrottleWriteIOPSDevice: []*cgroups.ThrottleDevice{td},
850849
}
851850
blkio := &BlkioGroup{}
852851
if err := blkio.Set(path, r); err != nil {

libcontainer/cgroups/fs/cpu.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/opencontainers/runc/libcontainer/cgroups"
1111
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
12-
"github.com/opencontainers/runc/libcontainer/configs"
1312
"golang.org/x/sys/unix"
1413
)
1514

@@ -19,7 +18,7 @@ func (s *CpuGroup) Name() string {
1918
return "cpu"
2019
}
2120

22-
func (s *CpuGroup) Apply(path string, r *configs.Resources, pid int) error {
21+
func (s *CpuGroup) Apply(path string, r *cgroups.Resources, pid int) error {
2322
if err := os.MkdirAll(path, 0o755); err != nil {
2423
return err
2524
}
@@ -34,7 +33,7 @@ func (s *CpuGroup) Apply(path string, r *configs.Resources, pid int) error {
3433
return cgroups.WriteCgroupProc(path, pid)
3534
}
3635

37-
func (s *CpuGroup) SetRtSched(path string, r *configs.Resources) error {
36+
func (s *CpuGroup) SetRtSched(path string, r *cgroups.Resources) error {
3837
var period string
3938
if r.CpuRtPeriod != 0 {
4039
period = strconv.FormatUint(r.CpuRtPeriod, 10)
@@ -64,7 +63,7 @@ func (s *CpuGroup) SetRtSched(path string, r *configs.Resources) error {
6463
return nil
6564
}
6665

67-
func (s *CpuGroup) Set(path string, r *configs.Resources) error {
66+
func (s *CpuGroup) Set(path string, r *cgroups.Resources) error {
6867
if r.CpuShares != 0 {
6968
shares := r.CpuShares
7069
if err := cgroups.WriteFile(path, "cpu.shares", strconv.FormatUint(shares, 10)); err != nil {

libcontainer/cgroups/fs/cpu_test.go

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

88
"github.com/opencontainers/runc/libcontainer/cgroups"
99
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
10-
"github.com/opencontainers/runc/libcontainer/configs"
1110
)
1211

1312
func TestCpuSetShares(t *testing.T) {
@@ -22,7 +21,7 @@ func TestCpuSetShares(t *testing.T) {
2221
"cpu.shares": strconv.Itoa(sharesBefore),
2322
})
2423

25-
r := &configs.Resources{
24+
r := &cgroups.Resources{
2625
CpuShares: sharesAfter,
2726
}
2827
cpu := &CpuGroup{}
@@ -63,7 +62,7 @@ func TestCpuSetBandWidth(t *testing.T) {
6362
"cpu.rt_period_us": strconv.Itoa(rtPeriodBefore),
6463
})
6564

66-
r := &configs.Resources{
65+
r := &cgroups.Resources{
6766
CpuQuota: quotaAfter,
6867
CpuBurst: &burstAfter,
6968
CpuPeriod: periodAfter,
@@ -191,7 +190,7 @@ func TestCpuSetRtSchedAtApply(t *testing.T) {
191190
"cpu.rt_period_us": strconv.Itoa(rtPeriodBefore),
192191
})
193192

194-
r := &configs.Resources{
193+
r := &cgroups.Resources{
195194
CpuRtRuntime: rtRuntimeAfter,
196195
CpuRtPeriod: rtPeriodAfter,
197196
}

libcontainer/cgroups/fs/cpuacct.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/opencontainers/runc/libcontainer/cgroups"
1010
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
11-
"github.com/opencontainers/runc/libcontainer/configs"
1211
)
1312

1413
const (
@@ -34,11 +33,11 @@ func (s *CpuacctGroup) Name() string {
3433
return "cpuacct"
3534
}
3635

37-
func (s *CpuacctGroup) Apply(path string, _ *configs.Resources, pid int) error {
36+
func (s *CpuacctGroup) Apply(path string, _ *cgroups.Resources, pid int) error {
3837
return apply(path, pid)
3938
}
4039

41-
func (s *CpuacctGroup) Set(_ string, _ *configs.Resources) error {
40+
func (s *CpuacctGroup) Set(_ string, _ *cgroups.Resources) error {
4241
return nil
4342
}
4443

0 commit comments

Comments
 (0)