Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ linters:
enable:
- gofumpt
- errorlint
- revive
- unconvert
- unparam

issues:
include:
- EXC0002
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a warning produced by golint? Since this commit does not enable golint, it makes no sense.

Or, if it is also produced by revive, I think a comment is needed here, telling what this does.

16 changes: 8 additions & 8 deletions checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"
"strconv"

criu "github.com/checkpoint-restore/go-criu/v5/rpc"
criurpc "github.com/checkpoint-restore/go-criu/v5/rpc"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/userns"
"github.com/opencontainers/runtime-spec/specs-go"
Expand Down Expand Up @@ -109,7 +109,7 @@ func prepareImagePaths(context *cli.Context) (string, string, error) {
return imagePath, parentPath, nil
}

func setPageServer(context *cli.Context, options *libcontainer.CriuOpts) {
func setPageServer(context *cli.Context, options *libcontainer.CRIUOpts) {
// xxx following criu opts are optional
// The dump image can be sent to a criu page server
if psOpt := context.String("page-server"); psOpt != "" {
Expand All @@ -122,22 +122,22 @@ func setPageServer(context *cli.Context, options *libcontainer.CriuOpts) {
if err != nil {
fatal(errors.New("Invalid port number"))
}
options.PageServer = libcontainer.CriuPageServerInfo{
options.PageServer = libcontainer.CRIUPageServerInfo{
Address: address,
Port: int32(portInt),
}
}
}

func setManageCgroupsMode(context *cli.Context, options *libcontainer.CriuOpts) {
func setManageCgroupsMode(context *cli.Context, options *libcontainer.CRIUOpts) {
if cgOpt := context.String("manage-cgroups-mode"); cgOpt != "" {
switch cgOpt {
case "soft":
options.ManageCgroupsMode = criu.CriuCgMode_SOFT
options.ManageCgroupsMode = criurpc.CriuCgMode_SOFT
case "full":
options.ManageCgroupsMode = criu.CriuCgMode_FULL
options.ManageCgroupsMode = criurpc.CriuCgMode_FULL
case "strict":
options.ManageCgroupsMode = criu.CriuCgMode_STRICT
options.ManageCgroupsMode = criurpc.CriuCgMode_STRICT
default:
fatal(errors.New("Invalid manage cgroups mode"))
}
Expand All @@ -148,7 +148,7 @@ var namespaceMapping = map[specs.LinuxNamespaceType]int{
specs.NetworkNamespace: unix.CLONE_NEWNET,
}

func setEmptyNsMask(context *cli.Context, options *libcontainer.CriuOpts) error {
func setEmptyNsMask(context *cli.Context, options *libcontainer.CRIUOpts) error {
/* Runc doesn't manage network devices and their configuration */
nsmask := unix.CLONE_NEWNET

Expand Down
2 changes: 1 addition & 1 deletion create.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ command(s) that get executed on start, edit the args parameter of the spec. See
if err := checkArgs(context, 1, exactArgs); err != nil {
return err
}
status, err := startContainer(context, CT_ACT_CREATE, nil)
status, err := startContainer(context, actCreate, nil)
if err == nil {
// exit with the container's exit status so any external supervisor
// is notified of the exit with the correct exit status.
Expand Down
24 changes: 12 additions & 12 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ func convertLibcontainerStats(ls *libcontainer.Stats) *types.Stats {
return nil
}
var s types.Stats
s.Pids.Current = cg.PidsStats.Current
s.Pids.Limit = cg.PidsStats.Limit

s.CPU.Usage.Kernel = cg.CpuStats.CpuUsage.UsageInKernelmode
s.CPU.Usage.User = cg.CpuStats.CpuUsage.UsageInUsermode
s.CPU.Usage.Total = cg.CpuStats.CpuUsage.TotalUsage
s.CPU.Usage.Percpu = cg.CpuStats.CpuUsage.PercpuUsage
s.CPU.Usage.PercpuKernel = cg.CpuStats.CpuUsage.PercpuUsageInKernelmode
s.CPU.Usage.PercpuUser = cg.CpuStats.CpuUsage.PercpuUsageInUsermode
s.CPU.Throttling.Periods = cg.CpuStats.ThrottlingData.Periods
s.CPU.Throttling.ThrottledPeriods = cg.CpuStats.ThrottlingData.ThrottledPeriods
s.CPU.Throttling.ThrottledTime = cg.CpuStats.ThrottlingData.ThrottledTime
s.Pids.Current = cg.PIDsStats.Current
s.Pids.Limit = cg.PIDsStats.Limit

s.CPU.Usage.Kernel = cg.CPUStats.CPUUsage.UsageInKernelmode
s.CPU.Usage.User = cg.CPUStats.CPUUsage.UsageInUsermode
s.CPU.Usage.Total = cg.CPUStats.CPUUsage.TotalUsage
s.CPU.Usage.PerCPU = cg.CPUStats.CPUUsage.PerCPUUsage
s.CPU.Usage.PerCPUKernel = cg.CPUStats.CPUUsage.PerCPUUsageInKernelmode
s.CPU.Usage.PerCPUUser = cg.CPUStats.CPUUsage.PerCPUUsageInUsermode
s.CPU.Throttling.Periods = cg.CPUStats.ThrottlingData.Periods
s.CPU.Throttling.ThrottledPeriods = cg.CPUStats.ThrottlingData.ThrottledPeriods
s.CPU.Throttling.ThrottledTime = cg.CPUStats.ThrottlingData.ThrottledTime

s.CPUSet = types.CPUSet(cg.CPUSetStats)

Expand Down
2 changes: 1 addition & 1 deletion exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func execProcess(context *cli.Context) (int, error) {
consoleSocket: context.String("console-socket"),
detach: context.Bool("detach"),
pidFile: context.String("pid-file"),
action: CT_ACT_RUN,
action: actRun,
init: false,
preserveFDs: context.Int("preserve-fds"),
subCgroupPaths: cgPaths,
Expand Down
4 changes: 2 additions & 2 deletions libcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ config := &configs.Config{
Flags: defaultMountFlags | unix.MS_RDONLY,
},
},
UidMappings: []configs.IDMap{
UIDMappings: []configs.IDMap{
{
ContainerID: 0,
HostID: 1000,
Size: 65536,
},
},
GidMappings: []configs.IDMap{
GIDMappings: []configs.IDMap{
{
ContainerID: 0,
HostID: 1000,
Expand Down
2 changes: 1 addition & 1 deletion libcontainer/capabilities/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (c *Caps) ApplyBoundingSet() error {
return c.pid.Apply(capability.BOUNDING)
}

// Apply sets all the capabilities for the current process in the config.
// ApplyCaps sets all the capabilities for the current process in the config.
func (c *Caps) ApplyCaps() error {
c.pid.Clear(allCapabilityTypes)
for _, g := range capTypes {
Expand Down
2 changes: 1 addition & 1 deletion libcontainer/cgroups/devices/devices_emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func EmulatorFromList(list io.Reader) (*Emulator, error) {
// This function is the sole reason for all of Emulator -- to allow us
// to figure out how to update a containers' cgroups without causing spurious
// device errors (if possible).
func (source *Emulator) Transition(target *Emulator) ([]*devices.Rule, error) {
func (source *Emulator) Transition(target *Emulator) ([]*devices.Rule, error) { //nolint:revive // ignore receiver name should be consistent
var transitionRules []*devices.Rule
oldRules := source.rules

Expand Down
18 changes: 9 additions & 9 deletions libcontainer/cgroups/ebpf/ebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func findAttachedCgroupDeviceFilters(dirFd int) ([]*ebpf.Program, error) {
size := 64
retries := 0
for retries < 10 {
progIds := make([]uint32, size)
progIDs := make([]uint32, size)
query := bpfAttrQuery{
TargetFd: uint32(dirFd),
AttachType: uint32(unix.BPF_CGROUP_DEVICE),
ProgIds: uint64(uintptr(unsafe.Pointer(&progIds[0]))),
ProgCnt: uint32(len(progIds)),
ProgIds: uint64(uintptr(unsafe.Pointer(&progIDs[0]))),
ProgCnt: uint32(len(progIDs)),
}

// Fetch the list of program ids.
Expand All @@ -58,10 +58,10 @@ func findAttachedCgroupDeviceFilters(dirFd int) ([]*ebpf.Program, error) {
}

// Convert the ids to program handles.
progIds = progIds[:size]
programs := make([]*ebpf.Program, 0, len(progIds))
for _, progId := range progIds {
program, err := ebpf.NewProgramFromID(ebpf.ProgramID(progId))
progIDs = progIDs[:size]
programs := make([]*ebpf.Program, 0, len(progIDs))
for _, progID := range progIDs {
program, err := ebpf.NewProgramFromID(ebpf.ProgramID(progID))
if err != nil {
// We skip over programs that give us -EACCES or -EPERM. This
// is necessary because there may be BPF programs that have
Expand All @@ -73,14 +73,14 @@ func findAttachedCgroupDeviceFilters(dirFd int) ([]*ebpf.Program, error) {
// programs (and stops runc from breaking on distributions with
// very strict SELinux policies).
if errors.Is(err, os.ErrPermission) {
logrus.Debugf("ignoring existing CGROUP_DEVICE program (prog_id=%v) which cannot be accessed by runc -- likely due to LSM policy: %v", progId, err)
logrus.Debugf("ignoring existing CGROUP_DEVICE program (prog_id=%v) which cannot be accessed by runc -- likely due to LSM policy: %v", progID, err)
continue
}
return nil, fmt.Errorf("cannot fetch program from id: %w", err)
}
programs = append(programs, program)
}
runtime.KeepAlive(progIds)
runtime.KeepAlive(progIDs)
return programs, nil
}

Expand Down
2 changes: 1 addition & 1 deletion libcontainer/cgroups/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var (
// TestMode is set to true by unit tests that need "fake" cgroupfs.
TestMode bool

cgroupFd int = -1
cgroupFd = -1
prepOnce sync.Once
prepErr error
resolveFlags uint64
Expand Down
40 changes: 20 additions & 20 deletions libcontainer/cgroups/fs/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
"golang.org/x/sys/unix"
)

type CpuGroup struct{}
type CPUGroup struct{}

func (s *CpuGroup) Name() string {
func (s *CPUGroup) Name() string {
return "cpu"
}

func (s *CpuGroup) Apply(path string, r *configs.Resources, pid int) error {
func (s *CPUGroup) Apply(path string, r *configs.Resources, pid int) error {
if err := os.MkdirAll(path, 0o755); err != nil {
return err
}
Expand All @@ -34,23 +34,23 @@ func (s *CpuGroup) Apply(path string, r *configs.Resources, pid int) error {
return cgroups.WriteCgroupProc(path, pid)
}

func (s *CpuGroup) SetRtSched(path string, r *configs.Resources) error {
if r.CpuRtPeriod != 0 {
if err := cgroups.WriteFile(path, "cpu.rt_period_us", strconv.FormatUint(r.CpuRtPeriod, 10)); err != nil {
func (s *CPUGroup) SetRtSched(path string, r *configs.Resources) error {
if r.CPURtPeriod != 0 {
if err := cgroups.WriteFile(path, "cpu.rt_period_us", strconv.FormatUint(r.CPURtPeriod, 10)); err != nil {
return err
}
}
if r.CpuRtRuntime != 0 {
if err := cgroups.WriteFile(path, "cpu.rt_runtime_us", strconv.FormatInt(r.CpuRtRuntime, 10)); err != nil {
if r.CPURtRuntime != 0 {
if err := cgroups.WriteFile(path, "cpu.rt_runtime_us", strconv.FormatInt(r.CPURtRuntime, 10)); err != nil {
return err
}
}
return nil
}

func (s *CpuGroup) Set(path string, r *configs.Resources) error {
if r.CpuShares != 0 {
shares := r.CpuShares
func (s *CPUGroup) Set(path string, r *configs.Resources) error {
if r.CPUShares != 0 {
shares := r.CPUShares
if err := cgroups.WriteFile(path, "cpu.shares", strconv.FormatUint(shares, 10)); err != nil {
return err
}
Expand All @@ -68,24 +68,24 @@ func (s *CpuGroup) Set(path string, r *configs.Resources) error {
}

var period string
if r.CpuPeriod != 0 {
period = strconv.FormatUint(r.CpuPeriod, 10)
if r.CPUPeriod != 0 {
period = strconv.FormatUint(r.CPUPeriod, 10)
if err := cgroups.WriteFile(path, "cpu.cfs_period_us", period); err != nil {
// Sometimes when the period to be set is smaller
// than the current one, it is rejected by the kernel
// (EINVAL) as old_quota/new_period exceeds the parent
// cgroup quota limit. If this happens and the quota is
// going to be set, ignore the error for now and retry
// after setting the quota.
if !errors.Is(err, unix.EINVAL) || r.CpuQuota == 0 {
if !errors.Is(err, unix.EINVAL) || r.CPUQuota == 0 {
return err
}
} else {
period = ""
}
}
if r.CpuQuota != 0 {
if err := cgroups.WriteFile(path, "cpu.cfs_quota_us", strconv.FormatInt(r.CpuQuota, 10)); err != nil {
if r.CPUQuota != 0 {
if err := cgroups.WriteFile(path, "cpu.cfs_quota_us", strconv.FormatInt(r.CPUQuota, 10)); err != nil {
return err
}
if period != "" {
Expand All @@ -97,7 +97,7 @@ func (s *CpuGroup) Set(path string, r *configs.Resources) error {
return s.SetRtSched(path, r)
}

func (s *CpuGroup) GetStats(path string, stats *cgroups.Stats) error {
func (s *CPUGroup) GetStats(path string, stats *cgroups.Stats) error {
const file = "cpu.stat"
f, err := cgroups.OpenFile(path, file, os.O_RDONLY)
if err != nil {
Expand All @@ -116,13 +116,13 @@ func (s *CpuGroup) GetStats(path string, stats *cgroups.Stats) error {
}
switch t {
case "nr_periods":
stats.CpuStats.ThrottlingData.Periods = v
stats.CPUStats.ThrottlingData.Periods = v

case "nr_throttled":
stats.CpuStats.ThrottlingData.ThrottledPeriods = v
stats.CPUStats.ThrottlingData.ThrottledPeriods = v

case "throttled_time":
stats.CpuStats.ThrottlingData.ThrottledTime = v
stats.CPUStats.ThrottlingData.ThrottledTime = v
}
}
return nil
Expand Down
28 changes: 14 additions & 14 deletions libcontainer/cgroups/fs/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func TestCpuSetShares(t *testing.T) {
})

r := &configs.Resources{
CpuShares: sharesAfter,
CPUShares: sharesAfter,
}
cpu := &CpuGroup{}
cpu := &CPUGroup{}
if err := cpu.Set(path, r); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -61,12 +61,12 @@ func TestCpuSetBandWidth(t *testing.T) {
})

r := &configs.Resources{
CpuQuota: quotaAfter,
CpuPeriod: periodAfter,
CpuRtRuntime: rtRuntimeAfter,
CpuRtPeriod: rtPeriodAfter,
CPUQuota: quotaAfter,
CPUPeriod: periodAfter,
CPURtRuntime: rtRuntimeAfter,
CPURtPeriod: rtPeriodAfter,
}
cpu := &CpuGroup{}
cpu := &CPUGroup{}
if err := cpu.Set(path, r); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestCpuStats(t *testing.T) {
"cpu.stat": cpuStatContent,
})

cpu := &CpuGroup{}
cpu := &CPUGroup{}
actualStats := *cgroups.NewStats()
err := cpu.GetStats(path, &actualStats)
if err != nil {
Expand All @@ -132,13 +132,13 @@ func TestCpuStats(t *testing.T) {
ThrottledTime: throttledTime,
}

expectThrottlingDataEquals(t, expectedStats, actualStats.CpuStats.ThrottlingData)
expectThrottlingDataEquals(t, expectedStats, actualStats.CPUStats.ThrottlingData)
}

func TestNoCpuStatFile(t *testing.T) {
path := tempDir(t, "cpu")

cpu := &CpuGroup{}
cpu := &CPUGroup{}
actualStats := *cgroups.NewStats()
err := cpu.GetStats(path, &actualStats)
if err != nil {
Expand All @@ -156,7 +156,7 @@ func TestInvalidCpuStat(t *testing.T) {
"cpu.stat": cpuStatContent,
})

cpu := &CpuGroup{}
cpu := &CPUGroup{}
actualStats := *cgroups.NewStats()
err := cpu.GetStats(path, &actualStats)
if err == nil {
Expand All @@ -180,10 +180,10 @@ func TestCpuSetRtSchedAtApply(t *testing.T) {
})

r := &configs.Resources{
CpuRtRuntime: rtRuntimeAfter,
CpuRtPeriod: rtPeriodAfter,
CPURtRuntime: rtRuntimeAfter,
CPURtPeriod: rtPeriodAfter,
}
cpu := &CpuGroup{}
cpu := &CPUGroup{}

if err := cpu.Apply(path, r, 1234); err != nil {
t.Fatal(err)
Expand Down
Loading