From 9695867521f7ab9c846f67f2a3d62e2e62476e0d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 8 Jun 2021 17:18:37 +0200 Subject: [PATCH] Rename variables to have correct capitalization libcontainer/user/lookup_unix.go:31:6: var-naming: func LookupUid should be LookupUID (revive) libcontainer/user/user.go:30:2: var-naming: struct field Uid should be UID (revive) libcontainer/user/user.go:214:2: var-naming: struct field Uid should be UID (revive) libcontainer/devices/device.go:23:2: var-naming: struct field Uid should be UID (revive) libcontainer/configs/cgroup_linux.go:60:2: var-naming: struct field CpuShares should be CPUShares (revive) libcontainer/configs/cgroup_linux.go:63:2: var-naming: struct field CpuQuota should be CPUQuota (revive) libcontainer/configs/cgroup_linux.go:66:2: var-naming: struct field CpuPeriod should be CPUPeriod (revive) libcontainer/configs/cgroup_linux.go:69:2: var-naming: struct field CpuRtRuntime should be CPURtRuntime (revive) libcontainer/configs/cgroup_linux.go:72:2: var-naming: struct field CpuRtPeriod should be CPURtPeriod (revive) libcontainer/configs/cgroup_linux.go:125:2: var-naming: struct field CpuWeight should be CPUWeight (revive) libcontainer/configs/config.go:159:2: var-naming: struct field UidMappings should be UIDMappings (revive) libcontainer/cgroups/stats.go:16:6: var-naming: type CpuUsage should be CPUUsage (revive) libcontainer/cgroups/stats.go:37:6: var-naming: type CpuStats should be CPUStats (revive) libcontainer/cgroups/stats.go:38:2: var-naming: struct field CpuUsage should be CPUUsage (revive) libcontainer/cgroups/stats.go:150:2: var-naming: struct field CpuStats should be CPUStats (revive) types/events.go:60:6: var-naming: type CpuUsage should be CPUUsage (revive) types/events.go:70:6: var-naming: type Cpu should be CPU (revive) libcontainer/cgroups/fs/cpu.go:16:6: var-naming: type CpuGroup should be CPUGroup (revive) libcontainer/error.go:12:2: var-naming: const IdInUse should be IDInUse (revive) libcontainer/error.go:13:2: var-naming: const InvalidIdFormat should be InvalidIDFormat (revive) libcontainer/criu_opts_linux.go:20:2: var-naming: struct field TcpEstablished should be TCPEstablished (revive) libcontainer/init_linux.go:65:2: var-naming: struct field ContainerId should be ContainerID (revive) Signed-off-by: Sebastiaan van Stijn --- checkpoint.go | 8 +- events.go | 24 ++-- libcontainer/README.md | 4 +- libcontainer/cgroups/fs/cpu.go | 40 +++--- libcontainer/cgroups/fs/cpu_test.go | 28 ++--- libcontainer/cgroups/fs/cpuacct.go | 12 +- libcontainer/cgroups/fs/cpuacct_test.go | 24 ++-- libcontainer/cgroups/fs/cpuset.go | 8 +- libcontainer/cgroups/fs/cpuset_test.go | 4 +- libcontainer/cgroups/fs/fs.go | 2 +- libcontainer/cgroups/fs/fs_test.go | 2 +- libcontainer/cgroups/fs/memory.go | 2 +- libcontainer/cgroups/fs/pids.go | 10 +- libcontainer/cgroups/fs/pids_test.go | 20 +-- libcontainer/cgroups/fs2/cpu.go | 26 ++-- libcontainer/cgroups/fs2/cpuset.go | 16 +-- libcontainer/cgroups/fs2/create.go | 2 +- libcontainer/cgroups/fs2/fs2.go | 2 +- libcontainer/cgroups/fs2/pids.go | 12 +- libcontainer/cgroups/stats.go | 20 +-- libcontainer/cgroups/systemd/systemd_test.go | 4 +- libcontainer/cgroups/systemd/v1.go | 14 +-- libcontainer/cgroups/systemd/v2.go | 12 +- libcontainer/configs/cgroup_linux.go | 22 ++-- libcontainer/configs/config.go | 12 +- libcontainer/configs/config_linux.go | 8 +- libcontainer/configs/config_linux_test.go | 4 +- libcontainer/configs/validate/rootless.go | 8 +- .../configs/validate/rootless_test.go | 20 +-- libcontainer/configs/validate/validator.go | 2 +- .../configs/validate/validator_test.go | 2 +- libcontainer/container_linux.go | 104 +++++++-------- libcontainer/criu_opts_linux.go | 8 +- libcontainer/devices/device.go | 8 +- libcontainer/devices/device_unix.go | 4 +- libcontainer/factory.go | 2 +- libcontainer/factory_linux.go | 48 +++---- libcontainer/init_linux.go | 20 +-- libcontainer/integration/checkpoint_test.go | 4 +- libcontainer/integration/exec_test.go | 18 +-- libcontainer/integration/execin_test.go | 6 +- libcontainer/integration/template_test.go | 4 +- libcontainer/intelrdt/cmt_test.go | 2 +- libcontainer/intelrdt/mbm_test.go | 2 +- libcontainer/intelrdt/monitoring_test.go | 4 +- libcontainer/process_linux.go | 2 +- libcontainer/rootfs_linux.go | 2 +- libcontainer/setns_init_linux.go | 2 +- libcontainer/specconv/spec_linux.go | 58 ++++----- libcontainer/specconv/spec_linux_test.go | 6 +- libcontainer/standard_init_linux.go | 2 +- libcontainer/system/proc.go | 2 +- libcontainer/user/lookup_unix.go | 12 +- libcontainer/user/user.go | 60 ++++----- libcontainer/user/user_test.go | 118 +++++++++--------- list.go | 2 +- restore.go | 6 +- types/events.go | 14 +-- update.go | 22 ++-- utils_linux.go | 10 +- 60 files changed, 463 insertions(+), 463 deletions(-) diff --git a/checkpoint.go b/checkpoint.go index 556b19cd6e9..ea165c14450 100644 --- a/checkpoint.go +++ b/checkpoint.go @@ -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 != "" { @@ -122,14 +122,14 @@ 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": @@ -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 diff --git a/events.go b/events.go index 6cdc01cdd3a..e6881cfde14 100644 --- a/events.go +++ b/events.go @@ -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) diff --git a/libcontainer/README.md b/libcontainer/README.md index 13eee49d4b9..8ab3fb16b38 100644 --- a/libcontainer/README.md +++ b/libcontainer/README.md @@ -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, diff --git a/libcontainer/cgroups/fs/cpu.go b/libcontainer/cgroups/fs/cpu.go index 6c79f899b48..1cbf24f1c58 100644 --- a/libcontainer/cgroups/fs/cpu.go +++ b/libcontainer/cgroups/fs/cpu.go @@ -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 } @@ -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 } @@ -68,8 +68,8 @@ 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 @@ -77,15 +77,15 @@ func (s *CpuGroup) Set(path string, r *configs.Resources) error { // 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 != "" { @@ -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 { @@ -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 diff --git a/libcontainer/cgroups/fs/cpu_test.go b/libcontainer/cgroups/fs/cpu_test.go index bbdd45a7118..ef18f1617a4 100644 --- a/libcontainer/cgroups/fs/cpu_test.go +++ b/libcontainer/cgroups/fs/cpu_test.go @@ -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) } @@ -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) } @@ -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 { @@ -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 { @@ -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 { @@ -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) diff --git a/libcontainer/cgroups/fs/cpuacct.go b/libcontainer/cgroups/fs/cpuacct.go index 44b53f39ce7..e673c6b7d7e 100644 --- a/libcontainer/cgroups/fs/cpuacct.go +++ b/libcontainer/cgroups/fs/cpuacct.go @@ -66,12 +66,12 @@ func (s *CpuacctGroup) GetStats(path string, stats *cgroups.Stats) error { return err } - stats.CpuStats.CpuUsage.TotalUsage = totalUsage - stats.CpuStats.CpuUsage.PercpuUsage = percpuUsage - stats.CpuStats.CpuUsage.PercpuUsageInKernelmode = percpuUsageInKernelmode - stats.CpuStats.CpuUsage.PercpuUsageInUsermode = percpuUsageInUsermode - stats.CpuStats.CpuUsage.UsageInUsermode = userModeUsage - stats.CpuStats.CpuUsage.UsageInKernelmode = kernelModeUsage + stats.CPUStats.CPUUsage.TotalUsage = totalUsage + stats.CPUStats.CPUUsage.PerCPUUsage = percpuUsage + stats.CPUStats.CPUUsage.PerCPUUsageInKernelmode = percpuUsageInKernelmode + stats.CPUStats.CPUUsage.PerCPUUsageInUsermode = percpuUsageInUsermode + stats.CPUStats.CPUUsage.UsageInUsermode = userModeUsage + stats.CPUStats.CPUUsage.UsageInKernelmode = kernelModeUsage return nil } diff --git a/libcontainer/cgroups/fs/cpuacct_test.go b/libcontainer/cgroups/fs/cpuacct_test.go index 70b237a0b61..1f0d12f48eb 100644 --- a/libcontainer/cgroups/fs/cpuacct_test.go +++ b/libcontainer/cgroups/fs/cpuacct_test.go @@ -39,17 +39,17 @@ func TestCpuacctStats(t *testing.T) { t.Fatal(err) } - expectedStats := cgroups.CpuUsage{ + expectedStats := cgroups.CPUUsage{ TotalUsage: uint64(12262454190222160), - PercpuUsage: []uint64{ + PerCPUUsage: []uint64{ 1564936537989058, 1583937096487821, 1604195415465681, 1596445226820187, 1481069084155629, 1478735613864327, 1477610593414743, 1476362015778086, }, - PercpuUsageInKernelmode: []uint64{ + PerCPUUsageInKernelmode: []uint64{ 637727786389114, 638197595421064, 638956774598358, 637985531181620, 638837766495476, 638763309884944, 640081778921247, 638716766259495, }, - PercpuUsageInUsermode: []uint64{ + PerCPUUsageInUsermode: []uint64{ 962250696038415, 981956408513304, 1002658817529022, 994937703492523, 874843781648690, 872544369885276, 870104915696359, 870202363887496, }, @@ -57,9 +57,9 @@ func TestCpuacctStats(t *testing.T) { UsageInUsermode: (uint64(452278264) * nanosecondsInSecond) / clockTicks, } - if !reflect.DeepEqual(expectedStats, actualStats.CpuStats.CpuUsage) { + if !reflect.DeepEqual(expectedStats, actualStats.CPUStats.CPUUsage) { t.Errorf("Expected CPU usage %#v but found %#v\n", - expectedStats, actualStats.CpuStats.CpuUsage) + expectedStats, actualStats.CPUStats.CPUUsage) } } @@ -78,20 +78,20 @@ func TestCpuacctStatsWithoutUsageAll(t *testing.T) { t.Fatal(err) } - expectedStats := cgroups.CpuUsage{ + expectedStats := cgroups.CPUUsage{ TotalUsage: uint64(12262454190222160), - PercpuUsage: []uint64{ + PerCPUUsage: []uint64{ 1564936537989058, 1583937096487821, 1604195415465681, 1596445226820187, 1481069084155629, 1478735613864327, 1477610593414743, 1476362015778086, }, - PercpuUsageInKernelmode: []uint64{}, - PercpuUsageInUsermode: []uint64{}, + PerCPUUsageInKernelmode: []uint64{}, + PerCPUUsageInUsermode: []uint64{}, UsageInKernelmode: (uint64(291429664) * nanosecondsInSecond) / clockTicks, UsageInUsermode: (uint64(452278264) * nanosecondsInSecond) / clockTicks, } - if !reflect.DeepEqual(expectedStats, actualStats.CpuStats.CpuUsage) { + if !reflect.DeepEqual(expectedStats, actualStats.CPUStats.CPUUsage) { t.Errorf("Expected CPU usage %#v but found %#v\n", - expectedStats, actualStats.CpuStats.CpuUsage) + expectedStats, actualStats.CPUStats.CPUUsage) } } diff --git a/libcontainer/cgroups/fs/cpuset.go b/libcontainer/cgroups/fs/cpuset.go index 550baa42756..9eafe599305 100644 --- a/libcontainer/cgroups/fs/cpuset.go +++ b/libcontainer/cgroups/fs/cpuset.go @@ -25,13 +25,13 @@ func (s *CpusetGroup) Apply(path string, r *configs.Resources, pid int) error { } func (s *CpusetGroup) Set(path string, r *configs.Resources) error { - if r.CpusetCpus != "" { - if err := cgroups.WriteFile(path, "cpuset.cpus", r.CpusetCpus); err != nil { + if r.CPUSetCPUs != "" { + if err := cgroups.WriteFile(path, "cpuset.cpus", r.CPUSetCPUs); err != nil { return err } } - if r.CpusetMems != "" { - if err := cgroups.WriteFile(path, "cpuset.mems", r.CpusetMems); err != nil { + if r.CPUSetMems != "" { + if err := cgroups.WriteFile(path, "cpuset.mems", r.CPUSetMems); err != nil { return err } } diff --git a/libcontainer/cgroups/fs/cpuset_test.go b/libcontainer/cgroups/fs/cpuset_test.go index 8933b3ca351..19cd85f0424 100644 --- a/libcontainer/cgroups/fs/cpuset_test.go +++ b/libcontainer/cgroups/fs/cpuset_test.go @@ -50,7 +50,7 @@ func TestCPUSetSetCpus(t *testing.T) { }) r := &configs.Resources{ - CpusetCpus: cpusAfter, + CPUSetCPUs: cpusAfter, } cpuset := &CpusetGroup{} if err := cpuset.Set(path, r); err != nil { @@ -79,7 +79,7 @@ func TestCPUSetSetMems(t *testing.T) { }) r := &configs.Resources{ - CpusetMems: memsAfter, + CPUSetMems: memsAfter, } cpuset := &CpusetGroup{} if err := cpuset.Set(path, r); err != nil { diff --git a/libcontainer/cgroups/fs/fs.go b/libcontainer/cgroups/fs/fs.go index fb4fcc7f75b..1cd1cd2fb23 100644 --- a/libcontainer/cgroups/fs/fs.go +++ b/libcontainer/cgroups/fs/fs.go @@ -17,7 +17,7 @@ var subsystems = []subsystem{ &CpusetGroup{}, &DevicesGroup{}, &MemoryGroup{}, - &CpuGroup{}, + &CPUGroup{}, &CpuacctGroup{}, &PidsGroup{}, &BlkioGroup{}, diff --git a/libcontainer/cgroups/fs/fs_test.go b/libcontainer/cgroups/fs/fs_test.go index 01293ad1267..9dcd881b3e4 100644 --- a/libcontainer/cgroups/fs/fs_test.go +++ b/libcontainer/cgroups/fs/fs_test.go @@ -44,7 +44,7 @@ func BenchmarkGetStats(b *testing.B) { b.Fatal(err) } } - if st.CpuStats.CpuUsage.TotalUsage != 0 { + if st.CPUStats.CPUUsage.TotalUsage != 0 { b.Fatalf("stats: %+v", st) } } diff --git a/libcontainer/cgroups/fs/memory.go b/libcontainer/cgroups/fs/memory.go index e374c43b81a..8186f6d38b2 100644 --- a/libcontainer/cgroups/fs/memory.go +++ b/libcontainer/cgroups/fs/memory.go @@ -115,7 +115,7 @@ func (s *MemoryGroup) Set(path string, r *configs.Resources) error { } } - if r.OomKillDisable { + if r.OOMKillDisable { if err := cgroups.WriteFile(path, "memory.oom_control", "1"); err != nil { return err } diff --git a/libcontainer/cgroups/fs/pids.go b/libcontainer/cgroups/fs/pids.go index 1f13532a5ad..85e609ea14a 100644 --- a/libcontainer/cgroups/fs/pids.go +++ b/libcontainer/cgroups/fs/pids.go @@ -20,12 +20,12 @@ func (s *PidsGroup) Apply(path string, _ *configs.Resources, pid int) error { } func (s *PidsGroup) Set(path string, r *configs.Resources) error { - if r.PidsLimit != 0 { + if r.PIDsLimit != 0 { // "max" is the fallback value. limit := "max" - if r.PidsLimit > 0 { - limit = strconv.FormatInt(r.PidsLimit, 10) + if r.PIDsLimit > 0 { + limit = strconv.FormatInt(r.PIDsLimit, 10) } if err := cgroups.WriteFile(path, "pids.max", limit); err != nil { @@ -56,7 +56,7 @@ func (s *PidsGroup) GetStats(path string, stats *cgroups.Stats) error { max = 0 } - stats.PidsStats.Current = current - stats.PidsStats.Limit = max + stats.PIDsStats.Current = current + stats.PIDsStats.Limit = max return nil } diff --git a/libcontainer/cgroups/fs/pids_test.go b/libcontainer/cgroups/fs/pids_test.go index 9d9a7ce8f18..259eae7b024 100644 --- a/libcontainer/cgroups/fs/pids_test.go +++ b/libcontainer/cgroups/fs/pids_test.go @@ -22,7 +22,7 @@ func TestPidsSetMax(t *testing.T) { }) r := &configs.Resources{ - PidsLimit: maxLimited, + PIDsLimit: maxLimited, } pids := &PidsGroup{} if err := pids.Set(path, r); err != nil { @@ -46,7 +46,7 @@ func TestPidsSetUnlimited(t *testing.T) { }) r := &configs.Resources{ - PidsLimit: maxUnlimited, + PIDsLimit: maxUnlimited, } pids := &PidsGroup{} if err := pids.Set(path, r); err != nil { @@ -76,12 +76,12 @@ func TestPidsStats(t *testing.T) { t.Fatal(err) } - if stats.PidsStats.Current != 1337 { - t.Fatalf("Expected %d, got %d for pids.current", 1337, stats.PidsStats.Current) + if stats.PIDsStats.Current != 1337 { + t.Fatalf("Expected %d, got %d for pids.current", 1337, stats.PIDsStats.Current) } - if stats.PidsStats.Limit != maxLimited { - t.Fatalf("Expected %d, got %d for pids.max", maxLimited, stats.PidsStats.Limit) + if stats.PIDsStats.Limit != maxLimited { + t.Fatalf("Expected %d, got %d for pids.max", maxLimited, stats.PIDsStats.Limit) } } @@ -99,11 +99,11 @@ func TestPidsStatsUnlimited(t *testing.T) { t.Fatal(err) } - if stats.PidsStats.Current != 4096 { - t.Fatalf("Expected %d, got %d for pids.current", 4096, stats.PidsStats.Current) + if stats.PIDsStats.Current != 4096 { + t.Fatalf("Expected %d, got %d for pids.current", 4096, stats.PIDsStats.Current) } - if stats.PidsStats.Limit != 0 { - t.Fatalf("Expected %d, got %d for pids.max", 0, stats.PidsStats.Limit) + if stats.PIDsStats.Limit != 0 { + t.Fatalf("Expected %d, got %d for pids.max", 0, stats.PIDsStats.Limit) } } diff --git a/libcontainer/cgroups/fs2/cpu.go b/libcontainer/cgroups/fs2/cpu.go index d0c522df849..96ff657838e 100644 --- a/libcontainer/cgroups/fs2/cpu.go +++ b/libcontainer/cgroups/fs2/cpu.go @@ -11,7 +11,7 @@ import ( ) func isCPUSet(r *configs.Resources) bool { - return r.CpuWeight != 0 || r.CpuQuota != 0 || r.CpuPeriod != 0 + return r.CPUWeight != 0 || r.CPUQuota != 0 || r.CPUPeriod != 0 } func setCPU(dirPath string, r *configs.Resources) error { @@ -20,18 +20,18 @@ func setCPU(dirPath string, r *configs.Resources) error { } // NOTE: .CpuShares is not used here. Conversion is the caller's responsibility. - if r.CpuWeight != 0 { - if err := cgroups.WriteFile(dirPath, "cpu.weight", strconv.FormatUint(r.CpuWeight, 10)); err != nil { + if r.CPUWeight != 0 { + if err := cgroups.WriteFile(dirPath, "cpu.weight", strconv.FormatUint(r.CPUWeight, 10)); err != nil { return err } } - if r.CpuQuota != 0 || r.CpuPeriod != 0 { + if r.CPUQuota != 0 || r.CPUPeriod != 0 { str := "max" - if r.CpuQuota > 0 { - str = strconv.FormatInt(r.CpuQuota, 10) + if r.CPUQuota > 0 { + str = strconv.FormatInt(r.CPUQuota, 10) } - period := r.CpuPeriod + period := r.CPUPeriod if period == 0 { // This default value is documented in // https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html @@ -62,22 +62,22 @@ func statCPU(dirPath string, stats *cgroups.Stats) error { } switch t { case "usage_usec": - stats.CpuStats.CpuUsage.TotalUsage = v * 1000 + stats.CPUStats.CPUUsage.TotalUsage = v * 1000 case "user_usec": - stats.CpuStats.CpuUsage.UsageInUsermode = v * 1000 + stats.CPUStats.CPUUsage.UsageInUsermode = v * 1000 case "system_usec": - stats.CpuStats.CpuUsage.UsageInKernelmode = v * 1000 + stats.CPUStats.CPUUsage.UsageInKernelmode = v * 1000 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_usec": - stats.CpuStats.ThrottlingData.ThrottledTime = v * 1000 + stats.CPUStats.ThrottlingData.ThrottledTime = v * 1000 } } if err := sc.Err(); err != nil { diff --git a/libcontainer/cgroups/fs2/cpuset.go b/libcontainer/cgroups/fs2/cpuset.go index 16c45bad8f0..31c5d7fcde8 100644 --- a/libcontainer/cgroups/fs2/cpuset.go +++ b/libcontainer/cgroups/fs2/cpuset.go @@ -5,22 +5,22 @@ import ( "github.com/opencontainers/runc/libcontainer/configs" ) -func isCpusetSet(r *configs.Resources) bool { - return r.CpusetCpus != "" || r.CpusetMems != "" +func isCPUSetSet(r *configs.Resources) bool { + return r.CPUSetCPUs != "" || r.CPUSetMems != "" } -func setCpuset(dirPath string, r *configs.Resources) error { - if !isCpusetSet(r) { +func setCPUSet(dirPath string, r *configs.Resources) error { + if !isCPUSetSet(r) { return nil } - if r.CpusetCpus != "" { - if err := cgroups.WriteFile(dirPath, "cpuset.cpus", r.CpusetCpus); err != nil { + if r.CPUSetCPUs != "" { + if err := cgroups.WriteFile(dirPath, "cpuset.cpus", r.CPUSetCPUs); err != nil { return err } } - if r.CpusetMems != "" { - if err := cgroups.WriteFile(dirPath, "cpuset.mems", r.CpusetMems); err != nil { + if r.CPUSetMems != "" { + if err := cgroups.WriteFile(dirPath, "cpuset.mems", r.CPUSetMems); err != nil { return err } } diff --git a/libcontainer/cgroups/fs2/create.go b/libcontainer/cgroups/fs2/create.go index a5e044aa677..03e4fa1017a 100644 --- a/libcontainer/cgroups/fs2/create.go +++ b/libcontainer/cgroups/fs2/create.go @@ -51,7 +51,7 @@ func needAnyControllers(r *configs.Resources) (bool, error) { if isCPUSet(r) && have("cpu") { return true, nil } - if isCpusetSet(r) && have("cpuset") { + if isCPUSetSet(r) && have("cpuset") { return true, nil } if isHugeTlbSet(r) && have("hugetlb") { diff --git a/libcontainer/cgroups/fs2/fs2.go b/libcontainer/cgroups/fs2/fs2.go index c4a45df199e..fd428d3d8f5 100644 --- a/libcontainer/cgroups/fs2/fs2.go +++ b/libcontainer/cgroups/fs2/fs2.go @@ -176,7 +176,7 @@ func (m *manager) Set(r *configs.Resources) error { return err } // cpuset (since kernel 5.0) - if err := setCpuset(m.dirPath, r); err != nil { + if err := setCPUSet(m.dirPath, r); err != nil { return err } // hugetlb (since kernel 5.6) diff --git a/libcontainer/cgroups/fs2/pids.go b/libcontainer/cgroups/fs2/pids.go index c8c4a365894..907aea9ee82 100644 --- a/libcontainer/cgroups/fs2/pids.go +++ b/libcontainer/cgroups/fs2/pids.go @@ -14,14 +14,14 @@ import ( ) func isPidsSet(r *configs.Resources) bool { - return r.PidsLimit != 0 + return r.PIDsLimit != 0 } func setPids(dirPath string, r *configs.Resources) error { if !isPidsSet(r) { return nil } - if val := numToStr(r.PidsLimit); val != "" { + if val := numToStr(r.PIDsLimit); val != "" { if err := cgroups.WriteFile(dirPath, "pids.max", val); err != nil { return err } @@ -41,8 +41,8 @@ func statPidsFromCgroupProcs(dirPath string, stats *cgroups.Stats) error { return err } pids := strings.Count(contents, "\n") - stats.PidsStats.Current = uint64(pids) - stats.PidsStats.Limit = 0 + stats.PIDsStats.Current = uint64(pids) + stats.PIDsStats.Limit = 0 return nil } @@ -66,7 +66,7 @@ func statPids(dirPath string, stats *cgroups.Stats) error { max = 0 } - stats.PidsStats.Current = current - stats.PidsStats.Limit = max + stats.PIDsStats.Current = current + stats.PIDsStats.Limit = max return nil } diff --git a/libcontainer/cgroups/stats.go b/libcontainer/cgroups/stats.go index 40a81dd5a86..b0779b166d2 100644 --- a/libcontainer/cgroups/stats.go +++ b/libcontainer/cgroups/stats.go @@ -9,21 +9,21 @@ type ThrottlingData struct { ThrottledTime uint64 `json:"throttled_time,omitempty"` } -// CpuUsage denotes the usage of a CPU. +// CPUUsage denotes the usage of a CPU. // All CPU stats are aggregate since container inception. -type CpuUsage struct { +type CPUUsage struct { // Total CPU time consumed. // Units: nanoseconds. TotalUsage uint64 `json:"total_usage,omitempty"` // Total CPU time consumed per core. // Units: nanoseconds. - PercpuUsage []uint64 `json:"percpu_usage,omitempty"` + PerCPUUsage []uint64 `json:"percpu_usage,omitempty"` // CPU time consumed per core in kernel mode // Units: nanoseconds. - PercpuUsageInKernelmode []uint64 `json:"percpu_usage_in_kernelmode"` + PerCPUUsageInKernelmode []uint64 `json:"percpu_usage_in_kernelmode"` // CPU time consumed per core in user mode // Units: nanoseconds. - PercpuUsageInUsermode []uint64 `json:"percpu_usage_in_usermode"` + PerCPUUsageInUsermode []uint64 `json:"percpu_usage_in_usermode"` // Time spent by tasks of the cgroup in kernel mode. // Units: nanoseconds. UsageInKernelmode uint64 `json:"usage_in_kernelmode"` @@ -32,8 +32,8 @@ type CpuUsage struct { UsageInUsermode uint64 `json:"usage_in_usermode"` } -type CpuStats struct { - CpuUsage CpuUsage `json:"cpu_usage,omitempty"` +type CPUStats struct { + CPUUsage CPUUsage `json:"cpu_usage,omitempty"` ThrottlingData ThrottlingData `json:"throttling_data,omitempty"` } @@ -109,7 +109,7 @@ type PageStats struct { Nodes map[uint8]uint64 `json:"nodes,omitempty"` } -type PidsStats struct { +type PIDsStats struct { // number of pids in the cgroup Current uint64 `json:"current,omitempty"` // active pids hard limit @@ -156,10 +156,10 @@ type RdmaStats struct { } type Stats struct { - CpuStats CpuStats `json:"cpu_stats,omitempty"` + CPUStats CPUStats `json:"cpu_stats,omitempty"` CPUSetStats CPUSetStats `json:"cpuset_stats,omitempty"` MemoryStats MemoryStats `json:"memory_stats,omitempty"` - PidsStats PidsStats `json:"pids_stats,omitempty"` + PIDsStats PIDsStats `json:"pids_stats,omitempty"` BlkioStats BlkioStats `json:"blkio_stats,omitempty"` // the map is in the format "size of hugepage: stats of the hugepage" HugetlbStats map[string]HugetlbStats `json:"hugetlb_stats,omitempty"` diff --git a/libcontainer/cgroups/systemd/systemd_test.go b/libcontainer/cgroups/systemd/systemd_test.go index 7417bf28789..bbd1bae9336 100644 --- a/libcontainer/cgroups/systemd/systemd_test.go +++ b/libcontainer/cgroups/systemd/systemd_test.go @@ -93,7 +93,7 @@ func TestPodSkipDevicesUpdate(t *testing.T) { Parent: "system.slice", Name: podName, Resources: &configs.Resources{ - PidsLimit: 42, + PIDsLimit: 42, Memory: 32 * 1024 * 1024, SkipDevices: true, }, @@ -157,7 +157,7 @@ func TestPodSkipDevicesUpdate(t *testing.T) { // Now update the pod a few times. for i := 0; i < 42; i++ { - podConfig.Resources.PidsLimit++ + podConfig.Resources.PIDsLimit++ podConfig.Resources.Memory += 1024 * 1024 if err := pm.Set(podConfig.Resources); err != nil { t.Fatal(err) diff --git a/libcontainer/cgroups/systemd/v1.go b/libcontainer/cgroups/systemd/v1.go index 4cbf2587244..0093869089e 100644 --- a/libcontainer/cgroups/systemd/v1.go +++ b/libcontainer/cgroups/systemd/v1.go @@ -60,7 +60,7 @@ var legacySubsystems = []subsystem{ &fs.CpusetGroup{}, &fs.DevicesGroup{}, &fs.MemoryGroup{}, - &fs.CpuGroup{}, + &fs.CPUGroup{}, &fs.CpuacctGroup{}, &fs.PidsGroup{}, &fs.BlkioGroup{}, @@ -87,24 +87,24 @@ func genV1ResourcesProperties(r *configs.Resources, cm *dbusConnManager) ([]syst newProp("MemoryLimit", uint64(r.Memory))) } - if r.CpuShares != 0 { + if r.CPUShares != 0 { properties = append(properties, - newProp("CPUShares", r.CpuShares)) + newProp("CPUShares", r.CPUShares)) } - addCPUQuota(cm, &properties, r.CpuQuota, r.CpuPeriod) + addCPUQuota(cm, &properties, r.CPUQuota, r.CPUPeriod) if r.BlkioWeight != 0 { properties = append(properties, newProp("BlockIOWeight", uint64(r.BlkioWeight))) } - if r.PidsLimit > 0 || r.PidsLimit == -1 { + if r.PIDsLimit > 0 || r.PIDsLimit == -1 { properties = append(properties, - newProp("TasksMax", uint64(r.PidsLimit))) + newProp("TasksMax", uint64(r.PIDsLimit))) } - err = addCPUSet(cm, &properties, r.CpusetCpus, r.CpusetMems) + err = addCPUSet(cm, &properties, r.CPUSetCPUs, r.CPUSetMems) if err != nil { return nil, err } diff --git a/libcontainer/cgroups/systemd/v2.go b/libcontainer/cgroups/systemd/v2.go index e7573871d9a..3a97a2ac114 100644 --- a/libcontainer/cgroups/systemd/v2.go +++ b/libcontainer/cgroups/systemd/v2.go @@ -205,19 +205,19 @@ func genV2ResourcesProperties(r *configs.Resources, cm *dbusConnManager) ([]syst newProp("MemorySwapMax", uint64(swap))) } - if r.CpuWeight != 0 { + if r.CPUWeight != 0 { properties = append(properties, - newProp("CPUWeight", r.CpuWeight)) + newProp("CPUWeight", r.CPUWeight)) } - addCPUQuota(cm, &properties, r.CpuQuota, r.CpuPeriod) + addCPUQuota(cm, &properties, r.CPUQuota, r.CPUPeriod) - if r.PidsLimit > 0 || r.PidsLimit == -1 { + if r.PIDsLimit > 0 || r.PIDsLimit == -1 { properties = append(properties, - newProp("TasksMax", uint64(r.PidsLimit))) + newProp("TasksMax", uint64(r.PIDsLimit))) } - err = addCPUSet(cm, &properties, r.CpusetCpus, r.CpusetMems) + err = addCPUSet(cm, &properties, r.CPUSetCPUs, r.CPUSetMems) if err != nil { return nil, err } diff --git a/libcontainer/configs/cgroup_linux.go b/libcontainer/configs/cgroup_linux.go index 63d56a135db..c161a29e392 100644 --- a/libcontainer/configs/cgroup_linux.go +++ b/libcontainer/configs/cgroup_linux.go @@ -66,28 +66,28 @@ type Resources struct { MemorySwap int64 `json:"memory_swap"` // CPU shares (relative weight vs. other containers) - CpuShares uint64 `json:"cpu_shares"` + CPUShares uint64 `json:"cpu_shares"` // CPU hardcap limit (in usecs). Allowed cpu time in a given period. - CpuQuota int64 `json:"cpu_quota"` + CPUQuota int64 `json:"cpu_quota"` // CPU period to be used for hardcapping (in usecs). 0 to use system default. - CpuPeriod uint64 `json:"cpu_period"` + CPUPeriod uint64 `json:"cpu_period"` // How many time CPU will use in realtime scheduling (in usecs). - CpuRtRuntime int64 `json:"cpu_rt_quota"` + CPURtRuntime int64 `json:"cpu_rt_quota"` // CPU period to be used for realtime scheduling (in usecs). - CpuRtPeriod uint64 `json:"cpu_rt_period"` + CPURtPeriod uint64 `json:"cpu_rt_period"` // CPU to use - CpusetCpus string `json:"cpuset_cpus"` + CPUSetCPUs string `json:"cpuset_cpus"` // MEM to use - CpusetMems string `json:"cpuset_mems"` + CPUSetMems string `json:"cpuset_mems"` // Process limit; set <= `0' to disable limit. - PidsLimit int64 `json:"pids_limit"` + PIDsLimit int64 `json:"pids_limit"` // Specifies per cgroup weight, range is from 10 to 1000. BlkioWeight uint16 `json:"blkio_weight"` @@ -117,7 +117,7 @@ type Resources struct { HugetlbLimit []*HugepageLimit `json:"hugetlb_limit"` // Whether to disable OOM Killer - OomKillDisable bool `json:"oom_kill_disable"` + OOMKillDisable bool `json:"oom_kill_disable"` // Tuning swappiness behaviour per cgroup MemorySwappiness *uint64 `json:"memory_swappiness"` @@ -133,8 +133,8 @@ type Resources struct { // Used on cgroups v2: - // CpuWeight sets a proportional bandwidth limit. - CpuWeight uint64 `json:"cpu_weight"` + // CPUWeight sets a proportional bandwidth limit. + CPUWeight uint64 `json:"cpu_weight"` // Unified is cgroupv2-only key-value map. Unified map[string]string `json:"unified"` diff --git a/libcontainer/configs/config.go b/libcontainer/configs/config.go index c9fa838b844..489607e03ff 100644 --- a/libcontainer/configs/config.go +++ b/libcontainer/configs/config.go @@ -153,18 +153,18 @@ type Config struct { // If Rlimits are not set, the container will inherit rlimits from the parent process Rlimits []Rlimit `json:"rlimits,omitempty"` - // OomScoreAdj specifies the adjustment to be made by the kernel when calculating oom scores + // OOMScoreAdj specifies the adjustment to be made by the kernel when calculating oom scores // for a process. Valid values are between the range [-1000, '1000'], where processes with // higher scores are preferred for being killed. If it is unset then we don't touch the current // value. // More information about kernel oom score calculation here: https://lwn.net/Articles/317814/ - OomScoreAdj *int `json:"oom_score_adj,omitempty"` + OOMScoreAdj *int `json:"oom_score_adj,omitempty"` - // UidMappings is an array of User ID mappings for User Namespaces - UidMappings []IDMap `json:"uid_mappings"` + // UIDMappings is an array of User ID mappings for User Namespaces + UIDMappings []IDMap `json:"uid_mappings"` - // GidMappings is an array of Group ID mappings for User Namespaces - GidMappings []IDMap `json:"gid_mappings"` + // GIDMappings is an array of Group ID mappings for User Namespaces + GIDMappings []IDMap `json:"gid_mappings"` // MaskPaths specifies paths within the container's rootfs to mask over with a bind // mount pointing to /dev/null as to prevent reads of the file. diff --git a/libcontainer/configs/config_linux.go b/libcontainer/configs/config_linux.go index 827a2f22245..e96b0e3799a 100644 --- a/libcontainer/configs/config_linux.go +++ b/libcontainer/configs/config_linux.go @@ -13,10 +13,10 @@ var ( // different when user namespaces are enabled. func (c Config) HostUID(containerID int) (int, error) { if c.Namespaces.Contains(NEWUSER) { - if c.UidMappings == nil { + if c.UIDMappings == nil { return -1, errNoUIDMap } - id, found := c.hostIDFromMapping(containerID, c.UidMappings) + id, found := c.hostIDFromMapping(containerID, c.UIDMappings) if !found { return -1, errNoUserMap } @@ -36,10 +36,10 @@ func (c Config) HostRootUID() (int, error) { // different when user namespaces are enabled. func (c Config) HostGID(containerID int) (int, error) { if c.Namespaces.Contains(NEWUSER) { - if c.GidMappings == nil { + if c.GIDMappings == nil { return -1, errNoGIDMap } - id, found := c.hostIDFromMapping(containerID, c.GidMappings) + id, found := c.hostIDFromMapping(containerID, c.GIDMappings) if !found { return -1, errNoGroupMap } diff --git a/libcontainer/configs/config_linux_test.go b/libcontainer/configs/config_linux_test.go index 68d33e61a22..b94ffaed2c1 100644 --- a/libcontainer/configs/config_linux_test.go +++ b/libcontainer/configs/config_linux_test.go @@ -34,7 +34,7 @@ func TestHostRootUIDNoUSERNS(t *testing.T) { func TestHostRootUIDWithUSERNS(t *testing.T) { config := &Config{ Namespaces: Namespaces{{Type: NEWUSER}}, - UidMappings: []IDMap{ + UIDMappings: []IDMap{ { ContainerID: 0, HostID: 1000, @@ -67,7 +67,7 @@ func TestHostRootGIDNoUSERNS(t *testing.T) { func TestHostRootGIDWithUSERNS(t *testing.T) { config := &Config{ Namespaces: Namespaces{{Type: NEWUSER}}, - GidMappings: []IDMap{ + GIDMappings: []IDMap{ { ContainerID: 0, HostID: 1000, diff --git a/libcontainer/configs/validate/rootless.go b/libcontainer/configs/validate/rootless.go index 9a6e5eb32a3..566ad7cf8c4 100644 --- a/libcontainer/configs/validate/rootless.go +++ b/libcontainer/configs/validate/rootless.go @@ -42,10 +42,10 @@ func rootlessEUIDMappings(config *configs.Config) error { return errors.New("rootless container requires user namespaces") } - if len(config.UidMappings) == 0 { + if len(config.UIDMappings) == 0 { return errors.New("rootless containers requires at least one UID mapping") } - if len(config.GidMappings) == 0 { + if len(config.GIDMappings) == 0 { return errors.New("rootless containers requires at least one GID mapping") } return nil @@ -70,7 +70,7 @@ func rootlessEUIDMount(config *configs.Config) error { // Ignore unknown mount options. continue } - if !hasIDMapping(uid, config.UidMappings) { + if !hasIDMapping(uid, config.UIDMappings) { return errors.New("cannot specify uid= mount options for unmapped uid in rootless containers") } } @@ -82,7 +82,7 @@ func rootlessEUIDMount(config *configs.Config) error { // Ignore unknown mount options. continue } - if !hasIDMapping(gid, config.GidMappings) { + if !hasIDMapping(gid, config.GIDMappings) { return errors.New("cannot specify gid= mount options for unmapped gid in rootless containers") } } diff --git a/libcontainer/configs/validate/rootless_test.go b/libcontainer/configs/validate/rootless_test.go index 59d15575dd7..8db0ebcc9ac 100644 --- a/libcontainer/configs/validate/rootless_test.go +++ b/libcontainer/configs/validate/rootless_test.go @@ -16,14 +16,14 @@ func rootlessEUIDConfig() *configs.Config { {Type: configs.NEWUSER}, }, ), - UidMappings: []configs.IDMap{ + UIDMappings: []configs.IDMap{ { HostID: 1337, ContainerID: 0, Size: 1, }, }, - GidMappings: []configs.IDMap{ + GIDMappings: []configs.IDMap{ { HostID: 7331, ContainerID: 0, @@ -58,7 +58,7 @@ func TestValidateRootlessEUIDMappingUid(t *testing.T) { validator := New() config := rootlessEUIDConfig() - config.UidMappings = nil + config.UIDMappings = nil if err := validator.Validate(config); err == nil { t.Errorf("Expected error to occur if no uid mappings provided") } @@ -68,7 +68,7 @@ func TestValidateNonZeroEUIDMappingGid(t *testing.T) { validator := New() config := rootlessEUIDConfig() - config.GidMappings = nil + config.GIDMappings = nil if err := validator.Validate(config); err == nil { t.Errorf("Expected error to occur if no gid mappings provided") } @@ -103,15 +103,15 @@ func TestValidateRootlessEUIDMountUid(t *testing.T) { } config.Mounts[0].Data = "uid=2" - config.UidMappings[0].Size = 10 + config.UIDMappings[0].Size = 10 if err := validator.Validate(config); err != nil { - t.Errorf("Expected error to not occur when setting uid=2 in mount options and UidMapping[0].size is 10") + t.Errorf("Expected error to not occur when setting uid=2 in mount options and UIDMapping[0].size is 10") } config.Mounts[0].Data = "uid=20" - config.UidMappings[0].Size = 10 + config.UIDMappings[0].Size = 10 if err := validator.Validate(config); err == nil { - t.Errorf("Expected error to occur when setting uid=20 in mount options and UidMapping[0].size is 10") + t.Errorf("Expected error to occur when setting uid=20 in mount options and UIDMapping[0].size is 10") } } @@ -142,13 +142,13 @@ func TestValidateRootlessEUIDMountGid(t *testing.T) { } config.Mounts[0].Data = "gid=5" - config.GidMappings[0].Size = 10 + config.GIDMappings[0].Size = 10 if err := validator.Validate(config); err != nil { t.Errorf("Expected error to not occur when setting gid=5 in mount options and GidMapping[0].size is 10") } config.Mounts[0].Data = "gid=11" - config.GidMappings[0].Size = 10 + config.GIDMappings[0].Size = 10 if err := validator.Validate(config); err == nil { t.Errorf("Expected error to occur when setting gid=11 in mount options and GidMapping[0].size is 10") } diff --git a/libcontainer/configs/validate/validator.go b/libcontainer/configs/validate/validator.go index 6493124a3f2..09d9fb9073d 100644 --- a/libcontainer/configs/validate/validator.go +++ b/libcontainer/configs/validate/validator.go @@ -112,7 +112,7 @@ func (v *ConfigValidator) usernamespace(config *configs.Config) error { return errors.New("USER namespaces aren't enabled in the kernel") } } else { - if config.UidMappings != nil || config.GidMappings != nil { + if config.UIDMappings != nil || config.GIDMappings != nil { return errors.New("User namespace mappings specified, but USER namespace isn't enabled in the config") } } diff --git a/libcontainer/configs/validate/validator_test.go b/libcontainer/configs/validate/validator_test.go index 5181333fb12..62e89d0d74e 100644 --- a/libcontainer/configs/validate/validator_test.go +++ b/libcontainer/configs/validate/validator_test.go @@ -174,7 +174,7 @@ func TestValidateUsernamespaceWithoutUserNS(t *testing.T) { uidMap := configs.IDMap{ContainerID: 123} config := &configs.Config{ Rootfs: "/var", - UidMappings: []configs.IDMap{uidMap}, + UIDMappings: []configs.IDMap{uidMap}, } validator := New() diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index f6877b7429f..5195bf0b8ad 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -95,10 +95,10 @@ type Container interface { // Methods below here are platform specific // Checkpoint checkpoints the running container's state to disk using the criu(8) utility. - Checkpoint(criuOpts *CriuOpts) error + Checkpoint(criuOpts *CRIUOpts) error // Restore restores the checkpointed container to a running state using the criu(8) utility. - Restore(process *Process, criuOpts *CriuOpts) error + Restore(process *Process, criuOpts *CRIUOpts) error // If the Container state is RUNNING or CREATED, sets the Container state to PAUSING and pauses // the execution of any user processes. Asynchronously, when the container finished being paused the @@ -580,13 +580,13 @@ func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, messageSockPa mountFds[i] = stdioFdCount + len(cmd.ExtraFiles) - 1 } - mountFdsJson, err := json.Marshal(mountFds) + mountFdsJSON, err := json.Marshal(mountFds) if err != nil { return nil, fmt.Errorf("Error creating _LIBCONTAINER_MOUNT_FDS: %w", err) } cmd.Env = append(cmd.Env, - "_LIBCONTAINER_MOUNT_FDS="+string(mountFdsJson), + "_LIBCONTAINER_MOUNT_FDS="+string(mountFdsJSON), ) } @@ -665,7 +665,7 @@ func (c *linuxContainer) newInitConfig(process *Process) *initConfig { Cwd: process.Cwd, Capabilities: process.Capabilities, PassedFilesCount: len(process.ExtraFiles), - ContainerId: c.ID(), + ContainerID: c.ID(), NoNewPrivileges: c.config.NoNewPrivileges, RootlessEUID: c.config.RootlessEUID, RootlessCgroups: c.config.RootlessCgroups, @@ -760,7 +760,7 @@ func (c *linuxContainer) NotifyMemoryPressure(level PressureLevel) (<-chan struc var criuFeatures *criurpc.CriuFeatures -func (c *linuxContainer) checkCriuFeatures(criuOpts *CriuOpts, rpcOpts *criurpc.CriuOpts, criuFeat *criurpc.CriuFeatures) error { +func (c *linuxContainer) checkCRIUFeatures(criuOpts *CRIUOpts, rpcOpts *criurpc.CriuOpts, criuFeat *criurpc.CriuFeatures) error { t := criurpc.CriuReqType_FEATURE_CHECK // make sure the features we are looking for are really not from @@ -811,7 +811,7 @@ func (c *linuxContainer) checkCriuFeatures(criuOpts *CriuOpts, rpcOpts *criurpc. return nil } -func compareCriuVersion(criuVersion int, minVersion int) error { +func compareCRIUVersion(criuVersion int, minVersion int) error { // simple function to perform the actual version compare if criuVersion < minVersion { return fmt.Errorf("CRIU version %d must be %d or higher", criuVersion, minVersion) @@ -820,12 +820,12 @@ func compareCriuVersion(criuVersion int, minVersion int) error { return nil } -// checkCriuVersion checks Criu version greater than or equal to minVersion -func (c *linuxContainer) checkCriuVersion(minVersion int) error { +// checkCRIUVersion checks Criu version greater than or equal to minVersion +func (c *linuxContainer) checkCRIUVersion(minVersion int) error { // If the version of criu has already been determined there is no need // to ask criu for the version again. Use the value from c.criuVersion. if c.criuVersion != 0 { - return compareCriuVersion(c.criuVersion, minVersion) + return compareCRIUVersion(c.criuVersion, minVersion) } criu := criu.MakeCriu() @@ -836,12 +836,12 @@ func (c *linuxContainer) checkCriuVersion(minVersion int) error { return fmt.Errorf("CRIU version check failed: %w", err) } - return compareCriuVersion(c.criuVersion, minVersion) + return compareCRIUVersion(c.criuVersion, minVersion) } const descriptorsFilename = "descriptors.json" -func (c *linuxContainer) addCriuDumpMount(req *criurpc.CriuReq, m *configs.Mount) { +func (c *linuxContainer) addCRIUDumpMount(req *criurpc.CriuReq, m *configs.Mount) { mountDest := strings.TrimPrefix(m.Destination, c.config.Rootfs) if dest, err := securejoin.SecureJoin(c.config.Rootfs, mountDest); err == nil { mountDest = dest[len(c.config.Rootfs):] @@ -875,7 +875,7 @@ func (c *linuxContainer) addMaskPaths(req *criurpc.CriuReq) error { return nil } -func (c *linuxContainer) handleCriuConfigurationFile(rpcOpts *criurpc.CriuOpts) { +func (c *linuxContainer) handleCRIUConfigurationFile(rpcOpts *criurpc.CriuOpts) { // CRIU will evaluate a configuration starting with release 3.11. // Settings in the configuration file will overwrite RPC settings. // Look for annotations. The annotation 'org.criu.config' @@ -914,7 +914,7 @@ func (c *linuxContainer) criuSupportsExtNS(t configs.NamespaceType) bool { default: return false } - return c.checkCriuVersion(minVersion) == nil + return c.checkCRIUVersion(minVersion) == nil } func criuNsToKey(t configs.NamespaceType) string { @@ -1012,7 +1012,7 @@ func (c *linuxContainer) handleRestoringExternalNamespaces(rpcOpts *criurpc.Criu return nil } -func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { +func (c *linuxContainer) Checkpoint(criuOpts *CRIUOpts) error { c.m.Lock() defer c.m.Unlock() @@ -1023,7 +1023,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { // rootless containers might make this complicated. // We are relying on the CRIU version RPC which was introduced with CRIU 3.0.0 - if err := c.checkCriuVersion(30000); err != nil { + if err := c.checkCRIUVersion(30000); err != nil { return err } @@ -1053,7 +1053,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { Pid: proto.Int32(int32(c.initProcess.pid())), ShellJob: proto.Bool(criuOpts.ShellJob), LeaveRunning: proto.Bool(criuOpts.LeaveRunning), - TcpEstablished: proto.Bool(criuOpts.TcpEstablished), + TcpEstablished: proto.Bool(criuOpts.TCPEstablished), ExtUnixSk: proto.Bool(criuOpts.ExternalUnixConnections), FileLocks: proto.Bool(criuOpts.FileLocks), EmptyNs: proto.Uint32(criuOpts.EmptyNs), @@ -1075,7 +1075,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { rpcOpts.WorkDirFd = proto.Int32(int32(workDir.Fd())) } - c.handleCriuConfigurationFile(&rpcOpts) + c.handleCRIUConfigurationFile(&rpcOpts) // If the container is running in a network namespace and has // a path to the network namespace configured, we will dump @@ -1095,7 +1095,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { // CRIU can use cgroup freezer; when rpcOpts.FreezeCgroup // is not set, CRIU uses ptrace() to pause the processes. // Note cgroup v2 freezer is only supported since CRIU release 3.14. - if !cgroups.IsCgroup2UnifiedMode() || c.checkCriuVersion(31400) == nil { + if !cgroups.IsCgroup2UnifiedMode() || c.checkCRIUVersion(31400) == nil { if fcg := c.cgroupManager.Path("freezer"); fcg != "" { rpcOpts.FreezeCgroup = proto.String(fcg) } @@ -1127,7 +1127,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { MemTrack: proto.Bool(true), } - if err := c.checkCriuFeatures(criuOpts, &rpcOpts, &feat); err != nil { + if err := c.checkCRIUFeatures(criuOpts, &rpcOpts, &feat); err != nil { return err } @@ -1141,7 +1141,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { feat := criurpc.CriuFeatures{ LazyPages: proto.Bool(true), } - if err := c.checkCriuFeatures(criuOpts, &rpcOpts, &feat); err != nil { + if err := c.checkCRIUFeatures(criuOpts, &rpcOpts, &feat); err != nil { return err } @@ -1156,7 +1156,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { return fmt.Errorf("invalid --status-fd argument %d: not writable", fd) } - if c.checkCriuVersion(31500) != nil { + if c.checkCRIUVersion(31500) != nil { // For criu 3.15+, use notifications (see case "status-ready" // in criuNotifications). Otherwise, rely on criu status fd. rpcOpts.StatusFd = proto.Int32(int32(fd)) @@ -1175,7 +1175,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { for _, m := range c.config.Mounts { switch m.Device { case "bind": - c.addCriuDumpMount(req, m) + c.addCRIUDumpMount(req, m) case "cgroup": if cgroups.IsCgroup2UnifiedMode() || hasCgroupns { // real mount(s) @@ -1187,7 +1187,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { return err } for _, b := range binds { - c.addCriuDumpMount(req, b) + c.addCRIUDumpMount(req, b) } } } @@ -1198,7 +1198,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { for _, node := range c.config.Devices { m := &configs.Mount{Destination: node.Path, Source: node.Path} - c.addCriuDumpMount(req, m) + c.addCRIUDumpMount(req, m) } // Write the FD info to a file in the image directory @@ -1220,7 +1220,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { return nil } -func (c *linuxContainer) addCriuRestoreMount(req *criurpc.CriuReq, m *configs.Mount) { +func (c *linuxContainer) addCRIURestoreMount(req *criurpc.CriuReq, m *configs.Mount) { mountDest := strings.TrimPrefix(m.Destination, c.config.Rootfs) if dest, err := securejoin.SecureJoin(c.config.Rootfs, mountDest); err == nil { mountDest = dest[len(c.config.Rootfs):] @@ -1232,7 +1232,7 @@ func (c *linuxContainer) addCriuRestoreMount(req *criurpc.CriuReq, m *configs.Mo req.Opts.ExtMnt = append(req.Opts.ExtMnt, extMnt) } -func (c *linuxContainer) restoreNetwork(req *criurpc.CriuReq, criuOpts *CriuOpts) { +func (c *linuxContainer) restoreNetwork(req *criurpc.CriuReq, criuOpts *CRIUOpts) { for _, iface := range c.config.Networks { switch iface.Type { case "veth": @@ -1252,10 +1252,10 @@ func (c *linuxContainer) restoreNetwork(req *criurpc.CriuReq, criuOpts *CriuOpts } } -// makeCriuRestoreMountpoints makes the actual mountpoints for the +// makeCRIURestoreMountpoints makes the actual mountpoints for the // restore using CRIU. This function is inspired from the code in // rootfs_linux.go -func (c *linuxContainer) makeCriuRestoreMountpoints(m *configs.Mount) error { +func (c *linuxContainer) makeCRIURestoreMountpoints(m *configs.Mount) error { switch m.Device { case "cgroup": // No mount point(s) need to be created: @@ -1301,13 +1301,13 @@ func isPathInPrefixList(path string, prefix []string) bool { return false } -// prepareCriuRestoreMounts tries to set up the rootfs of the +// prepareCRIURestoreMounts tries to set up the rootfs of the // container to be restored in the same way runc does it for // initial container creation. Even for a read-only rootfs container // runc modifies the rootfs to add mountpoints which do not exist. // This function also creates missing mountpoints as long as they // are not on top of a tmpfs, as CRIU will restore tmpfs content anyway. -func (c *linuxContainer) prepareCriuRestoreMounts(mounts []*configs.Mount) error { +func (c *linuxContainer) prepareCRIURestoreMounts(mounts []*configs.Mount) error { // First get a list of a all tmpfs mounts tmpfs := []string{} for _, m := range mounts { @@ -1336,7 +1336,7 @@ func (c *linuxContainer) prepareCriuRestoreMounts(mounts []*configs.Mount) error }() for _, m := range mounts { if !isPathInPrefixList(m.Destination, tmpfs) { - if err := c.makeCriuRestoreMountpoints(m); err != nil { + if err := c.makeCRIURestoreMountpoints(m); err != nil { return err } // If the mount point is a bind mount, we need to mount @@ -1364,7 +1364,7 @@ func (c *linuxContainer) prepareCriuRestoreMounts(mounts []*configs.Mount) error return nil } -func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error { +func (c *linuxContainer) Restore(process *Process, criuOpts *CRIUOpts) error { c.m.Lock() defer c.m.Unlock() @@ -1376,7 +1376,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error { // support for unprivileged restore at the moment. // We are relying on the CRIU version RPC which was introduced with CRIU 3.0.0 - if err := c.checkCriuVersion(30000); err != nil { + if err := c.checkCRIUVersion(30000); err != nil { return err } if criuOpts.ImagesDirectory == "" { @@ -1420,7 +1420,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error { NotifyScripts: proto.Bool(true), ShellJob: proto.Bool(criuOpts.ShellJob), ExtUnixSk: proto.Bool(criuOpts.ExternalUnixConnections), - TcpEstablished: proto.Bool(criuOpts.TcpEstablished), + TcpEstablished: proto.Bool(criuOpts.TCPEstablished), FileLocks: proto.Bool(criuOpts.FileLocks), EmptyNs: proto.Uint32(criuOpts.EmptyNs), OrphanPtsMaster: proto.Bool(true), @@ -1432,13 +1432,13 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error { if criuOpts.LsmProfile != "" { // CRIU older than 3.16 has a bug which breaks the possibility // to set a different LSM profile. - if err := c.checkCriuVersion(31600); err != nil { + if err := c.checkCRIUVersion(31600); err != nil { return errors.New("--lsm-profile requires at least CRIU 3.16") } req.Opts.LsmProfile = proto.String(criuOpts.LsmProfile) } if criuOpts.LsmMountContext != "" { - if err := c.checkCriuVersion(31600); err != nil { + if err := c.checkCRIUVersion(31600); err != nil { return errors.New("--lsm-mount-context requires at least CRIU 3.16") } req.Opts.LsmMountContext = proto.String(criuOpts.LsmMountContext) @@ -1457,7 +1457,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error { defer workDir.Close() req.Opts.WorkDirFd = proto.Int32(int32(workDir.Fd())) } - c.handleCriuConfigurationFile(req.Opts) + c.handleCRIUConfigurationFile(req.Opts) if err := c.handleRestoringNamespaces(req.Opts, &extraFiles); err != nil { return err @@ -1465,7 +1465,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error { // This will modify the rootfs of the container in the same way runc // modifies the container during initial creation. - if err := c.prepareCriuRestoreMounts(c.config.Mounts); err != nil { + if err := c.prepareCRIURestoreMounts(c.config.Mounts); err != nil { return err } @@ -1473,7 +1473,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error { for _, m := range c.config.Mounts { switch m.Device { case "bind": - c.addCriuRestoreMount(req, m) + c.addCRIURestoreMount(req, m) case "cgroup": if cgroups.IsCgroup2UnifiedMode() || hasCgroupns { continue @@ -1484,19 +1484,19 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error { return err } for _, b := range binds { - c.addCriuRestoreMount(req, b) + c.addCRIURestoreMount(req, b) } } } if len(c.config.MaskPaths) > 0 { m := &configs.Mount{Destination: "/dev/null", Source: "/dev/null"} - c.addCriuRestoreMount(req, m) + c.addCRIURestoreMount(req, m) } for _, node := range c.config.Devices { m := &configs.Mount{Destination: node.Path, Source: node.Path} - c.addCriuRestoreMount(req, m) + c.addCRIURestoreMount(req, m) } if criuOpts.EmptyNs&unix.CLONE_NEWNET == 0 { @@ -1575,7 +1575,7 @@ func (c *linuxContainer) criuApplyCgroups(pid int, req *criurpc.CriuReq) error { return nil } -func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts *CriuOpts, extraFiles []*os.File) error { +func (c *linuxContainer) criuSwrk(process *Process, req *criurpc.CriuReq, opts *CRIUOpts, extraFiles []*os.File) error { fds, err := unix.Socketpair(unix.AF_LOCAL, unix.SOCK_SEQPACKET|unix.SOCK_CLOEXEC, 0) if err != nil { return err @@ -1794,7 +1794,7 @@ func unlockNetwork(config *configs.Config) error { return nil } -func (c *linuxContainer) criuNotifications(resp *criurpc.CriuResp, process *Process, cmd *exec.Cmd, opts *CriuOpts, fds []string, oob []byte) error { +func (c *linuxContainer) criuNotifications(resp *criurpc.CriuResp, process *Process, cmd *exec.Cmd, opts *CRIUOpts, fds []string, oob []byte) error { notify := resp.GetNotify() if notify == nil { return fmt.Errorf("invalid response: %s", resp.String()) @@ -2152,14 +2152,14 @@ func (c *linuxContainer) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Na _, joinExistingUser := nsMaps[configs.NEWUSER] if !joinExistingUser { // write uid mappings - if len(c.config.UidMappings) > 0 { + if len(c.config.UIDMappings) > 0 { if c.config.RootlessEUID && c.newuidmapPath != "" { r.AddData(&Bytemsg{ Type: UidmapPathAttr, Value: []byte(c.newuidmapPath), }) } - b, err := encodeIDMapping(c.config.UidMappings) + b, err := encodeIDMapping(c.config.UIDMappings) if err != nil { return nil, err } @@ -2170,8 +2170,8 @@ func (c *linuxContainer) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Na } // write gid mappings - if len(c.config.GidMappings) > 0 { - b, err := encodeIDMapping(c.config.GidMappings) + if len(c.config.GIDMappings) > 0 { + b, err := encodeIDMapping(c.config.GIDMappings) if err != nil { return nil, err } @@ -2194,11 +2194,11 @@ func (c *linuxContainer) bootstrapData(cloneFlags uintptr, nsMaps map[configs.Na } } - if c.config.OomScoreAdj != nil { + if c.config.OOMScoreAdj != nil { // write oom_score_adj r.AddData(&Bytemsg{ Type: OomScoreAdjAttr, - Value: []byte(strconv.Itoa(*c.config.OomScoreAdj)), + Value: []byte(strconv.Itoa(*c.config.OOMScoreAdj)), }) } @@ -2259,5 +2259,5 @@ func requiresRootOrMappingTool(c *configs.Config) bool { gidMap := []configs.IDMap{ {ContainerID: 0, HostID: os.Getegid(), Size: 1}, } - return !reflect.DeepEqual(c.GidMappings, gidMap) + return !reflect.DeepEqual(c.GIDMappings, gidMap) } diff --git a/libcontainer/criu_opts_linux.go b/libcontainer/criu_opts_linux.go index 56b869fb7a8..f970f8e1e41 100644 --- a/libcontainer/criu_opts_linux.go +++ b/libcontainer/criu_opts_linux.go @@ -2,7 +2,7 @@ package libcontainer import criurpc "github.com/checkpoint-restore/go-criu/v5/rpc" -type CriuPageServerInfo struct { +type CRIUPageServerInfo struct { Address string // IP address of CRIU page server Port int32 // port number of CRIU page server } @@ -12,17 +12,17 @@ type VethPairName struct { HostInterfaceName string } -type CriuOpts struct { +type CRIUOpts struct { ImagesDirectory string // directory for storing image files WorkDirectory string // directory to cd and write logs/pidfiles/stats to ParentImage string // directory for storing parent image files in pre-dump and dump LeaveRunning bool // leave container in running state after checkpoint - TcpEstablished bool // checkpoint/restore established TCP connections + TCPEstablished bool // checkpoint/restore established TCP connections ExternalUnixConnections bool // allow external unix connections ShellJob bool // allow to dump and restore shell jobs FileLocks bool // handle file locks, for safety PreDump bool // call criu predump to perform iterative checkpoint - PageServer CriuPageServerInfo // allow to dump to criu page server + PageServer CRIUPageServerInfo // allow to dump to criu page server VethPairs []VethPairName // pass the veth to criu when restore ManageCgroupsMode criurpc.CriuCgMode // dump or restore cgroup mode EmptyNs uint32 // don't c/r properties for namespace from this mask diff --git a/libcontainer/devices/device.go b/libcontainer/devices/device.go index 59874d209b1..9f7c919b183 100644 --- a/libcontainer/devices/device.go +++ b/libcontainer/devices/device.go @@ -20,11 +20,11 @@ type Device struct { // FileMode permission bits for the device. FileMode os.FileMode `json:"file_mode"` - // Uid of the device. - Uid uint32 `json:"uid"` + // UID of the device. + UID uint32 `json:"uid"` - // Gid of the device. - Gid uint32 `json:"gid"` + // GID of the device. + GID uint32 `json:"gid"` } // Permissions is a cgroupv1-style string to represent device access. It diff --git a/libcontainer/devices/device_unix.go b/libcontainer/devices/device_unix.go index 7d8e9fc3104..5e5bf8a5356 100644 --- a/libcontainer/devices/device_unix.go +++ b/libcontainer/devices/device_unix.go @@ -63,8 +63,8 @@ func DeviceFromPath(path, permissions string) (*Device, error) { }, Path: path, FileMode: os.FileMode(mode &^ unix.S_IFMT), - Uid: stat.Uid, - Gid: stat.Gid, + UID: stat.Uid, + GID: stat.Gid, }, nil } diff --git a/libcontainer/factory.go b/libcontainer/factory.go index 9f9e8fc583c..27bd943991b 100644 --- a/libcontainer/factory.go +++ b/libcontainer/factory.go @@ -5,7 +5,7 @@ import ( ) type Factory interface { - // Creates a new container with the given id and starts the initial process inside it. + // Create creates a new container with the given id and starts the initial process inside it. // id must be a string containing only letters, digits and underscores and must contain // between 1 and 1024 characters, inclusive. // diff --git a/libcontainer/factory_linux.go b/libcontainer/factory_linux.go index e6be3185c9c..e1c41570163 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -76,11 +76,11 @@ func TmpfsRoot(l *LinuxFactory) error { return nil } -// CriuPath returns an option func to configure a LinuxFactory with the +// CRIUPath returns an option func to configure a LinuxFactory with the // provided criupath -func CriuPath(criupath string) func(*LinuxFactory) error { +func CRIUPath(criupath string) func(*LinuxFactory) error { return func(l *LinuxFactory) error { - l.CriuPath = criupath + l.CRIUPath = criupath return nil } } @@ -98,7 +98,7 @@ func New(root string, options ...func(*LinuxFactory) error) (Factory, error) { InitPath: "/proc/self/exe", InitArgs: []string{os.Args[0], "init"}, Validator: validate.New(), - CriuPath: "criu", + CRIUPath: "criu", } for _, opt := range options { @@ -125,14 +125,14 @@ type LinuxFactory struct { // a container. InitArgs []string - // CriuPath is the path to the criu binary used for checkpoint and restore of + // CRIUPath is the path to the criu binary used for checkpoint and restore of // containers. - CriuPath string + CRIUPath string // New{u,g}idmapPath is the path to the binaries used for mapping with // rootless containers. - NewuidmapPath string - NewgidmapPath string + NewUIDMapPath string + NewGIDMapPath string // Validator provides validation to container configurations. Validator validate.Validator @@ -207,9 +207,9 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err config: config, initPath: l.InitPath, initArgs: l.InitArgs, - criuPath: l.CriuPath, - newuidmapPath: l.NewuidmapPath, - newgidmapPath: l.NewgidmapPath, + criuPath: l.CRIUPath, + newuidmapPath: l.NewUIDMapPath, + newgidmapPath: l.NewGIDMapPath, cgroupManager: cm, } if l.NewIntelRdtManager != nil { @@ -251,9 +251,9 @@ func (l *LinuxFactory) Load(id string) (Container, error) { config: &state.Config, initPath: l.InitPath, initArgs: l.InitArgs, - criuPath: l.CriuPath, - newuidmapPath: l.NewuidmapPath, - newgidmapPath: l.NewgidmapPath, + criuPath: l.CRIUPath, + newuidmapPath: l.NewUIDMapPath, + newgidmapPath: l.NewGIDMapPath, cgroupManager: cm, root: containerRoot, created: state.Created, @@ -379,34 +379,34 @@ func (l *LinuxFactory) validateID(id string) error { return nil } -// NewuidmapPath returns an option func to configure a LinuxFactory with the +// NewUIDMapPath returns an option func to configure a LinuxFactory with the // provided .. -func NewuidmapPath(newuidmapPath string) func(*LinuxFactory) error { +func NewUIDMapPath(newuidmapPath string) func(*LinuxFactory) error { return func(l *LinuxFactory) error { - l.NewuidmapPath = newuidmapPath + l.NewUIDMapPath = newuidmapPath return nil } } -// NewgidmapPath returns an option func to configure a LinuxFactory with the +// NewGIDMapPath returns an option func to configure a LinuxFactory with the // provided .. -func NewgidmapPath(newgidmapPath string) func(*LinuxFactory) error { +func NewGIDMapPath(newgidmapPath string) func(*LinuxFactory) error { return func(l *LinuxFactory) error { - l.NewgidmapPath = newgidmapPath + l.NewGIDMapPath = newgidmapPath return nil } } func parseMountFds() ([]int, error) { - fdsJson := os.Getenv("_LIBCONTAINER_MOUNT_FDS") - if fdsJson == "" { + fdsJSON := os.Getenv("_LIBCONTAINER_MOUNT_FDS") + if fdsJSON == "" { // Always return the nil slice if no fd is present. return nil, nil } var mountFds []int - if err := json.Unmarshal([]byte(fdsJson), &mountFds); err != nil { - return nil, fmt.Errorf("Error unmarshalling _LIBCONTAINER_MOUNT_FDS: %w", err) + if err := json.Unmarshal([]byte(fdsJSON), &mountFds); err != nil { + return nil, fmt.Errorf("error unmarshalling _LIBCONTAINER_MOUNT_FDS: %w", err) } return mountFds, nil diff --git a/libcontainer/init_linux.go b/libcontainer/init_linux.go index e62f4e8da65..05322a4a3b2 100644 --- a/libcontainer/init_linux.go +++ b/libcontainer/init_linux.go @@ -61,7 +61,7 @@ type initConfig struct { Config *configs.Config `json:"config"` Networks []*network `json:"network"` PassedFilesCount int `json:"passed_files_count"` - ContainerId string `json:"containerid"` + ContainerID string `json:"containerid"` Rlimits []configs.Rlimit `json:"rlimits"` CreateConsole bool `json:"create_console"` ConsoleWidth uint16 `json:"console_width"` @@ -88,7 +88,7 @@ func newContainerInit(t initType, pipe *os.File, consoleSocket *os.File, fifoFd, case initSetns: // mountFds must be nil in this case. We don't mount while doing runc exec. if mountFds != nil { - return nil, errors.New("mountFds must be nil. Can't mount while doing runc exec.") + return nil, errors.New("mountFds must be nil. Can't mount while doing runc exec") } return &linuxSetnsInit{ @@ -311,8 +311,8 @@ func syncParentSeccomp(pipe io.ReadWriter, seccompFd int) error { func setupUser(config *initConfig) error { // Set up defaults. defaultExecUser := user.ExecUser{ - Uid: 0, - Gid: 0, + UID: 0, + GID: 0, Home: "/", } @@ -341,10 +341,10 @@ func setupUser(config *initConfig) error { // Rather than just erroring out later in setuid(2) and setgid(2), check // that the user is mapped here. - if _, err := config.Config.HostUID(execUser.Uid); err != nil { + if _, err := config.Config.HostUID(execUser.UID); err != nil { return errors.New("cannot set uid to unmapped user in user namespace") } - if _, err := config.Config.HostGID(execUser.Gid); err != nil { + if _, err := config.Config.HostGID(execUser.GID); err != nil { return errors.New("cannot set gid to unmapped user in user namespace") } @@ -376,16 +376,16 @@ func setupUser(config *initConfig) error { allowSupGroups := !config.RootlessEUID && string(bytes.TrimSpace(setgroups)) != "deny" if allowSupGroups { - suppGroups := append(execUser.Sgids, addGroups...) + suppGroups := append(execUser.SGIDs, addGroups...) if err := unix.Setgroups(suppGroups); err != nil { return &os.SyscallError{Syscall: "setgroups", Err: err} } } - if err := system.Setgid(execUser.Gid); err != nil { + if err := system.Setgid(execUser.GID); err != nil { return err } - if err := system.Setuid(execUser.Uid); err != nil { + if err := system.Setuid(execUser.UID); err != nil { return err } @@ -427,7 +427,7 @@ func fixStdioPermissions(u *user.ExecUser) error { // that users expect to be able to actually use their console. Without // this code, you couldn't effectively run as a non-root user inside a // container and also have a console set up. - if err := unix.Fchown(int(fd), u.Uid, int(s.Gid)); err != nil { + if err := unix.Fchown(int(fd), u.UID, int(s.Gid)); err != nil { // If we've hit an EINVAL then s.Gid isn't mapped in the user // namespace. If we've hit an EPERM then the inode's current owner // is not mapped in our user namespace (in particular, diff --git a/libcontainer/integration/checkpoint_test.go b/libcontainer/integration/checkpoint_test.go index c86ec8a0c47..cd0c4fe2ad7 100644 --- a/libcontainer/integration/checkpoint_test.go +++ b/libcontainer/integration/checkpoint_test.go @@ -97,7 +97,7 @@ func testCheckpoint(t *testing.T, userns bool) { tmp := t.TempDir() parentDir := filepath.Join(tmp, "criu-parent") - preDumpOpts := &libcontainer.CriuOpts{ + preDumpOpts := &libcontainer.CRIUOpts{ ImagesDirectory: parentDir, WorkDirectory: parentDir, PreDump: true, @@ -118,7 +118,7 @@ func testCheckpoint(t *testing.T, userns bool) { imagesDir := filepath.Join(tmp, "criu") - checkpointOpts := &libcontainer.CriuOpts{ + checkpointOpts := &libcontainer.CRIUOpts{ ImagesDirectory: imagesDir, WorkDirectory: imagesDir, ParentImage: "../criu-parent", diff --git a/libcontainer/integration/exec_test.go b/libcontainer/integration/exec_test.go index f386b4daa95..55182889d29 100644 --- a/libcontainer/integration/exec_test.go +++ b/libcontainer/integration/exec_test.go @@ -535,7 +535,7 @@ func testCPUShares(t *testing.T, systemd bool) { } config := newTemplateConfig(t, &tParam{systemd: systemd}) - config.Cgroups.Resources.CpuShares = 1 + config.Cgroups.Resources.CPUShares = 1 if _, _, err := runContainer(t, config, "ps"); err == nil { t.Fatalf("runContainer should failed with invalid CpuShares") @@ -559,7 +559,7 @@ func testPids(t *testing.T, systemd bool) { } config := newTemplateConfig(t, &tParam{systemd: systemd}) - config.Cgroups.Resources.PidsLimit = -1 + config.Cgroups.Resources.PIDsLimit = -1 // Running multiple processes. _, ret, err := runContainer(t, config, "/bin/sh", "-c", "/bin/true | /bin/true | /bin/true | /bin/true") @@ -571,7 +571,7 @@ func testPids(t *testing.T, systemd bool) { // Enforce a permissive limit. This needs to be fairly hand-wavey due to the // issues with running Go binaries with pids restrictions (see below). - config.Cgroups.Resources.PidsLimit = 64 + config.Cgroups.Resources.PIDsLimit = 64 _, ret, err = runContainer(t, config, "/bin/sh", "-c", ` /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true | @@ -585,7 +585,7 @@ func testPids(t *testing.T, systemd bool) { // Enforce a restrictive limit. 64 * /bin/true + 1 * shell should cause this // to fail reliability. - config.Cgroups.Resources.PidsLimit = 64 + config.Cgroups.Resources.PIDsLimit = 64 out, _, err := runContainer(t, config, "/bin/sh", "-c", ` /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true | @@ -1025,7 +1025,7 @@ func TestOomScoreAdj(t *testing.T) { } config := newTemplateConfig(t, nil) - config.OomScoreAdj = ptrInt(200) + config.OOMScoreAdj = ptrInt(200) container, err := newContainer(t, config) ok(t, err) @@ -1048,8 +1048,8 @@ func TestOomScoreAdj(t *testing.T) { outputOomScoreAdj := strings.TrimSpace(stdout.String()) // Check that the oom_score_adj matches the value that was set as part of config. - if outputOomScoreAdj != strconv.Itoa(*config.OomScoreAdj) { - t.Fatalf("Expected oom_score_adj %d; got %q", *config.OomScoreAdj, outputOomScoreAdj) + if outputOomScoreAdj != strconv.Itoa(*config.OOMScoreAdj) { + t.Fatalf("Expected oom_score_adj %d; got %q", *config.OOMScoreAdj, outputOomScoreAdj) } } @@ -1877,8 +1877,8 @@ func TestBindMountAndUser(t *testing.T) { }) // Set HostID to 1000 to avoid DAC_OVERRIDE bypassing the purpose of this test. - config.UidMappings[0].HostID = 1000 - config.GidMappings[0].HostID = 1000 + config.UIDMappings[0].HostID = 1000 + config.GIDMappings[0].HostID = 1000 // Set the owner of rootfs to the effective IDs in the host to avoid errors // while creating the folders to perform the mounts. diff --git a/libcontainer/integration/execin_test.go b/libcontainer/integration/execin_test.go index f8a6a9c6996..dc4ce44a5b3 100644 --- a/libcontainer/integration/execin_test.go +++ b/libcontainer/integration/execin_test.go @@ -454,7 +454,7 @@ func TestExecInOomScoreAdj(t *testing.T) { return } config := newTemplateConfig(t, nil) - config.OomScoreAdj = ptrInt(200) + config.OOMScoreAdj = ptrInt(200) container, err := newContainer(t, config) ok(t, err) defer destroyContainer(container) @@ -490,8 +490,8 @@ func TestExecInOomScoreAdj(t *testing.T) { waitProcess(process, t) out := buffers.Stdout.String() - if oomScoreAdj := strings.TrimSpace(out); oomScoreAdj != strconv.Itoa(*config.OomScoreAdj) { - t.Fatalf("expected oomScoreAdj to be %d, got %s", *config.OomScoreAdj, oomScoreAdj) + if oomScoreAdj := strings.TrimSpace(out); oomScoreAdj != strconv.Itoa(*config.OOMScoreAdj) { + t.Fatalf("expected oomScoreAdj to be %d, got %s", *config.OOMScoreAdj, oomScoreAdj) } } diff --git a/libcontainer/integration/template_test.go b/libcontainer/integration/template_test.go index f56db8956a7..105f33e972b 100644 --- a/libcontainer/integration/template_test.go +++ b/libcontainer/integration/template_test.go @@ -208,8 +208,8 @@ func newTemplateConfig(t *testing.T, p *tParam) *configs.Config { } if p.userns { - config.UidMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}} - config.GidMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}} + config.UIDMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}} + config.GIDMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}} config.Namespaces = append(config.Namespaces, configs.Namespace{Type: configs.NEWUSER}) } else { config.Mounts = append(config.Mounts, &configs.Mount{ diff --git a/libcontainer/intelrdt/cmt_test.go b/libcontainer/intelrdt/cmt_test.go index 3bd43adae82..64230d26d5a 100644 --- a/libcontainer/intelrdt/cmt_test.go +++ b/libcontainer/intelrdt/cmt_test.go @@ -12,7 +12,7 @@ func TestGetCMTNumaNodeStats(t *testing.T) { "llc_occupancy": 9123911, } - mockedL3_MON := mockResctrlL3_MON(t, mocksNUMANodesToCreate, mocksFilesToCreate) + mockedL3_MON := mockResctrlL3_MON(t, mocksNUMANodesToCreate, mocksFilesToCreate) //nolint:revive // ignore var mockedL3_MON should be mockedL3MON t.Run("Gather mbm", func(t *testing.T) { enabledMonFeatures.llcOccupancy = true diff --git a/libcontainer/intelrdt/mbm_test.go b/libcontainer/intelrdt/mbm_test.go index 4f22cbd0ab2..01fc2daa003 100644 --- a/libcontainer/intelrdt/mbm_test.go +++ b/libcontainer/intelrdt/mbm_test.go @@ -13,7 +13,7 @@ func TestGetMBMNumaNodeStats(t *testing.T) { "mbm_local_bytes": 2361361, } - mockedL3_MON := mockResctrlL3_MON(t, mocksNUMANodesToCreate, mocksFilesToCreate) + mockedL3_MON := mockResctrlL3_MON(t, mocksNUMANodesToCreate, mocksFilesToCreate) //nolint:revive // ignore var mockedL3_MON should be mockedL3MON t.Run("Gather mbm", func(t *testing.T) { enabledMonFeatures.mbmTotalBytes = true diff --git a/libcontainer/intelrdt/monitoring_test.go b/libcontainer/intelrdt/monitoring_test.go index 0a89ef2f7b8..3e22bf25073 100644 --- a/libcontainer/intelrdt/monitoring_test.go +++ b/libcontainer/intelrdt/monitoring_test.go @@ -37,7 +37,7 @@ func TestParseMonFeatures(t *testing.T) { }) } -func mockResctrlL3_MON(t *testing.T, NUMANodes []string, mocks map[string]uint64) string { +func mockResctrlL3_MON(t *testing.T, NUMANodes []string, mocks map[string]uint64) string { //nolint:revive // ignore func mockResctrlL3_MON should be mockResctrlL3MON t.Helper() testDir := t.TempDir() monDataPath := filepath.Join(testDir, "mon_data") @@ -76,7 +76,7 @@ func TestGetMonitoringStats(t *testing.T) { "llc_occupancy": 123331, } - mockedL3_MON := mockResctrlL3_MON(t, mocksNUMANodesToCreate, mocksFilesToCreate) + mockedL3_MON := mockResctrlL3_MON(t, mocksNUMANodesToCreate, mocksFilesToCreate) //nolint:revive // ignore var mockedL3_MON should be mockedL3MON t.Run("Gather monitoring stats", func(t *testing.T) { var stats Stats diff --git a/libcontainer/process_linux.go b/libcontainer/process_linux.go index e025445d330..97f28a1ab30 100644 --- a/libcontainer/process_linux.go +++ b/libcontainer/process_linux.go @@ -192,7 +192,7 @@ func (p *setnsProcess) start() (retErr error) { Metadata: p.config.Config.Seccomp.ListenerMetadata, State: specs.State{ Version: specs.Version, - ID: p.config.ContainerId, + ID: p.config.ContainerID, Status: specs.StateRunning, Pid: p.initProcessPid, Bundle: bundle, diff --git a/libcontainer/rootfs_linux.go b/libcontainer/rootfs_linux.go index f23292fd0bb..1255f04ea5b 100644 --- a/libcontainer/rootfs_linux.go +++ b/libcontainer/rootfs_linux.go @@ -732,7 +732,7 @@ func mknodDevice(dest string, node *devices.Device) error { if err := unix.Mknod(dest, uint32(fileMode), int(dev)); err != nil { return &os.PathError{Op: "mknod", Path: dest, Err: err} } - return os.Chown(dest, int(node.Uid), int(node.Gid)) + return os.Chown(dest, int(node.UID), int(node.GID)) } // Get the parent mount point of directory passed in as argument. Also return diff --git a/libcontainer/setns_init_linux.go b/libcontainer/setns_init_linux.go index 09ab552b3d1..da31110aeee 100644 --- a/libcontainer/setns_init_linux.go +++ b/libcontainer/setns_init_linux.go @@ -26,7 +26,7 @@ type linuxSetnsInit struct { } func (l *linuxSetnsInit) getSessionRingName() string { - return "_ses." + l.config.ContainerId + return "_ses." + l.config.ContainerID } func (l *linuxSetnsInit) Init() error { diff --git a/libcontainer/specconv/spec_linux.go b/libcontainer/specconv/spec_linux.go index c7ca4c8af1f..13a429a2d5a 100644 --- a/libcontainer/specconv/spec_linux.go +++ b/libcontainer/specconv/spec_linux.go @@ -211,8 +211,8 @@ var AllowedDevices = []*devices.Device{ { Path: "/dev/null", FileMode: 0o666, - Uid: 0, - Gid: 0, + UID: 0, + GID: 0, Rule: devices.Rule{ Type: devices.CharDevice, Major: 1, @@ -224,8 +224,8 @@ var AllowedDevices = []*devices.Device{ { Path: "/dev/random", FileMode: 0o666, - Uid: 0, - Gid: 0, + UID: 0, + GID: 0, Rule: devices.Rule{ Type: devices.CharDevice, Major: 1, @@ -237,8 +237,8 @@ var AllowedDevices = []*devices.Device{ { Path: "/dev/full", FileMode: 0o666, - Uid: 0, - Gid: 0, + UID: 0, + GID: 0, Rule: devices.Rule{ Type: devices.CharDevice, Major: 1, @@ -250,8 +250,8 @@ var AllowedDevices = []*devices.Device{ { Path: "/dev/tty", FileMode: 0o666, - Uid: 0, - Gid: 0, + UID: 0, + GID: 0, Rule: devices.Rule{ Type: devices.CharDevice, Major: 5, @@ -263,8 +263,8 @@ var AllowedDevices = []*devices.Device{ { Path: "/dev/zero", FileMode: 0o666, - Uid: 0, - Gid: 0, + UID: 0, + GID: 0, Rule: devices.Rule{ Type: devices.CharDevice, Major: 1, @@ -276,8 +276,8 @@ var AllowedDevices = []*devices.Device{ { Path: "/dev/urandom", FileMode: 0o666, - Uid: 0, - Gid: 0, + UID: 0, + GID: 0, Rule: devices.Rule{ Type: devices.CharDevice, Major: 1, @@ -478,7 +478,7 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) { } if spec.Process != nil { - config.OomScoreAdj = spec.Process.OOMScoreAdj + config.OOMScoreAdj = spec.Process.OOMScoreAdj config.NoNewPrivileges = spec.Process.NoNewPrivileges config.Umask = spec.Process.User.Umask config.ProcessLabel = spec.Process.SelinuxLabel @@ -719,33 +719,33 @@ func CreateCgroupConfig(opts *CreateOpts, defaultDevs []*devices.Device) (*confi c.Resources.MemorySwappiness = r.Memory.Swappiness } if r.Memory.DisableOOMKiller != nil { - c.Resources.OomKillDisable = *r.Memory.DisableOOMKiller + c.Resources.OOMKillDisable = *r.Memory.DisableOOMKiller } } if r.CPU != nil { if r.CPU.Shares != nil { - c.Resources.CpuShares = *r.CPU.Shares + c.Resources.CPUShares = *r.CPU.Shares // CpuWeight is used for cgroupv2 and should be converted - c.Resources.CpuWeight = cgroups.ConvertCPUSharesToCgroupV2Value(c.Resources.CpuShares) + c.Resources.CPUWeight = cgroups.ConvertCPUSharesToCgroupV2Value(c.Resources.CPUShares) } if r.CPU.Quota != nil { - c.Resources.CpuQuota = *r.CPU.Quota + c.Resources.CPUQuota = *r.CPU.Quota } if r.CPU.Period != nil { - c.Resources.CpuPeriod = *r.CPU.Period + c.Resources.CPUPeriod = *r.CPU.Period } if r.CPU.RealtimeRuntime != nil { - c.Resources.CpuRtRuntime = *r.CPU.RealtimeRuntime + c.Resources.CPURtRuntime = *r.CPU.RealtimeRuntime } if r.CPU.RealtimePeriod != nil { - c.Resources.CpuRtPeriod = *r.CPU.RealtimePeriod + c.Resources.CPURtPeriod = *r.CPU.RealtimePeriod } - c.Resources.CpusetCpus = r.CPU.Cpus - c.Resources.CpusetMems = r.CPU.Mems + c.Resources.CPUSetCPUs = r.CPU.Cpus + c.Resources.CPUSetMems = r.CPU.Mems } if r.Pids != nil { - c.Resources.PidsLimit = r.Pids.Limit + c.Resources.PIDsLimit = r.Pids.Limit } if r.BlockIO != nil { if r.BlockIO.Weight != nil { @@ -912,8 +912,8 @@ next: }, Path: d.Path, FileMode: filemode, - Uid: uid, - Gid: gid, + UID: uid, + GID: gid, } config.Devices = append(config.Devices, device) } @@ -932,10 +932,10 @@ func setupUserNamespace(spec *specs.Spec, config *configs.Config) error { } if spec.Linux != nil { for _, m := range spec.Linux.UIDMappings { - config.UidMappings = append(config.UidMappings, create(m)) + config.UIDMappings = append(config.UIDMappings, create(m)) } for _, m := range spec.Linux.GIDMappings { - config.GidMappings = append(config.GidMappings, create(m)) + config.GIDMappings = append(config.GIDMappings, create(m)) } } rootUID, err := config.HostRootUID() @@ -947,8 +947,8 @@ func setupUserNamespace(spec *specs.Spec, config *configs.Config) error { return err } for _, node := range config.Devices { - node.Uid = uint32(rootUID) - node.Gid = uint32(rootGID) + node.UID = uint32(rootUID) + node.GID = uint32(rootGID) } return nil } diff --git a/libcontainer/specconv/spec_linux_test.go b/libcontainer/specconv/spec_linux_test.go index d11983eefc1..9ebfc23f0eb 100644 --- a/libcontainer/specconv/spec_linux_test.go +++ b/libcontainer/specconv/spec_linux_test.go @@ -385,7 +385,7 @@ func TestLinuxCgroupWithMemoryResource(t *testing.T) { if cgroup.Resources.MemorySwappiness != swappinessPtr { t.Errorf("Expected to have %d as memory swappiness, got %d", swappinessPtr, cgroup.Resources.MemorySwappiness) } - if cgroup.Resources.OomKillDisable != disableOOMKiller { + if cgroup.Resources.OOMKillDisable != disableOOMKiller { t.Errorf("The OOMKiller should be enabled") } } @@ -883,8 +883,8 @@ func TestCreateDevices(t *testing.T) { wantDev := &devices.Device{ Path: "/dev/tty", FileMode: 0o666, - Uid: 1000, - Gid: 1000, + UID: 1000, + GID: 1000, Rule: devices.Rule{ Type: devices.CharDevice, Major: 5, diff --git a/libcontainer/standard_init_linux.go b/libcontainer/standard_init_linux.go index 3308df41928..5710830fcf0 100644 --- a/libcontainer/standard_init_linux.go +++ b/libcontainer/standard_init_linux.go @@ -42,7 +42,7 @@ func (l *linuxStandardInit) getSessionRingParams() (string, uint32, uint32) { // Create a unique per session container name that we can join in setns; // However, other containers can also join it. - return "_ses." + l.config.ContainerId, 0xffffffff, newperms + return "_ses." + l.config.ContainerID, 0xffffffff, newperms } func (l *linuxStandardInit) Init() error { diff --git a/libcontainer/system/proc.go b/libcontainer/system/proc.go index b9c4e198ed4..9a74f59d346 100644 --- a/libcontainer/system/proc.go +++ b/libcontainer/system/proc.go @@ -55,7 +55,7 @@ func (s State) String() string { // Stat_t represents the information from /proc/[pid]/stat, as // described in proc(5) with names based on the /proc/[pid]/status // fields. -type Stat_t struct { +type Stat_t struct { //nolint:revive // ignore "type Stat_t should be StatT" // Name is the command run by the process. Name string diff --git a/libcontainer/user/lookup_unix.go b/libcontainer/user/lookup_unix.go index f95c1409fce..11471e5a2bd 100644 --- a/libcontainer/user/lookup_unix.go +++ b/libcontainer/user/lookup_unix.go @@ -26,12 +26,12 @@ func LookupUser(username string) (User, error) { }) } -// LookupUid looks up a user by their user id in /etc/passwd. If the user cannot +// LookupUID looks up a user by their user id in /etc/passwd. If the user cannot // be found (or there is no /etc/passwd file on the filesystem), then LookupId // returns an error. -func LookupUid(uid int) (User, error) { +func LookupUID(uid int) (User, error) { return lookupUserFunc(func(u User) bool { - return u.Uid == uid + return u.UID == uid }) } @@ -72,7 +72,7 @@ func LookupGroup(groupname string) (Group, error) { // returns an error. func LookupGid(gid int) (Group, error) { return lookupGroupFunc(func(g Group) bool { - return g.Gid == gid + return g.GID == gid }) } @@ -119,7 +119,7 @@ func GetGroup() (io.ReadCloser, error) { // user cannot be found (or there is no /etc/passwd file on the filesystem), // then CurrentUser returns an error. func CurrentUser() (User, error) { - return LookupUid(unix.Getuid()) + return LookupUID(unix.Getuid()) } // CurrentGroup looks up the current user's group by their primary group id's @@ -135,7 +135,7 @@ func currentUserSubIDs(fileName string) ([]SubID, error) { return nil, err } filter := func(entry SubID) bool { - return entry.Name == u.Name || entry.Name == strconv.Itoa(u.Uid) + return entry.Name == u.Name || entry.Name == strconv.Itoa(u.UID) } return ParseSubIDFileFilter(fileName, filter) } diff --git a/libcontainer/user/user.go b/libcontainer/user/user.go index 2473c5eaddc..0a44540ba89 100644 --- a/libcontainer/user/user.go +++ b/libcontainer/user/user.go @@ -28,8 +28,8 @@ var ( type User struct { Name string Pass string - Uid int - Gid int + UID int + GID int Gecos string Home string Shell string @@ -38,7 +38,7 @@ type User struct { type Group struct { Name string Pass string - Gid int + GID int List []string } @@ -140,7 +140,7 @@ func ParsePasswdFilter(r io.Reader, filter func(User) bool) ([]User, error) { // root:x:0:0:root:/root:/bin/bash // adm:x:3:4:adm:/var/adm:/bin/false p := User{} - parseLine(line, &p.Name, &p.Pass, &p.Uid, &p.Gid, &p.Gecos, &p.Home, &p.Shell) + parseLine(line, &p.Name, &p.Pass, &p.UID, &p.GID, &p.Gecos, &p.Home, &p.Shell) if filter == nil || filter(p) { out = append(out, p) @@ -236,7 +236,7 @@ func ParseGroupFilter(r io.Reader, filter func(Group) bool) ([]Group, error) { // root:x:0:root // adm:x:4:root,adm,daemon p := Group{} - parseLine(wholeLine, &p.Name, &p.Pass, &p.Gid, &p.List) + parseLine(wholeLine, &p.Name, &p.Pass, &p.GID, &p.List) if filter == nil || filter(p) { out = append(out, p) @@ -245,9 +245,9 @@ func ParseGroupFilter(r io.Reader, filter func(Group) bool) ([]Group, error) { } type ExecUser struct { - Uid int - Gid int - Sgids []int + UID int + GID int + SGIDs []int Home string } @@ -299,15 +299,15 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) ( // Copy over defaults. user := &ExecUser{ - Uid: defaults.Uid, - Gid: defaults.Gid, - Sgids: defaults.Sgids, + UID: defaults.UID, + GID: defaults.GID, + SGIDs: defaults.SGIDs, Home: defaults.Home, } // Sgids slice *cannot* be nil. - if user.Sgids == nil { - user.Sgids = []int{} + if user.SGIDs == nil { + user.SGIDs = []int{} } // Allow for userArg to have either "user" syntax, or optionally "user:group" syntax @@ -323,12 +323,12 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) ( users, err := ParsePasswdFilter(passwd, func(u User) bool { if userArg == "" { // Default to current state of the user. - return u.Uid == user.Uid + return u.UID == user.UID } if uidErr == nil { // If the userArg is numeric, always treat it as a UID. - return uidArg == u.Uid + return uidArg == u.UID } return u.Name == userArg @@ -337,7 +337,7 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) ( // If we can't find the user, we have to bail. if err != nil && passwd != nil { if userArg == "" { - userArg = strconv.Itoa(user.Uid) + userArg = strconv.Itoa(user.UID) } return nil, fmt.Errorf("unable to find user %s: %w", userArg, err) } @@ -346,8 +346,8 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) ( if len(users) > 0 { // First match wins, even if there's more than one matching entry. matchedUserName = users[0].Name - user.Uid = users[0].Uid - user.Gid = users[0].Gid + user.UID = users[0].UID + user.GID = users[0].GID user.Home = users[0].Home } else if userArg != "" { // If we can't find a user with the given username, the only other valid @@ -357,10 +357,10 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) ( // Not numeric. return nil, fmt.Errorf("unable to find user %s: %w", userArg, ErrNoPasswdEntries) } - user.Uid = uidArg + user.UID = uidArg // Must be inside valid uid range. - if user.Uid < minID || user.Uid > maxID { + if user.UID < minID || user.UID > maxID { return nil, ErrRange } @@ -384,7 +384,7 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) ( if gidErr == nil { // If the groupArg is numeric, always treat it as a GID. - return gidArg == g.Gid + return gidArg == g.GID } return g.Name == groupArg @@ -397,7 +397,7 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) ( if groupArg != "" { if len(groups) > 0 { // First match wins, even if there's more than one matching entry. - user.Gid = groups[0].Gid + user.GID = groups[0].GID } else { // If we can't find a group with the given name, the only other valid // option is if it's a numeric group name with no associated entry in group. @@ -406,10 +406,10 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) ( // Not numeric. return nil, fmt.Errorf("unable to find group %s: %w", groupArg, ErrNoGroupEntries) } - user.Gid = gidArg + user.GID = gidArg // Must be inside valid gid range. - if user.Gid < minID || user.Gid > maxID { + if user.GID < minID || user.GID > maxID { return nil, ErrRange } @@ -417,9 +417,9 @@ func GetExecUser(userSpec string, defaults *ExecUser, passwd, group io.Reader) ( } } else if len(groups) > 0 { // Supplementary group ids only make sense if in the implicit form. - user.Sgids = make([]int, len(groups)) + user.SGIDs = make([]int, len(groups)) for i, group := range groups { - user.Sgids[i] = group.Gid + user.SGIDs[i] = group.GID } } } @@ -438,7 +438,7 @@ func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, err var err error groups, err = ParseGroupFilter(group, func(g Group) bool { for _, ag := range additionalGroups { - if g.Name == ag || strconv.Itoa(g.Gid) == ag { + if g.Name == ag || strconv.Itoa(g.GID) == ag { return true } } @@ -455,9 +455,9 @@ func GetAdditionalGroups(additionalGroups []string, group io.Reader) ([]int, err for _, g := range groups { // if we found a matched group either by name or gid, take the // first matched as correct - if g.Name == ag || strconv.Itoa(g.Gid) == ag { - if _, ok := gidMap[g.Gid]; !ok { - gidMap[g.Gid] = struct{}{} + if g.Name == ag || strconv.Itoa(g.GID) == ag { + if _, ok := gidMap[g.GID]; !ok { + gidMap[g.GID] = struct{}{} found = true break } diff --git a/libcontainer/user/user_test.go b/libcontainer/user/user_test.go index c0c762d6a89..134d5d94cdf 100644 --- a/libcontainer/user/user_test.go +++ b/libcontainer/user/user_test.go @@ -70,11 +70,11 @@ this is just some garbage data if len(users) != 3 { t.Fatalf("Expected 3 users, got %v", len(users)) } - if users[0].Uid != 0 || users[0].Name != "root" { - t.Fatalf("Expected users[0] to be 0 - root, got %v - %v", users[0].Uid, users[0].Name) + if users[0].UID != 0 || users[0].Name != "root" { + t.Fatalf("Expected users[0] to be 0 - root, got %v - %v", users[0].UID, users[0].Name) } - if users[1].Uid != 3 || users[1].Name != "adm" { - t.Fatalf("Expected users[1] to be 3 - adm, got %v - %v", users[1].Uid, users[1].Name) + if users[1].UID != 3 || users[1].Name != "adm" { + t.Fatalf("Expected users[1] to be 3 - adm, got %v - %v", users[1].UID, users[1].Name) } } @@ -90,11 +90,11 @@ this is just some garbage data if len(groups) != 4 { t.Fatalf("Expected 4 groups, got %v", len(groups)) } - if groups[0].Gid != 0 || groups[0].Name != "root" || len(groups[0].List) != 1 { - t.Fatalf("Expected groups[0] to be 0 - root - 1 member, got %v - %v - %v", groups[0].Gid, groups[0].Name, len(groups[0].List)) + if groups[0].GID != 0 || groups[0].Name != "root" || len(groups[0].List) != 1 { + t.Fatalf("Expected groups[0] to be 0 - root - 1 member, got %v - %v - %v", groups[0].GID, groups[0].Name, len(groups[0].List)) } - if groups[1].Gid != 4 || groups[1].Name != "adm" || len(groups[1].List) != 3 { - t.Fatalf("Expected groups[1] to be 4 - adm - 3 members, got %v - %v - %v", groups[1].Gid, groups[1].Name, len(groups[1].List)) + if groups[1].GID != 4 || groups[1].Name != "adm" || len(groups[1].List) != 3 { + t.Fatalf("Expected groups[1] to be 4 - adm - 3 members, got %v - %v - %v", groups[1].GID, groups[1].Name, len(groups[1].List)) } } @@ -117,9 +117,9 @@ this is just some garbage data ` + largeGroup() defaultExecUser := ExecUser{ - Uid: 8888, - Gid: 8888, - Sgids: []int{8888}, + UID: 8888, + GID: 8888, + SGIDs: []int{8888}, Home: "/8888", } @@ -130,72 +130,72 @@ this is just some garbage data { ref: "root", expected: ExecUser{ - Uid: 0, - Gid: 0, - Sgids: []int{0, 1234}, + UID: 0, + GID: 0, + SGIDs: []int{0, 1234}, Home: "/root", }, }, { ref: "adm", expected: ExecUser{ - Uid: 42, - Gid: 43, - Sgids: []int{1234}, + UID: 42, + GID: 43, + SGIDs: []int{1234}, Home: "/var/adm", }, }, { ref: "root:adm", expected: ExecUser{ - Uid: 0, - Gid: 43, - Sgids: defaultExecUser.Sgids, + UID: 0, + GID: 43, + SGIDs: defaultExecUser.SGIDs, Home: "/root", }, }, { ref: "adm:1234", expected: ExecUser{ - Uid: 42, - Gid: 1234, - Sgids: defaultExecUser.Sgids, + UID: 42, + GID: 1234, + SGIDs: defaultExecUser.SGIDs, Home: "/var/adm", }, }, { ref: "42:1234", expected: ExecUser{ - Uid: 42, - Gid: 1234, - Sgids: defaultExecUser.Sgids, + UID: 42, + GID: 1234, + SGIDs: defaultExecUser.SGIDs, Home: "/var/adm", }, }, { ref: "1337:1234", expected: ExecUser{ - Uid: 1337, - Gid: 1234, - Sgids: defaultExecUser.Sgids, + UID: 1337, + GID: 1234, + SGIDs: defaultExecUser.SGIDs, Home: defaultExecUser.Home, }, }, { ref: "1337", expected: ExecUser{ - Uid: 1337, - Gid: defaultExecUser.Gid, - Sgids: defaultExecUser.Sgids, + UID: 1337, + GID: defaultExecUser.GID, + SGIDs: defaultExecUser.SGIDs, Home: defaultExecUser.Home, }, }, { ref: "", expected: ExecUser{ - Uid: defaultExecUser.Uid, - Gid: defaultExecUser.Gid, - Sgids: defaultExecUser.Sgids, + UID: defaultExecUser.UID, + GID: defaultExecUser.GID, + SGIDs: defaultExecUser.SGIDs, Home: defaultExecUser.Home, }, }, @@ -204,18 +204,18 @@ this is just some garbage data { ref: "111", expected: ExecUser{ - Uid: 111, - Gid: 112, - Sgids: defaultExecUser.Sgids, + UID: 111, + GID: 112, + SGIDs: defaultExecUser.SGIDs, Home: "/home/odd", }, }, { ref: "111:444", expected: ExecUser{ - Uid: 111, - Gid: 444, - Sgids: defaultExecUser.Sgids, + UID: 111, + GID: 444, + SGIDs: defaultExecUser.SGIDs, Home: "/home/odd", }, }, @@ -223,9 +223,9 @@ this is just some garbage data { ref: "7456", expected: ExecUser{ - Uid: 7456, - Gid: 100, - Sgids: []int{1234, 1000}, // 1000 is largegroup GID + UID: 7456, + GID: 100, + SGIDs: []int{1234, 1000}, // 1000 is largegroup GID Home: "/home/user7456", }, }, @@ -310,9 +310,9 @@ this is just some garbage data ` defaultExecUser := ExecUser{ - Uid: 8888, - Gid: 8888, - Sgids: []int{8888}, + UID: 8888, + GID: 8888, + SGIDs: []int{8888}, Home: "/8888", } @@ -326,9 +326,9 @@ this is just some garbage data passwd: false, group: false, expected: ExecUser{ - Uid: 8888, - Gid: 8888, - Sgids: []int{8888}, + UID: 8888, + GID: 8888, + SGIDs: []int{8888}, Home: "/8888", }, }, @@ -337,9 +337,9 @@ this is just some garbage data passwd: true, group: false, expected: ExecUser{ - Uid: 0, - Gid: 0, - Sgids: []int{8888}, + UID: 0, + GID: 0, + SGIDs: []int{8888}, Home: "/root", }, }, @@ -348,9 +348,9 @@ this is just some garbage data passwd: false, group: false, expected: ExecUser{ - Uid: 0, - Gid: 8888, - Sgids: []int{8888}, + UID: 0, + GID: 8888, + SGIDs: []int{8888}, Home: "/8888", }, }, @@ -359,9 +359,9 @@ this is just some garbage data passwd: false, group: false, expected: ExecUser{ - Uid: 0, - Gid: 0, - Sgids: []int{8888}, + UID: 0, + GID: 0, + SGIDs: []int{8888}, Home: "/8888", }, }, diff --git a/list.go b/list.go index 3503dcd2f5e..42b5217475c 100644 --- a/list.go +++ b/list.go @@ -134,7 +134,7 @@ func getContainers(context *cli.Context) ([]containerState, error) { } // This cast is safe on Linux. uid := st.Sys().(*syscall.Stat_t).Uid - owner, err := user.LookupUid(int(uid)) + owner, err := user.LookupUID(int(uid)) if err != nil { owner.Name = fmt.Sprintf("#%d", uid) } diff --git a/restore.go b/restore.go index dd2c8b6d715..5ced8ee126e 100644 --- a/restore.go +++ b/restore.go @@ -124,18 +124,18 @@ using the runc checkpoint command.`, }, } -func criuOptions(context *cli.Context) *libcontainer.CriuOpts { +func criuOptions(context *cli.Context) *libcontainer.CRIUOpts { imagePath, parentPath, err := prepareImagePaths(context) if err != nil { fatal(err) } - return &libcontainer.CriuOpts{ + return &libcontainer.CRIUOpts{ ImagesDirectory: imagePath, WorkDirectory: context.String("work-path"), ParentImage: parentPath, LeaveRunning: context.Bool("leave-running"), - TcpEstablished: context.Bool("tcp-established"), + TCPEstablished: context.Bool("tcp-established"), ExternalUnixConnections: context.Bool("ext-unix-sk"), ShellJob: context.Bool("shell-job"), FileLocks: context.Bool("file-locks"), diff --git a/types/events.go b/types/events.go index a2f57461e9d..703020c8ec2 100644 --- a/types/events.go +++ b/types/events.go @@ -12,7 +12,7 @@ type Event struct { // Stats is the runc specific stats structure for stability when encoding and // decoding stats. type Stats struct { - CPU Cpu `json:"cpu"` + CPU CPU `json:"cpu"` CPUSet CPUSet `json:"cpuset"` Memory Memory `json:"memory"` Pids Pids `json:"pids"` @@ -57,18 +57,18 @@ type Throttling struct { ThrottledTime uint64 `json:"throttledTime,omitempty"` } -type CpuUsage struct { +type CPUUsage struct { // Units: nanoseconds. Total uint64 `json:"total,omitempty"` - Percpu []uint64 `json:"percpu,omitempty"` - PercpuKernel []uint64 `json:"percpu_kernel,omitempty"` - PercpuUser []uint64 `json:"percpu_user,omitempty"` + PerCPU []uint64 `json:"percpu,omitempty"` + PerCPUKernel []uint64 `json:"percpu_kernel,omitempty"` + PerCPUUser []uint64 `json:"percpu_user,omitempty"` Kernel uint64 `json:"kernel"` User uint64 `json:"user"` } -type Cpu struct { - Usage CpuUsage `json:"usage,omitempty"` +type CPU struct { + Usage CPUUsage `json:"usage,omitempty"` Throttling Throttling `json:"throttling,omitempty"` } diff --git a/update.go b/update.go index d02e7af90d3..17f7f54f29a 100644 --- a/update.go +++ b/update.go @@ -272,30 +272,30 @@ other options are ignored. p, q := *r.CPU.Period, *r.CPU.Quota if (p == 0 && q == 0) || (p != 0 && q != 0) { // both values are either set or unset (0) - config.Cgroups.Resources.CpuPeriod = p - config.Cgroups.Resources.CpuQuota = q + config.Cgroups.Resources.CPUPeriod = p + config.Cgroups.Resources.CPUQuota = q } else { // one is set and the other is not if p != 0 { // set new period, leave quota at old value - config.Cgroups.Resources.CpuPeriod = p + config.Cgroups.Resources.CPUPeriod = p } else if q != 0 { // set new quota, leave period at old value - config.Cgroups.Resources.CpuQuota = q + config.Cgroups.Resources.CPUQuota = q } } - config.Cgroups.Resources.CpuShares = *r.CPU.Shares + config.Cgroups.Resources.CPUShares = *r.CPU.Shares // CpuWeight is used for cgroupv2 and should be converted - config.Cgroups.Resources.CpuWeight = cgroups.ConvertCPUSharesToCgroupV2Value(*r.CPU.Shares) - config.Cgroups.Resources.CpuRtPeriod = *r.CPU.RealtimePeriod - config.Cgroups.Resources.CpuRtRuntime = *r.CPU.RealtimeRuntime - config.Cgroups.Resources.CpusetCpus = r.CPU.Cpus - config.Cgroups.Resources.CpusetMems = r.CPU.Mems + config.Cgroups.Resources.CPUWeight = cgroups.ConvertCPUSharesToCgroupV2Value(*r.CPU.Shares) + config.Cgroups.Resources.CPURtPeriod = *r.CPU.RealtimePeriod + config.Cgroups.Resources.CPURtRuntime = *r.CPU.RealtimeRuntime + config.Cgroups.Resources.CPUSetCPUs = r.CPU.Cpus + config.Cgroups.Resources.CPUSetMems = r.CPU.Mems config.Cgroups.Resources.Memory = *r.Memory.Limit config.Cgroups.Resources.MemoryReservation = *r.Memory.Reservation config.Cgroups.Resources.MemorySwap = *r.Memory.Swap - config.Cgroups.Resources.PidsLimit = r.Pids.Limit + config.Cgroups.Resources.PIDsLimit = r.Pids.Limit config.Cgroups.Resources.Unified = r.Unified // Update Intel RDT diff --git a/utils_linux.go b/utils_linux.go index 69dc62d9e52..ee9bc2c62ba 100644 --- a/utils_linux.go +++ b/utils_linux.go @@ -47,9 +47,9 @@ func loadFactory(context *cli.Context) (libcontainer.Factory, error) { } return libcontainer.New(abs, intelRdtManager, - libcontainer.CriuPath(context.GlobalString("criu")), - libcontainer.NewuidmapPath(newuidmap), - libcontainer.NewgidmapPath(newgidmap)) + libcontainer.CRIUPath(context.GlobalString("criu")), + libcontainer.NewUIDMapPath(newuidmap), + libcontainer.NewGIDMapPath(newgidmap)) } // getContainer returns the specified container instance by loading it from state @@ -231,7 +231,7 @@ type runner struct { container libcontainer.Container action ctAct notifySocket *notifySocket - criuOpts *libcontainer.CriuOpts + criuOpts *libcontainer.CRIUOpts subCgroupPaths map[string]string } @@ -371,7 +371,7 @@ const ( actRestore // Restore container ) -func startContainer(context *cli.Context, action ctAct, criuOpts *libcontainer.CriuOpts) (int, error) { +func startContainer(context *cli.Context, action ctAct, criuOpts *libcontainer.CRIUOpts) (int, error) { if err := revisePidFile(context); err != nil { return -1, err }