Skip to content

Commit a56f85f

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

File tree

9 files changed

+38
-34
lines changed

9 files changed

+38
-34
lines changed

libcontainer/container_linux.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func (c *Container) signal(s os.Signal) error {
417417
// does nothing until it's thawed. Only thaw the cgroup
418418
// for SIGKILL.
419419
if paused, _ := c.isPaused(); paused {
420-
_ = c.cgroupManager.Freeze(configs.Thawed)
420+
_ = c.cgroupManager.Freeze(cgroups.Thawed)
421421
}
422422
}
423423
return nil
@@ -742,7 +742,7 @@ func (c *Container) Pause() error {
742742
}
743743
switch status {
744744
case Running, Created:
745-
if err := c.cgroupManager.Freeze(configs.Frozen); err != nil {
745+
if err := c.cgroupManager.Freeze(cgroups.Frozen); err != nil {
746746
return err
747747
}
748748
return c.state.transition(&pausedState{
@@ -766,7 +766,7 @@ func (c *Container) Resume() error {
766766
if status != Paused {
767767
return ErrNotPaused
768768
}
769-
if err := c.cgroupManager.Freeze(configs.Thawed); err != nil {
769+
if err := c.cgroupManager.Freeze(cgroups.Thawed); err != nil {
770770
return err
771771
}
772772
return c.state.transition(&runningState{
@@ -886,7 +886,7 @@ func (c *Container) isPaused() (bool, error) {
886886
if err != nil {
887887
return false, err
888888
}
889-
return state == configs.Frozen, nil
889+
return state == cgroups.Frozen, nil
890890
}
891891

892892
func (c *Container) currentState() *State {

libcontainer/container_linux_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (m *mockCgroupManager) Apply(pid int) error {
3232
return nil
3333
}
3434

35-
func (m *mockCgroupManager) Set(_ *configs.Resources) error {
35+
func (m *mockCgroupManager) Set(_ *cgroups.Resources) error {
3636
return nil
3737
}
3838

@@ -57,16 +57,16 @@ func (m *mockCgroupManager) Path(subsys string) string {
5757
return m.paths[subsys]
5858
}
5959

60-
func (m *mockCgroupManager) Freeze(state configs.FreezerState) error {
60+
func (m *mockCgroupManager) Freeze(_ cgroups.FreezerState) error {
6161
return nil
6262
}
6363

64-
func (m *mockCgroupManager) GetCgroups() (*configs.Cgroup, error) {
64+
func (m *mockCgroupManager) GetCgroups() (*cgroups.Cgroup, error) {
6565
return nil, nil
6666
}
6767

68-
func (m *mockCgroupManager) GetFreezerState() (configs.FreezerState, error) {
69-
return configs.Thawed, nil
68+
func (m *mockCgroupManager) GetFreezerState() (cgroups.FreezerState, error) {
69+
return cgroups.Thawed, nil
7070
}
7171

7272
type mockProcess struct {
@@ -243,8 +243,8 @@ func TestGetContainerStateAfterUpdate(t *testing.T) {
243243
{Type: configs.NEWUTS},
244244
{Type: configs.NEWIPC},
245245
},
246-
Cgroups: &configs.Cgroup{
247-
Resources: &configs.Resources{
246+
Cgroups: &cgroups.Cgroup{
247+
Resources: &cgroups.Resources{
248248
Memory: 1024,
249249
},
250250
},

libcontainer/factory_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
securejoin "github.com/cyphar/filepath-securejoin"
1010
"golang.org/x/sys/unix"
1111

12+
"github.com/opencontainers/runc/libcontainer/cgroups"
1213
"github.com/opencontainers/runc/libcontainer/cgroups/manager"
1314
"github.com/opencontainers/runc/libcontainer/configs"
1415
"github.com/opencontainers/runc/libcontainer/configs/validate"
@@ -82,7 +83,7 @@ func Create(root, id string, config *configs.Config) (*Container, error) {
8283
if err != nil {
8384
return nil, fmt.Errorf("unable to get cgroup freezer state: %w", err)
8485
}
85-
if st == configs.Frozen {
86+
if st == cgroups.Frozen {
8687
return nil, errors.New("container's cgroup unexpectedly frozen")
8788
}
8889

libcontainer/factory_linux_test.go

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

10+
"github.com/opencontainers/runc/libcontainer/cgroups"
1011
"github.com/opencontainers/runc/libcontainer/configs"
1112
"github.com/opencontainers/runc/libcontainer/utils"
1213
"github.com/opencontainers/runtime-spec/specs-go"
@@ -43,8 +44,8 @@ func TestFactoryLoadContainer(t *testing.T) {
4344
expectedConfig = &configs.Config{
4445
Rootfs: "/mycontainer/root",
4546
Hooks: expectedHooks,
46-
Cgroups: &configs.Cgroup{
47-
Resources: &configs.Resources{},
47+
Cgroups: &cgroups.Cgroup{
48+
Resources: &cgroups.Resources{},
4849
},
4950
}
5051
expectedState = &State{

libcontainer/init_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,12 @@ func signalAllProcesses(m cgroups.Manager, s unix.Signal) error {
696696
}
697697
}
698698

699-
if err := m.Freeze(configs.Frozen); err != nil {
699+
if err := m.Freeze(cgroups.Frozen); err != nil {
700700
logrus.Warn(err)
701701
}
702702
pids, err := m.GetAllPids()
703703
if err != nil {
704-
if err := m.Freeze(configs.Thawed); err != nil {
704+
if err := m.Freeze(cgroups.Thawed); err != nil {
705705
logrus.Warn(err)
706706
}
707707
return err
@@ -712,7 +712,7 @@ func signalAllProcesses(m cgroups.Manager, s unix.Signal) error {
712712
logrus.Warnf("kill %d: %v", pid, err)
713713
}
714714
}
715-
if err := m.Freeze(configs.Thawed); err != nil {
715+
if err := m.Freeze(cgroups.Thawed); err != nil {
716716
logrus.Warn(err)
717717
}
718718

libcontainer/integration/exec_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ func testFreeze(t *testing.T, withSystemd bool, useSet bool) {
472472
if !useSet {
473473
err = container.Pause()
474474
} else {
475-
config.Cgroups.Resources.Freezer = configs.Frozen
475+
config.Cgroups.Resources.Freezer = cgroups.Frozen
476476
err = container.Set(*config)
477477
}
478478
ok(t, err)
@@ -486,7 +486,7 @@ func testFreeze(t *testing.T, withSystemd bool, useSet bool) {
486486
if !useSet {
487487
err = container.Resume()
488488
} else {
489-
config.Cgroups.Resources.Freezer = configs.Thawed
489+
config.Cgroups.Resources.Freezer = cgroups.Thawed
490490
err = container.Set(*config)
491491
}
492492
ok(t, err)

libcontainer/integration/template_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77
"time"
88

9+
"github.com/opencontainers/runc/libcontainer/cgroups"
910
"github.com/opencontainers/runc/libcontainer/configs"
1011
"github.com/opencontainers/runc/libcontainer/devices"
1112
"github.com/opencontainers/runc/libcontainer/specconv"
@@ -99,9 +100,9 @@ func newTemplateConfig(t testing.TB, p *tParam) *configs.Config {
99100
{Type: configs.NEWPID},
100101
{Type: configs.NEWNET},
101102
}),
102-
Cgroups: &configs.Cgroup{
103+
Cgroups: &cgroups.Cgroup{
103104
Systemd: p.systemd,
104-
Resources: &configs.Resources{
105+
Resources: &cgroups.Resources{
105106
MemorySwappiness: nil,
106107
Devices: allowedDevices,
107108
},

libcontainer/specconv/spec_linux.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ func initSystemdProps(spec *specs.Spec) ([]systemdDbus.Property, error) {
697697
return sp, nil
698698
}
699699

700-
func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*configs.Cgroup, error) {
700+
func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*cgroups.Cgroup, error) {
701701
var (
702702
myCgroupPath string
703703

@@ -706,10 +706,10 @@ func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*confi
706706
name = opts.CgroupName
707707
)
708708

709-
c := &configs.Cgroup{
709+
c := &cgroups.Cgroup{
710710
Systemd: useSystemdCgroup,
711711
Rootless: opts.RootlessCgroups,
712-
Resources: &configs.Resources{},
712+
Resources: &cgroups.Resources{},
713713
}
714714

715715
if useSystemdCgroup {
@@ -853,40 +853,40 @@ func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*confi
853853
if wd.LeafWeight != nil {
854854
leafWeight = *wd.LeafWeight
855855
}
856-
weightDevice := configs.NewWeightDevice(wd.Major, wd.Minor, weight, leafWeight)
856+
weightDevice := cgroups.NewWeightDevice(wd.Major, wd.Minor, weight, leafWeight)
857857
c.Resources.BlkioWeightDevice = append(c.Resources.BlkioWeightDevice, weightDevice)
858858
}
859859
for _, td := range r.BlockIO.ThrottleReadBpsDevice {
860860
rate := td.Rate
861-
throttleDevice := configs.NewThrottleDevice(td.Major, td.Minor, rate)
861+
throttleDevice := cgroups.NewThrottleDevice(td.Major, td.Minor, rate)
862862
c.Resources.BlkioThrottleReadBpsDevice = append(c.Resources.BlkioThrottleReadBpsDevice, throttleDevice)
863863
}
864864
for _, td := range r.BlockIO.ThrottleWriteBpsDevice {
865865
rate := td.Rate
866-
throttleDevice := configs.NewThrottleDevice(td.Major, td.Minor, rate)
866+
throttleDevice := cgroups.NewThrottleDevice(td.Major, td.Minor, rate)
867867
c.Resources.BlkioThrottleWriteBpsDevice = append(c.Resources.BlkioThrottleWriteBpsDevice, throttleDevice)
868868
}
869869
for _, td := range r.BlockIO.ThrottleReadIOPSDevice {
870870
rate := td.Rate
871-
throttleDevice := configs.NewThrottleDevice(td.Major, td.Minor, rate)
871+
throttleDevice := cgroups.NewThrottleDevice(td.Major, td.Minor, rate)
872872
c.Resources.BlkioThrottleReadIOPSDevice = append(c.Resources.BlkioThrottleReadIOPSDevice, throttleDevice)
873873
}
874874
for _, td := range r.BlockIO.ThrottleWriteIOPSDevice {
875875
rate := td.Rate
876-
throttleDevice := configs.NewThrottleDevice(td.Major, td.Minor, rate)
876+
throttleDevice := cgroups.NewThrottleDevice(td.Major, td.Minor, rate)
877877
c.Resources.BlkioThrottleWriteIOPSDevice = append(c.Resources.BlkioThrottleWriteIOPSDevice, throttleDevice)
878878
}
879879
}
880880
for _, l := range r.HugepageLimits {
881-
c.Resources.HugetlbLimit = append(c.Resources.HugetlbLimit, &configs.HugepageLimit{
881+
c.Resources.HugetlbLimit = append(c.Resources.HugetlbLimit, &cgroups.HugepageLimit{
882882
Pagesize: l.Pagesize,
883883
Limit: l.Limit,
884884
})
885885
}
886886
if len(r.Rdma) > 0 {
887-
c.Resources.Rdma = make(map[string]configs.LinuxRdma, len(r.Rdma))
887+
c.Resources.Rdma = make(map[string]cgroups.LinuxRdma, len(r.Rdma))
888888
for k, v := range r.Rdma {
889-
c.Resources.Rdma[k] = configs.LinuxRdma{
889+
c.Resources.Rdma[k] = cgroups.LinuxRdma{
890890
HcaHandles: v.HcaHandles,
891891
HcaObjects: v.HcaObjects,
892892
}
@@ -897,7 +897,7 @@ func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*confi
897897
c.Resources.NetClsClassid = *r.Network.ClassID
898898
}
899899
for _, m := range r.Network.Priorities {
900-
c.Resources.NetPrioIfpriomap = append(c.Resources.NetPrioIfpriomap, &configs.IfPrioMap{
900+
c.Resources.NetPrioIfpriomap = append(c.Resources.NetPrioIfpriomap, &cgroups.IfPrioMap{
901901
Interface: m.Name,
902902
Priority: int64(m.Priority),
903903
})

libcontainer/state_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77

8+
"github.com/opencontainers/runc/libcontainer/cgroups"
89
"github.com/opencontainers/runc/libcontainer/configs"
910
"github.com/opencontainers/runtime-spec/specs-go"
1011
"golang.org/x/sys/unix"
@@ -185,7 +186,7 @@ func (p *pausedState) destroy() error {
185186
if p.c.hasInit() {
186187
return ErrPaused
187188
}
188-
if err := p.c.cgroupManager.Freeze(configs.Thawed); err != nil {
189+
if err := p.c.cgroupManager.Freeze(cgroups.Thawed); err != nil {
189190
return err
190191
}
191192
return destroy(p.c)

0 commit comments

Comments
 (0)