mirror of
https://github.com/opencontainers/runc.git
synced 2025-10-06 16:07:09 +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
|
// does nothing until it's thawed. Only thaw the cgroup
|
||||||
// for SIGKILL.
|
// for SIGKILL.
|
||||||
if paused, _ := c.isPaused(); paused {
|
if paused, _ := c.isPaused(); paused {
|
||||||
_ = c.cgroupManager.Freeze(configs.Thawed)
|
_ = c.cgroupManager.Freeze(cgroups.Thawed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -742,7 +742,7 @@ func (c *Container) Pause() error {
|
|||||||
}
|
}
|
||||||
switch status {
|
switch status {
|
||||||
case Running, Created:
|
case Running, Created:
|
||||||
if err := c.cgroupManager.Freeze(configs.Frozen); err != nil {
|
if err := c.cgroupManager.Freeze(cgroups.Frozen); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return c.state.transition(&pausedState{
|
return c.state.transition(&pausedState{
|
||||||
@@ -766,7 +766,7 @@ func (c *Container) Resume() error {
|
|||||||
if status != Paused {
|
if status != Paused {
|
||||||
return ErrNotPaused
|
return ErrNotPaused
|
||||||
}
|
}
|
||||||
if err := c.cgroupManager.Freeze(configs.Thawed); err != nil {
|
if err := c.cgroupManager.Freeze(cgroups.Thawed); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return c.state.transition(&runningState{
|
return c.state.transition(&runningState{
|
||||||
@@ -886,7 +886,7 @@ func (c *Container) isPaused() (bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return state == configs.Frozen, nil
|
return state == cgroups.Frozen, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) currentState() *State {
|
func (c *Container) currentState() *State {
|
||||||
|
@@ -32,7 +32,7 @@ func (m *mockCgroupManager) Apply(pid int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockCgroupManager) Set(_ *configs.Resources) error {
|
func (m *mockCgroupManager) Set(_ *cgroups.Resources) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,16 +57,16 @@ func (m *mockCgroupManager) Path(subsys string) string {
|
|||||||
return m.paths[subsys]
|
return m.paths[subsys]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockCgroupManager) Freeze(state configs.FreezerState) error {
|
func (m *mockCgroupManager) Freeze(_ cgroups.FreezerState) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockCgroupManager) GetCgroups() (*configs.Cgroup, error) {
|
func (m *mockCgroupManager) GetCgroups() (*cgroups.Cgroup, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockCgroupManager) GetFreezerState() (configs.FreezerState, error) {
|
func (m *mockCgroupManager) GetFreezerState() (cgroups.FreezerState, error) {
|
||||||
return configs.Thawed, nil
|
return cgroups.Thawed, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockProcess struct {
|
type mockProcess struct {
|
||||||
@@ -243,8 +243,8 @@ func TestGetContainerStateAfterUpdate(t *testing.T) {
|
|||||||
{Type: configs.NEWUTS},
|
{Type: configs.NEWUTS},
|
||||||
{Type: configs.NEWIPC},
|
{Type: configs.NEWIPC},
|
||||||
},
|
},
|
||||||
Cgroups: &configs.Cgroup{
|
Cgroups: &cgroups.Cgroup{
|
||||||
Resources: &configs.Resources{
|
Resources: &cgroups.Resources{
|
||||||
Memory: 1024,
|
Memory: 1024,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@@ -9,6 +9,7 @@ import (
|
|||||||
securejoin "github.com/cyphar/filepath-securejoin"
|
securejoin "github.com/cyphar/filepath-securejoin"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups/manager"
|
"github.com/opencontainers/runc/libcontainer/cgroups/manager"
|
||||||
"github.com/opencontainers/runc/libcontainer/configs"
|
"github.com/opencontainers/runc/libcontainer/configs"
|
||||||
"github.com/opencontainers/runc/libcontainer/configs/validate"
|
"github.com/opencontainers/runc/libcontainer/configs/validate"
|
||||||
@@ -82,7 +83,7 @@ func Create(root, id string, config *configs.Config) (*Container, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to get cgroup freezer state: %w", err)
|
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")
|
return nil, errors.New("container's cgroup unexpectedly frozen")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
"github.com/opencontainers/runc/libcontainer/configs"
|
"github.com/opencontainers/runc/libcontainer/configs"
|
||||||
"github.com/opencontainers/runc/libcontainer/utils"
|
"github.com/opencontainers/runc/libcontainer/utils"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
@@ -43,8 +44,8 @@ func TestFactoryLoadContainer(t *testing.T) {
|
|||||||
expectedConfig = &configs.Config{
|
expectedConfig = &configs.Config{
|
||||||
Rootfs: "/mycontainer/root",
|
Rootfs: "/mycontainer/root",
|
||||||
Hooks: expectedHooks,
|
Hooks: expectedHooks,
|
||||||
Cgroups: &configs.Cgroup{
|
Cgroups: &cgroups.Cgroup{
|
||||||
Resources: &configs.Resources{},
|
Resources: &cgroups.Resources{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expectedState = &State{
|
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)
|
logrus.Warn(err)
|
||||||
}
|
}
|
||||||
pids, err := m.GetAllPids()
|
pids, err := m.GetAllPids()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err := m.Freeze(configs.Thawed); err != nil {
|
if err := m.Freeze(cgroups.Thawed); err != nil {
|
||||||
logrus.Warn(err)
|
logrus.Warn(err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -712,7 +712,7 @@ func signalAllProcesses(m cgroups.Manager, s unix.Signal) error {
|
|||||||
logrus.Warnf("kill %d: %v", pid, err)
|
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)
|
logrus.Warn(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -472,7 +472,7 @@ func testFreeze(t *testing.T, withSystemd bool, useSet bool) {
|
|||||||
if !useSet {
|
if !useSet {
|
||||||
err = container.Pause()
|
err = container.Pause()
|
||||||
} else {
|
} else {
|
||||||
config.Cgroups.Resources.Freezer = configs.Frozen
|
config.Cgroups.Resources.Freezer = cgroups.Frozen
|
||||||
err = container.Set(*config)
|
err = container.Set(*config)
|
||||||
}
|
}
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
@@ -486,7 +486,7 @@ func testFreeze(t *testing.T, withSystemd bool, useSet bool) {
|
|||||||
if !useSet {
|
if !useSet {
|
||||||
err = container.Resume()
|
err = container.Resume()
|
||||||
} else {
|
} else {
|
||||||
config.Cgroups.Resources.Freezer = configs.Thawed
|
config.Cgroups.Resources.Freezer = cgroups.Thawed
|
||||||
err = container.Set(*config)
|
err = container.Set(*config)
|
||||||
}
|
}
|
||||||
ok(t, err)
|
ok(t, err)
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
"github.com/opencontainers/runc/libcontainer/configs"
|
"github.com/opencontainers/runc/libcontainer/configs"
|
||||||
"github.com/opencontainers/runc/libcontainer/devices"
|
"github.com/opencontainers/runc/libcontainer/devices"
|
||||||
"github.com/opencontainers/runc/libcontainer/specconv"
|
"github.com/opencontainers/runc/libcontainer/specconv"
|
||||||
@@ -99,9 +100,9 @@ func newTemplateConfig(t testing.TB, p *tParam) *configs.Config {
|
|||||||
{Type: configs.NEWPID},
|
{Type: configs.NEWPID},
|
||||||
{Type: configs.NEWNET},
|
{Type: configs.NEWNET},
|
||||||
}),
|
}),
|
||||||
Cgroups: &configs.Cgroup{
|
Cgroups: &cgroups.Cgroup{
|
||||||
Systemd: p.systemd,
|
Systemd: p.systemd,
|
||||||
Resources: &configs.Resources{
|
Resources: &cgroups.Resources{
|
||||||
MemorySwappiness: nil,
|
MemorySwappiness: nil,
|
||||||
Devices: allowedDevices,
|
Devices: allowedDevices,
|
||||||
},
|
},
|
||||||
|
@@ -697,7 +697,7 @@ func initSystemdProps(spec *specs.Spec) ([]systemdDbus.Property, error) {
|
|||||||
return sp, nil
|
return sp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*configs.Cgroup, error) {
|
func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*cgroups.Cgroup, error) {
|
||||||
var (
|
var (
|
||||||
myCgroupPath string
|
myCgroupPath string
|
||||||
|
|
||||||
@@ -706,10 +706,10 @@ func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*confi
|
|||||||
name = opts.CgroupName
|
name = opts.CgroupName
|
||||||
)
|
)
|
||||||
|
|
||||||
c := &configs.Cgroup{
|
c := &cgroups.Cgroup{
|
||||||
Systemd: useSystemdCgroup,
|
Systemd: useSystemdCgroup,
|
||||||
Rootless: opts.RootlessCgroups,
|
Rootless: opts.RootlessCgroups,
|
||||||
Resources: &configs.Resources{},
|
Resources: &cgroups.Resources{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if useSystemdCgroup {
|
if useSystemdCgroup {
|
||||||
@@ -853,40 +853,40 @@ func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*confi
|
|||||||
if wd.LeafWeight != nil {
|
if wd.LeafWeight != nil {
|
||||||
leafWeight = *wd.LeafWeight
|
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)
|
c.Resources.BlkioWeightDevice = append(c.Resources.BlkioWeightDevice, weightDevice)
|
||||||
}
|
}
|
||||||
for _, td := range r.BlockIO.ThrottleReadBpsDevice {
|
for _, td := range r.BlockIO.ThrottleReadBpsDevice {
|
||||||
rate := td.Rate
|
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)
|
c.Resources.BlkioThrottleReadBpsDevice = append(c.Resources.BlkioThrottleReadBpsDevice, throttleDevice)
|
||||||
}
|
}
|
||||||
for _, td := range r.BlockIO.ThrottleWriteBpsDevice {
|
for _, td := range r.BlockIO.ThrottleWriteBpsDevice {
|
||||||
rate := td.Rate
|
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)
|
c.Resources.BlkioThrottleWriteBpsDevice = append(c.Resources.BlkioThrottleWriteBpsDevice, throttleDevice)
|
||||||
}
|
}
|
||||||
for _, td := range r.BlockIO.ThrottleReadIOPSDevice {
|
for _, td := range r.BlockIO.ThrottleReadIOPSDevice {
|
||||||
rate := td.Rate
|
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)
|
c.Resources.BlkioThrottleReadIOPSDevice = append(c.Resources.BlkioThrottleReadIOPSDevice, throttleDevice)
|
||||||
}
|
}
|
||||||
for _, td := range r.BlockIO.ThrottleWriteIOPSDevice {
|
for _, td := range r.BlockIO.ThrottleWriteIOPSDevice {
|
||||||
rate := td.Rate
|
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)
|
c.Resources.BlkioThrottleWriteIOPSDevice = append(c.Resources.BlkioThrottleWriteIOPSDevice, throttleDevice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, l := range r.HugepageLimits {
|
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,
|
Pagesize: l.Pagesize,
|
||||||
Limit: l.Limit,
|
Limit: l.Limit,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if len(r.Rdma) > 0 {
|
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 {
|
for k, v := range r.Rdma {
|
||||||
c.Resources.Rdma[k] = configs.LinuxRdma{
|
c.Resources.Rdma[k] = cgroups.LinuxRdma{
|
||||||
HcaHandles: v.HcaHandles,
|
HcaHandles: v.HcaHandles,
|
||||||
HcaObjects: v.HcaObjects,
|
HcaObjects: v.HcaObjects,
|
||||||
}
|
}
|
||||||
@@ -897,7 +897,7 @@ func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*confi
|
|||||||
c.Resources.NetClsClassid = *r.Network.ClassID
|
c.Resources.NetClsClassid = *r.Network.ClassID
|
||||||
}
|
}
|
||||||
for _, m := range r.Network.Priorities {
|
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,
|
Interface: m.Name,
|
||||||
Priority: int64(m.Priority),
|
Priority: int64(m.Priority),
|
||||||
})
|
})
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
"github.com/opencontainers/runc/libcontainer/configs"
|
"github.com/opencontainers/runc/libcontainer/configs"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
@@ -185,7 +186,7 @@ func (p *pausedState) destroy() error {
|
|||||||
if p.c.hasInit() {
|
if p.c.hasInit() {
|
||||||
return ErrPaused
|
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 err
|
||||||
}
|
}
|
||||||
return destroy(p.c)
|
return destroy(p.c)
|
||||||
|
Reference in New Issue
Block a user