diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index c02116177ad..613db842715 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -21,6 +21,7 @@ import ( "golang.org/x/sys/unix" "github.com/opencontainers/runc/libcontainer/cgroups" + cgConfig "github.com/opencontainers/runc/libcontainer/cgroups/configs" "github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/dmz" "github.com/opencontainers/runc/libcontainer/intelrdt" @@ -417,7 +418,7 @@ func (c *Container) signal(s os.Signal) error { // does nothing until it's thawed. Only thaw the cgroup // for SIGKILL. if paused, _ := c.isPaused(); paused { - _ = c.cgroupManager.Freeze(configs.Thawed) + _ = c.cgroupManager.Freeze(cgConfig.Thawed) } } return nil @@ -742,7 +743,7 @@ func (c *Container) Pause() error { } switch status { case Running, Created: - if err := c.cgroupManager.Freeze(configs.Frozen); err != nil { + if err := c.cgroupManager.Freeze(cgConfig.Frozen); err != nil { return err } return c.state.transition(&pausedState{ @@ -766,7 +767,7 @@ func (c *Container) Resume() error { if status != Paused { return ErrNotPaused } - if err := c.cgroupManager.Freeze(configs.Thawed); err != nil { + if err := c.cgroupManager.Freeze(cgConfig.Thawed); err != nil { return err } return c.state.transition(&runningState{ @@ -886,7 +887,7 @@ func (c *Container) isPaused() (bool, error) { if err != nil { return false, err } - return state == configs.Frozen, nil + return state == cgConfig.Frozen, nil } func (c *Container) currentState() *State { diff --git a/libcontainer/container_linux_test.go b/libcontainer/container_linux_test.go index 99908376562..2d430b037eb 100644 --- a/libcontainer/container_linux_test.go +++ b/libcontainer/container_linux_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/opencontainers/runc/libcontainer/cgroups" + cgConfig "github.com/opencontainers/runc/libcontainer/cgroups/configs" "github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/system" ) @@ -32,7 +33,7 @@ func (m *mockCgroupManager) Apply(pid int) error { return nil } -func (m *mockCgroupManager) Set(_ *configs.Resources) error { +func (m *mockCgroupManager) Set(_ *cgConfig.Resources) error { return nil } @@ -57,16 +58,16 @@ func (m *mockCgroupManager) Path(subsys string) string { return m.paths[subsys] } -func (m *mockCgroupManager) Freeze(state configs.FreezerState) error { +func (m *mockCgroupManager) Freeze(_ cgConfig.FreezerState) error { return nil } -func (m *mockCgroupManager) GetCgroups() (*configs.Cgroup, error) { +func (m *mockCgroupManager) GetCgroups() (*cgConfig.Cgroup, error) { return nil, nil } -func (m *mockCgroupManager) GetFreezerState() (configs.FreezerState, error) { - return configs.Thawed, nil +func (m *mockCgroupManager) GetFreezerState() (cgConfig.FreezerState, error) { + return cgConfig.Thawed, nil } type mockProcess struct { @@ -243,8 +244,8 @@ func TestGetContainerStateAfterUpdate(t *testing.T) { {Type: configs.NEWUTS}, {Type: configs.NEWIPC}, }, - Cgroups: &configs.Cgroup{ - Resources: &configs.Resources{ + Cgroups: &cgConfig.Cgroup{ + Resources: &cgConfig.Resources{ Memory: 1024, }, }, diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go index b13f8bf9bb3..fa233bd6ee3 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -9,6 +9,7 @@ import ( securejoin "github.com/cyphar/filepath-securejoin" "golang.org/x/sys/unix" + cgConfig "github.com/opencontainers/runc/libcontainer/cgroups/configs" "github.com/opencontainers/runc/libcontainer/cgroups/manager" "github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/configs/validate" @@ -82,7 +83,7 @@ func Create(root, id string, config *configs.Config) (*Container, error) { if err != nil { return nil, fmt.Errorf("unable to get cgroup freezer state: %w", err) } - if st == configs.Frozen { + if st == cgConfig.Frozen { return nil, errors.New("container's cgroup unexpectedly frozen") } diff --git a/libcontainer/factory_linux_test.go b/libcontainer/factory_linux_test.go index 889ae0340dd..77548a0f3a0 100644 --- a/libcontainer/factory_linux_test.go +++ b/libcontainer/factory_linux_test.go @@ -7,6 +7,7 @@ import ( "reflect" "testing" + cgConfig "github.com/opencontainers/runc/libcontainer/cgroups/configs" "github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/utils" "github.com/opencontainers/runtime-spec/specs-go" @@ -43,8 +44,8 @@ func TestFactoryLoadContainer(t *testing.T) { expectedConfig = &configs.Config{ Rootfs: "/mycontainer/root", Hooks: expectedHooks, - Cgroups: &configs.Cgroup{ - Resources: &configs.Resources{}, + Cgroups: &cgConfig.Cgroup{ + Resources: &cgConfig.Resources{}, }, } expectedState = &State{ diff --git a/libcontainer/init_linux.go b/libcontainer/init_linux.go index 1eb0279d9e0..92c5a6c4438 100644 --- a/libcontainer/init_linux.go +++ b/libcontainer/init_linux.go @@ -23,6 +23,7 @@ import ( "github.com/opencontainers/runc/libcontainer/capabilities" "github.com/opencontainers/runc/libcontainer/cgroups" + cgConfig "github.com/opencontainers/runc/libcontainer/cgroups/configs" "github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/system" "github.com/opencontainers/runc/libcontainer/utils" @@ -696,12 +697,12 @@ func signalAllProcesses(m cgroups.Manager, s unix.Signal) error { } } - if err := m.Freeze(configs.Frozen); err != nil { + if err := m.Freeze(cgConfig.Frozen); err != nil { logrus.Warn(err) } pids, err := m.GetAllPids() if err != nil { - if err := m.Freeze(configs.Thawed); err != nil { + if err := m.Freeze(cgConfig.Thawed); err != nil { logrus.Warn(err) } return err @@ -712,7 +713,7 @@ func signalAllProcesses(m cgroups.Manager, s unix.Signal) error { logrus.Warnf("kill %d: %v", pid, err) } } - if err := m.Freeze(configs.Thawed); err != nil { + if err := m.Freeze(cgConfig.Thawed); err != nil { logrus.Warn(err) } diff --git a/libcontainer/integration/exec_test.go b/libcontainer/integration/exec_test.go index e8a2dc53c80..be01786559e 100644 --- a/libcontainer/integration/exec_test.go +++ b/libcontainer/integration/exec_test.go @@ -16,6 +16,7 @@ import ( "github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer/cgroups" + cgConfig "github.com/opencontainers/runc/libcontainer/cgroups/configs" "github.com/opencontainers/runc/libcontainer/cgroups/systemd" "github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/internal/userns" @@ -472,7 +473,7 @@ func testFreeze(t *testing.T, withSystemd bool, useSet bool) { if !useSet { err = container.Pause() } else { - config.Cgroups.Resources.Freezer = configs.Frozen + config.Cgroups.Resources.Freezer = cgConfig.Frozen err = container.Set(*config) } ok(t, err) @@ -486,7 +487,7 @@ func testFreeze(t *testing.T, withSystemd bool, useSet bool) { if !useSet { err = container.Resume() } else { - config.Cgroups.Resources.Freezer = configs.Thawed + config.Cgroups.Resources.Freezer = cgConfig.Thawed err = container.Set(*config) } ok(t, err) diff --git a/libcontainer/integration/template_test.go b/libcontainer/integration/template_test.go index 38024c571d3..60f468be29a 100644 --- a/libcontainer/integration/template_test.go +++ b/libcontainer/integration/template_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + cgConfig "github.com/opencontainers/runc/libcontainer/cgroups/configs" "github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/devices" "github.com/opencontainers/runc/libcontainer/specconv" @@ -99,9 +100,9 @@ func newTemplateConfig(t testing.TB, p *tParam) *configs.Config { {Type: configs.NEWPID}, {Type: configs.NEWNET}, }), - Cgroups: &configs.Cgroup{ + Cgroups: &cgConfig.Cgroup{ Systemd: p.systemd, - Resources: &configs.Resources{ + Resources: &cgConfig.Resources{ MemorySwappiness: nil, Devices: allowedDevices, }, diff --git a/libcontainer/specconv/spec_linux.go b/libcontainer/specconv/spec_linux.go index e7c6faae347..d312e4132d4 100644 --- a/libcontainer/specconv/spec_linux.go +++ b/libcontainer/specconv/spec_linux.go @@ -15,6 +15,7 @@ import ( systemdDbus "github.com/coreos/go-systemd/v22/dbus" dbus "github.com/godbus/dbus/v5" "github.com/opencontainers/runc/libcontainer/cgroups" + cgConfig "github.com/opencontainers/runc/libcontainer/cgroups/configs" "github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/devices" "github.com/opencontainers/runc/libcontainer/internal/userns" @@ -697,7 +698,7 @@ func initSystemdProps(spec *specs.Spec) ([]systemdDbus.Property, error) { return sp, nil } -func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*configs.Cgroup, error) { +func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*cgConfig.Cgroup, error) { var ( myCgroupPath string @@ -706,10 +707,10 @@ func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*confi name = opts.CgroupName ) - c := &configs.Cgroup{ + c := &cgConfig.Cgroup{ Systemd: useSystemdCgroup, Rootless: opts.RootlessCgroups, - Resources: &configs.Resources{}, + Resources: &cgConfig.Resources{}, } if useSystemdCgroup { @@ -853,40 +854,40 @@ func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*confi if wd.LeafWeight != nil { leafWeight = *wd.LeafWeight } - weightDevice := configs.NewWeightDevice(wd.Major, wd.Minor, weight, leafWeight) + weightDevice := cgConfig.NewWeightDevice(wd.Major, wd.Minor, weight, leafWeight) c.Resources.BlkioWeightDevice = append(c.Resources.BlkioWeightDevice, weightDevice) } for _, td := range r.BlockIO.ThrottleReadBpsDevice { rate := td.Rate - throttleDevice := configs.NewThrottleDevice(td.Major, td.Minor, rate) + throttleDevice := cgConfig.NewThrottleDevice(td.Major, td.Minor, rate) c.Resources.BlkioThrottleReadBpsDevice = append(c.Resources.BlkioThrottleReadBpsDevice, throttleDevice) } for _, td := range r.BlockIO.ThrottleWriteBpsDevice { rate := td.Rate - throttleDevice := configs.NewThrottleDevice(td.Major, td.Minor, rate) + throttleDevice := cgConfig.NewThrottleDevice(td.Major, td.Minor, rate) c.Resources.BlkioThrottleWriteBpsDevice = append(c.Resources.BlkioThrottleWriteBpsDevice, throttleDevice) } for _, td := range r.BlockIO.ThrottleReadIOPSDevice { rate := td.Rate - throttleDevice := configs.NewThrottleDevice(td.Major, td.Minor, rate) + throttleDevice := cgConfig.NewThrottleDevice(td.Major, td.Minor, rate) c.Resources.BlkioThrottleReadIOPSDevice = append(c.Resources.BlkioThrottleReadIOPSDevice, throttleDevice) } for _, td := range r.BlockIO.ThrottleWriteIOPSDevice { rate := td.Rate - throttleDevice := configs.NewThrottleDevice(td.Major, td.Minor, rate) + throttleDevice := cgConfig.NewThrottleDevice(td.Major, td.Minor, rate) c.Resources.BlkioThrottleWriteIOPSDevice = append(c.Resources.BlkioThrottleWriteIOPSDevice, throttleDevice) } } for _, l := range r.HugepageLimits { - c.Resources.HugetlbLimit = append(c.Resources.HugetlbLimit, &configs.HugepageLimit{ + c.Resources.HugetlbLimit = append(c.Resources.HugetlbLimit, &cgConfig.HugepageLimit{ Pagesize: l.Pagesize, Limit: l.Limit, }) } if len(r.Rdma) > 0 { - c.Resources.Rdma = make(map[string]configs.LinuxRdma, len(r.Rdma)) + c.Resources.Rdma = make(map[string]cgConfig.LinuxRdma, len(r.Rdma)) for k, v := range r.Rdma { - c.Resources.Rdma[k] = configs.LinuxRdma{ + c.Resources.Rdma[k] = cgConfig.LinuxRdma{ HcaHandles: v.HcaHandles, HcaObjects: v.HcaObjects, } @@ -897,7 +898,7 @@ func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*confi c.Resources.NetClsClassid = *r.Network.ClassID } for _, m := range r.Network.Priorities { - c.Resources.NetPrioIfpriomap = append(c.Resources.NetPrioIfpriomap, &configs.IfPrioMap{ + c.Resources.NetPrioIfpriomap = append(c.Resources.NetPrioIfpriomap, &cgConfig.IfPrioMap{ Interface: m.Name, Priority: int64(m.Priority), }) diff --git a/libcontainer/state_linux.go b/libcontainer/state_linux.go index ad96f0801ea..398427d02c6 100644 --- a/libcontainer/state_linux.go +++ b/libcontainer/state_linux.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" + cgConfig "github.com/opencontainers/runc/libcontainer/cgroups/configs" "github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runtime-spec/specs-go" "golang.org/x/sys/unix" @@ -185,7 +186,7 @@ func (p *pausedState) destroy() error { if p.c.hasInit() { return ErrPaused } - if err := p.c.cgroupManager.Freeze(configs.Thawed); err != nil { + if err := p.c.cgroupManager.Freeze(cgConfig.Thawed); err != nil { return err } return destroy(p.c)