mirror of
https://github.com/opencontainers/runc.git
synced 2025-10-05 23:46:57 +08:00
libct/*: switch from configs to cgroups
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -417,7 +417,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(cgroups.Thawed)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -742,7 +742,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(cgroups.Frozen); err != nil {
|
||||
return err
|
||||
}
|
||||
return c.state.transition(&pausedState{
|
||||
@@ -766,7 +766,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(cgroups.Thawed); err != nil {
|
||||
return err
|
||||
}
|
||||
return c.state.transition(&runningState{
|
||||
@@ -886,7 +886,7 @@ func (c *Container) isPaused() (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return state == configs.Frozen, nil
|
||||
return state == cgroups.Frozen, nil
|
||||
}
|
||||
|
||||
func (c *Container) currentState() *State {
|
||||
|
@@ -32,7 +32,7 @@ func (m *mockCgroupManager) Apply(pid int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockCgroupManager) Set(_ *configs.Resources) error {
|
||||
func (m *mockCgroupManager) Set(_ *cgroups.Resources) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -57,16 +57,16 @@ func (m *mockCgroupManager) Path(subsys string) string {
|
||||
return m.paths[subsys]
|
||||
}
|
||||
|
||||
func (m *mockCgroupManager) Freeze(state configs.FreezerState) error {
|
||||
func (m *mockCgroupManager) Freeze(_ cgroups.FreezerState) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockCgroupManager) GetCgroups() (*configs.Cgroup, error) {
|
||||
func (m *mockCgroupManager) GetCgroups() (*cgroups.Cgroup, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *mockCgroupManager) GetFreezerState() (configs.FreezerState, error) {
|
||||
return configs.Thawed, nil
|
||||
func (m *mockCgroupManager) GetFreezerState() (cgroups.FreezerState, error) {
|
||||
return cgroups.Thawed, nil
|
||||
}
|
||||
|
||||
type mockProcess struct {
|
||||
@@ -243,8 +243,8 @@ func TestGetContainerStateAfterUpdate(t *testing.T) {
|
||||
{Type: configs.NEWUTS},
|
||||
{Type: configs.NEWIPC},
|
||||
},
|
||||
Cgroups: &configs.Cgroup{
|
||||
Resources: &configs.Resources{
|
||||
Cgroups: &cgroups.Cgroup{
|
||||
Resources: &cgroups.Resources{
|
||||
Memory: 1024,
|
||||
},
|
||||
},
|
||||
|
@@ -9,6 +9,7 @@ import (
|
||||
securejoin "github.com/cyphar/filepath-securejoin"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||
"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 == cgroups.Frozen {
|
||||
return nil, errors.New("container's cgroup unexpectedly frozen")
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||
"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: &cgroups.Cgroup{
|
||||
Resources: &cgroups.Resources{},
|
||||
},
|
||||
}
|
||||
expectedState = &State{
|
||||
|
@@ -696,12 +696,12 @@ func signalAllProcesses(m cgroups.Manager, s unix.Signal) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := m.Freeze(configs.Frozen); err != nil {
|
||||
if err := m.Freeze(cgroups.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(cgroups.Thawed); err != nil {
|
||||
logrus.Warn(err)
|
||||
}
|
||||
return err
|
||||
@@ -712,7 +712,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(cgroups.Thawed); err != nil {
|
||||
logrus.Warn(err)
|
||||
}
|
||||
|
||||
|
@@ -472,7 +472,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 = cgroups.Frozen
|
||||
err = container.Set(*config)
|
||||
}
|
||||
ok(t, err)
|
||||
@@ -486,7 +486,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 = cgroups.Thawed
|
||||
err = container.Set(*config)
|
||||
}
|
||||
ok(t, err)
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||
"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: &cgroups.Cgroup{
|
||||
Systemd: p.systemd,
|
||||
Resources: &configs.Resources{
|
||||
Resources: &cgroups.Resources{
|
||||
MemorySwappiness: nil,
|
||||
Devices: allowedDevices,
|
||||
},
|
||||
|
@@ -697,7 +697,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) (*cgroups.Cgroup, error) {
|
||||
var (
|
||||
myCgroupPath string
|
||||
|
||||
@@ -706,10 +706,10 @@ func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*confi
|
||||
name = opts.CgroupName
|
||||
)
|
||||
|
||||
c := &configs.Cgroup{
|
||||
c := &cgroups.Cgroup{
|
||||
Systemd: useSystemdCgroup,
|
||||
Rootless: opts.RootlessCgroups,
|
||||
Resources: &configs.Resources{},
|
||||
Resources: &cgroups.Resources{},
|
||||
}
|
||||
|
||||
if useSystemdCgroup {
|
||||
@@ -853,40 +853,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 := cgroups.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 := cgroups.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 := cgroups.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 := cgroups.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 := cgroups.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, &cgroups.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]cgroups.LinuxRdma, len(r.Rdma))
|
||||
for k, v := range r.Rdma {
|
||||
c.Resources.Rdma[k] = configs.LinuxRdma{
|
||||
c.Resources.Rdma[k] = cgroups.LinuxRdma{
|
||||
HcaHandles: v.HcaHandles,
|
||||
HcaObjects: v.HcaObjects,
|
||||
}
|
||||
@@ -897,7 +897,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, &cgroups.IfPrioMap{
|
||||
Interface: m.Name,
|
||||
Priority: int64(m.Priority),
|
||||
})
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||
"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(cgroups.Thawed); err != nil {
|
||||
return err
|
||||
}
|
||||
return destroy(p.c)
|
||||
|
Reference in New Issue
Block a user