From 55e210f94c7d94c4835984b9b332ac51adbf656e 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/cgroups/fs/cpu.go | 38 +++--- 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/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 | 16 +-- libcontainer/configs/validate/validator.go | 2 +- .../configs/validate/validator_test.go | 2 +- libcontainer/container_linux.go | 98 +++++++-------- 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 | 40 +++---- libcontainer/init_linux.go | 18 +-- libcontainer/integration/checkpoint_test.go | 4 +- libcontainer/integration/exec_test.go | 14 +-- libcontainer/integration/execin_test.go | 6 +- libcontainer/integration/template_test.go | 4 +- 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/user/lookup_unix.go | 12 +- libcontainer/user/user.go | 60 +++++----- libcontainer/user/user_test.go | 112 +++++++++--------- list.go | 2 +- restore.go | 6 +- types/events.go | 14 +-- update.go | 22 ++-- utils_linux.go | 10 +- 53 files changed, 437 insertions(+), 437 deletions(-) diff --git a/checkpoint.go b/checkpoint.go index 4990f12b1d9..8c1a0b89917 100644 --- a/checkpoint.go +++ b/checkpoint.go @@ -111,7 +111,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 != "" { @@ -124,14 +124,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": @@ -150,7 +150,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 0d1510667eb..5faef20fc9b 100644 --- a/events.go +++ b/events.go @@ -119,18 +119,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/cgroups/fs/cpu.go b/libcontainer/cgroups/fs/cpu.go index 04bd5bc9fb9..27ef98b2b1b 100644 --- a/libcontainer/cgroups/fs/cpu.go +++ b/libcontainer/cgroups/fs/cpu.go @@ -13,13 +13,13 @@ import ( "github.com/opencontainers/runc/libcontainer/configs" ) -type CpuGroup struct{} +type CPUGroup struct{} -func (s *CpuGroup) Name() string { +func (s *CPUGroup) Name() string { return "cpu" } -func (s *CpuGroup) Apply(path string, d *cgroupData) error { +func (s *CPUGroup) Apply(path string, d *cgroupData) error { // This might happen if we have no cpu cgroup mounted. // Just do nothing and don't fail. if path == "" { @@ -39,23 +39,23 @@ func (s *CpuGroup) Apply(path string, d *cgroupData) error { return cgroups.WriteCgroupProc(path, d.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 } @@ -71,20 +71,20 @@ func (s *CpuGroup) Set(path string, r *configs.Resources) error { return fmt.Errorf("the minimum allowed cpu-shares is %d", sharesRead) } } - if r.CpuPeriod != 0 { - if err := cgroups.WriteFile(path, "cpu.cfs_period_us", strconv.FormatUint(r.CpuPeriod, 10)); err != nil { + if r.CPUPeriod != 0 { + if err := cgroups.WriteFile(path, "cpu.cfs_period_us", strconv.FormatUint(r.CPUPeriod, 10)); err != nil { return err } } - 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 } } 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 { @@ -103,13 +103,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 2348247c22d..830c2dc2bbb 100644 --- a/libcontainer/cgroups/fs/cpu_test.go +++ b/libcontainer/cgroups/fs/cpu_test.go @@ -24,8 +24,8 @@ func TestCpuSetShares(t *testing.T) { "cpu.shares": strconv.Itoa(sharesBefore), }) - helper.CgroupData.config.Resources.CpuShares = sharesAfter - cpu := &CpuGroup{} + helper.CgroupData.config.Resources.CPUShares = sharesAfter + cpu := &CPUGroup{} if err := cpu.Set(helper.CgroupPath, helper.CgroupData.config.Resources); err != nil { t.Fatal(err) } @@ -61,11 +61,11 @@ func TestCpuSetBandWidth(t *testing.T) { "cpu.rt_period_us": strconv.Itoa(rtPeriodBefore), }) - helper.CgroupData.config.Resources.CpuQuota = quotaAfter - helper.CgroupData.config.Resources.CpuPeriod = periodAfter - helper.CgroupData.config.Resources.CpuRtRuntime = rtRuntimeAfter - helper.CgroupData.config.Resources.CpuRtPeriod = rtPeriodAfter - cpu := &CpuGroup{} + helper.CgroupData.config.Resources.CPUQuota = quotaAfter + helper.CgroupData.config.Resources.CPUPeriod = periodAfter + helper.CgroupData.config.Resources.CPURtRuntime = rtRuntimeAfter + helper.CgroupData.config.Resources.CPURtPeriod = rtPeriodAfter + cpu := &CPUGroup{} if err := cpu.Set(helper.CgroupPath, helper.CgroupData.config.Resources); 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(helper.CgroupPath, &actualStats) if err != nil { @@ -132,14 +132,14 @@ func TestCpuStats(t *testing.T) { ThrottledTime: throttledTime, } - expectThrottlingDataEquals(t, expectedStats, actualStats.CpuStats.ThrottlingData) + expectThrottlingDataEquals(t, expectedStats, actualStats.CPUStats.ThrottlingData) } func TestNoCpuStatFile(t *testing.T) { helper := newCgroupTestUtil("cpu", t) defer helper.cleanup() - cpu := &CpuGroup{} + cpu := &CPUGroup{} actualStats := *cgroups.NewStats() err := cpu.GetStats(helper.CgroupPath, &actualStats) if err != nil { @@ -157,7 +157,7 @@ func TestInvalidCpuStat(t *testing.T) { "cpu.stat": cpuStatContent, }) - cpu := &CpuGroup{} + cpu := &CPUGroup{} actualStats := *cgroups.NewStats() err := cpu.GetStats(helper.CgroupPath, &actualStats) if err == nil { @@ -181,9 +181,9 @@ func TestCpuSetRtSchedAtApply(t *testing.T) { "cpu.rt_period_us": strconv.Itoa(rtPeriodBefore), }) - helper.CgroupData.config.Resources.CpuRtRuntime = rtRuntimeAfter - helper.CgroupData.config.Resources.CpuRtPeriod = rtPeriodAfter - cpu := &CpuGroup{} + helper.CgroupData.config.Resources.CPURtRuntime = rtRuntimeAfter + helper.CgroupData.config.Resources.CPURtPeriod = rtPeriodAfter + cpu := &CPUGroup{} helper.CgroupData.pid = 1234 if err := cpu.Apply(helper.CgroupPath, helper.CgroupData); err != nil { diff --git a/libcontainer/cgroups/fs/cpuacct.go b/libcontainer/cgroups/fs/cpuacct.go index 2fcd52892b1..811018c3e3a 100644 --- a/libcontainer/cgroups/fs/cpuacct.go +++ b/libcontainer/cgroups/fs/cpuacct.go @@ -68,12 +68,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 7324e027dc1..1a0b8d176db 100644 --- a/libcontainer/cgroups/fs/cpuacct_test.go +++ b/libcontainer/cgroups/fs/cpuacct_test.go @@ -42,17 +42,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, }, @@ -60,9 +60,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) } } @@ -82,20 +82,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 05ee2693708..a43514ccd69 100644 --- a/libcontainer/cgroups/fs/cpuset.go +++ b/libcontainer/cgroups/fs/cpuset.go @@ -27,13 +27,13 @@ func (s *CpusetGroup) Apply(path string, d *cgroupData) 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 b99f4ac55c0..247b802f0b1 100644 --- a/libcontainer/cgroups/fs/cpuset_test.go +++ b/libcontainer/cgroups/fs/cpuset_test.go @@ -51,7 +51,7 @@ func TestCPUSetSetCpus(t *testing.T) { "cpuset.cpus": cpusBefore, }) - helper.CgroupData.config.Resources.CpusetCpus = cpusAfter + helper.CgroupData.config.Resources.CPUSetCPUs = cpusAfter cpuset := &CpusetGroup{} if err := cpuset.Set(helper.CgroupPath, helper.CgroupData.config.Resources); err != nil { t.Fatal(err) @@ -79,7 +79,7 @@ func TestCPUSetSetMems(t *testing.T) { "cpuset.mems": memsBefore, }) - helper.CgroupData.config.Resources.CpusetMems = memsAfter + helper.CgroupData.config.Resources.CPUSetMems = memsAfter cpuset := &CpusetGroup{} if err := cpuset.Set(helper.CgroupPath, helper.CgroupData.config.Resources); err != nil { t.Fatal(err) diff --git a/libcontainer/cgroups/fs/fs.go b/libcontainer/cgroups/fs/fs.go index 869e313b388..56bc3fcb92c 100644 --- a/libcontainer/cgroups/fs/fs.go +++ b/libcontainer/cgroups/fs/fs.go @@ -22,7 +22,7 @@ var ( &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 1d16ca5e76d..7a5953a179d 100644 --- a/libcontainer/cgroups/fs/fs_test.go +++ b/libcontainer/cgroups/fs/fs_test.go @@ -139,7 +139,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 9f257e5ce7d..d323fb6b3fb 100644 --- a/libcontainer/cgroups/fs/memory.go +++ b/libcontainer/cgroups/fs/memory.go @@ -117,7 +117,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 83aa6bffff4..de6d3cfb49f 100644 --- a/libcontainer/cgroups/fs/pids.go +++ b/libcontainer/cgroups/fs/pids.go @@ -22,12 +22,12 @@ func (s *PidsGroup) Apply(path string, d *cgroupData) 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 { @@ -58,7 +58,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 55edac5177b..07093c4a5d5 100644 --- a/libcontainer/cgroups/fs/pids_test.go +++ b/libcontainer/cgroups/fs/pids_test.go @@ -23,7 +23,7 @@ func TestPidsSetMax(t *testing.T) { "pids.max": "max", }) - helper.CgroupData.config.Resources.PidsLimit = maxLimited + helper.CgroupData.config.Resources.PIDsLimit = maxLimited pids := &PidsGroup{} if err := pids.Set(helper.CgroupPath, helper.CgroupData.config.Resources); err != nil { t.Fatal(err) @@ -46,7 +46,7 @@ func TestPidsSetUnlimited(t *testing.T) { "pids.max": strconv.Itoa(maxLimited), }) - helper.CgroupData.config.Resources.PidsLimit = maxUnlimited + helper.CgroupData.config.Resources.PIDsLimit = maxUnlimited pids := &PidsGroup{} if err := pids.Set(helper.CgroupPath, helper.CgroupData.config.Resources); err != nil { t.Fatal(err) @@ -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) } } @@ -100,11 +100,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 bd34b7f670b..2e477e8062c 100644 --- a/libcontainer/cgroups/fs2/cpu.go +++ b/libcontainer/cgroups/fs2/cpu.go @@ -13,7 +13,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 { @@ -22,18 +22,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 @@ -64,22 +64,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 da29d7f2bbb..e75e8000713 100644 --- a/libcontainer/cgroups/fs2/cpuset.go +++ b/libcontainer/cgroups/fs2/cpuset.go @@ -7,22 +7,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 2a861b7d831..e8fa93d2e3b 100644 --- a/libcontainer/cgroups/fs2/fs2.go +++ b/libcontainer/cgroups/fs2/fs2.go @@ -173,7 +173,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 f4c70179cd5..43b7e3f9aea 100644 --- a/libcontainer/cgroups/fs2/pids.go +++ b/libcontainer/cgroups/fs2/pids.go @@ -16,14 +16,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 } @@ -43,8 +43,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 } @@ -68,7 +68,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 e7f9c462635..5cf4aaec7ae 100644 --- a/libcontainer/cgroups/stats.go +++ b/libcontainer/cgroups/stats.go @@ -11,21 +11,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"` @@ -34,8 +34,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"` } @@ -111,7 +111,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 @@ -147,10 +147,10 @@ type HugetlbStats 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/v1.go b/libcontainer/cgroups/systemd/v1.go index 130853fff97..f54d65490b6 100644 --- a/libcontainer/cgroups/systemd/v1.go +++ b/libcontainer/cgroups/systemd/v1.go @@ -47,7 +47,7 @@ var legacySubsystems = []subsystem{ &fs.CpusetGroup{}, &fs.DevicesGroup{}, &fs.MemoryGroup{}, - &fs.CpuGroup{}, + &fs.CPUGroup{}, &fs.CpuacctGroup{}, &fs.PidsGroup{}, &fs.BlkioGroup{}, @@ -73,24 +73,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 2a22ec7c584..46d3a80b816 100644 --- a/libcontainer/cgroups/systemd/v2.go +++ b/libcontainer/cgroups/systemd/v2.go @@ -196,19 +196,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 557b255e6f7..b5e3d5c1933 100644 --- a/libcontainer/configs/cgroup_linux.go +++ b/libcontainer/configs/cgroup_linux.go @@ -57,28 +57,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"` @@ -108,7 +108,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"` @@ -121,8 +121,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 6021a4a889b..7b8e89eddd2 100644 --- a/libcontainer/configs/config.go +++ b/libcontainer/configs/config.go @@ -148,18 +148,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..db02ad5a39c 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,13 +103,13 @@ 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") } 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") } @@ -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 c2500a63052..27d916cb32d 100644 --- a/libcontainer/configs/validate/validator.go +++ b/libcontainer/configs/validate/validator.go @@ -115,7 +115,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 687ce1b09a4..94232042d9f 100644 --- a/libcontainer/configs/validate/validator_test.go +++ b/libcontainer/configs/validate/validator_test.go @@ -176,7 +176,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 := validate.New() diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index e710aab3634..7b7aa1c8c7e 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -97,10 +97,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,7 +580,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, @@ -675,7 +675,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 @@ -726,7 +726,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) @@ -735,12 +735,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() @@ -751,12 +751,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) extMnt := &criurpc.ExtMountMap{ Key: proto.String(mountDest), @@ -787,7 +787,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' @@ -826,7 +826,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 { @@ -924,7 +924,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() @@ -935,7 +935,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 } @@ -965,7 +965,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), @@ -987,7 +987,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 @@ -1007,7 +1007,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) } @@ -1039,7 +1039,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 } @@ -1053,7 +1053,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 } @@ -1068,7 +1068,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)) @@ -1087,7 +1087,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) @@ -1099,7 +1099,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error { return err } for _, b := range binds { - c.addCriuDumpMount(req, b) + c.addCRIUDumpMount(req, b) } } } @@ -1110,7 +1110,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 @@ -1132,7 +1132,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) extMnt := &criurpc.ExtMountMap{ Key: proto.String(mountDest), @@ -1141,7 +1141,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": @@ -1161,10 +1161,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: @@ -1208,13 +1208,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 { @@ -1243,7 +1243,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 @@ -1271,7 +1271,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() @@ -1283,7 +1283,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 == "" { @@ -1327,7 +1327,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), @@ -1339,7 +1339,7 @@ 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) @@ -1358,7 +1358,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 @@ -1366,7 +1366,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 } @@ -1374,7 +1374,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 @@ -1385,19 +1385,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 { @@ -1476,7 +1476,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 @@ -1695,7 +1695,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()) @@ -2034,14 +2034,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 } @@ -2052,8 +2052,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 } @@ -2076,11 +2076,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)), }) } @@ -2124,5 +2124,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 ebd32a6b8e7..b42cedbd2e0 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 47e586c6c78..dd9853ade29 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 edd3a979959..0d3b2e7372d 100644 --- a/libcontainer/factory_linux.go +++ b/libcontainer/factory_linux.go @@ -177,11 +177,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 } } @@ -199,7 +199,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", } if err := Cgroupfs(l); err != nil { @@ -230,14 +230,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 @@ -280,9 +280,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: l.NewCgroupsManager(config.Cgroups, nil), } if l.NewIntelRdtManager != nil { @@ -320,9 +320,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: l.NewCgroupsManager(state.Config.Cgroups, state.CgroupPaths), root: containerRoot, created: state.Created, @@ -439,20 +439,20 @@ 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 } } diff --git a/libcontainer/init_linux.go b/libcontainer/init_linux.go index 7fb230eab5a..76d8b80c750 100644 --- a/libcontainer/init_linux.go +++ b/libcontainer/init_linux.go @@ -63,7 +63,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"` @@ -277,8 +277,8 @@ func syncParentHooks(pipe io.ReadWriter) error { func setupUser(config *initConfig) error { // Set up defaults. defaultExecUser := user.ExecUser{ - Uid: 0, - Gid: 0, + UID: 0, + GID: 0, Home: "/", } @@ -307,10 +307,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") } @@ -342,16 +342,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 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 } @@ -393,7 +393,7 @@ func fixStdioPermissions(config *initConfig, 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 f2870ae0529..865d1c5dd13 100644 --- a/libcontainer/integration/checkpoint_test.go +++ b/libcontainer/integration/checkpoint_test.go @@ -110,7 +110,7 @@ func testCheckpoint(t *testing.T, userns bool) { ok(t, err) defer remove(parentDir) - preDumpOpts := &libcontainer.CriuOpts{ + preDumpOpts := &libcontainer.CRIUOpts{ ImagesDirectory: parentDir, WorkDirectory: parentDir, PreDump: true, @@ -133,7 +133,7 @@ func testCheckpoint(t *testing.T, userns bool) { ok(t, err) defer remove(imagesDir) - 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 502a6499304..20834de429d 100644 --- a/libcontainer/integration/exec_test.go +++ b/libcontainer/integration/exec_test.go @@ -576,7 +576,7 @@ func testCPUShares(t *testing.T, systemd bool) { rootfs: rootfs, systemd: systemd, }) - config.Cgroups.Resources.CpuShares = 1 + config.Cgroups.Resources.CPUShares = 1 _, _, err = runContainer(t, config, "", "ps") if err == nil { @@ -608,7 +608,7 @@ func testPids(t *testing.T, systemd bool) { rootfs: rootfs, 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") @@ -620,7 +620,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 | @@ -634,7 +634,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 | @@ -1110,7 +1110,7 @@ func TestOomScoreAdj(t *testing.T) { defer remove(rootfs) config := newTemplateConfig(t, &tParam{rootfs: rootfs}) - config.OomScoreAdj = ptrInt(200) + config.OOMScoreAdj = ptrInt(200) container, err := newContainer(t, config) ok(t, err) @@ -1133,8 +1133,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) } } diff --git a/libcontainer/integration/execin_test.go b/libcontainer/integration/execin_test.go index bfdbac028bf..d90c839bda0 100644 --- a/libcontainer/integration/execin_test.go +++ b/libcontainer/integration/execin_test.go @@ -485,7 +485,7 @@ func TestExecInOomScoreAdj(t *testing.T) { ok(t, err) defer remove(rootfs) config := newTemplateConfig(t, &tParam{rootfs: rootfs}) - config.OomScoreAdj = ptrInt(200) + config.OOMScoreAdj = ptrInt(200) container, err := newContainer(t, config) ok(t, err) defer destroyContainer(container) @@ -521,8 +521,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 c9ebff7e05f..92e76abad0e 100644 --- a/libcontainer/integration/template_test.go +++ b/libcontainer/integration/template_test.go @@ -202,8 +202,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/rootfs_linux.go b/libcontainer/rootfs_linux.go index 127103063b5..1e54887f24b 100644 --- a/libcontainer/rootfs_linux.go +++ b/libcontainer/rootfs_linux.go @@ -715,7 +715,7 @@ func mknodDevice(dest string, node *devices.Device) error { if err := unix.Mknod(dest, uint32(fileMode), int(dev)); err != nil { return err } - return unix.Chown(dest, int(node.Uid), int(node.Gid)) + return unix.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 89b5609a6b6..28d9440f447 100644 --- a/libcontainer/setns_init_linux.go +++ b/libcontainer/setns_init_linux.go @@ -29,7 +29,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 cbcb7d14059..15698874a57 100644 --- a/libcontainer/specconv/spec_linux.go +++ b/libcontainer/specconv/spec_linux.go @@ -86,8 +86,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, @@ -99,8 +99,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, @@ -112,8 +112,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, @@ -125,8 +125,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, @@ -138,8 +138,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, @@ -151,8 +151,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, @@ -310,7 +310,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 if spec.Process.SelinuxLabel != "" { @@ -529,37 +529,37 @@ 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 } if r.CPU.Cpus != "" { - c.Resources.CpusetCpus = r.CPU.Cpus + c.Resources.CPUSetCPUs = r.CPU.Cpus } if r.CPU.Mems != "" { - c.Resources.CpusetMems = r.CPU.Mems + 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 { @@ -717,8 +717,8 @@ next: }, Path: d.Path, FileMode: filemode, - Uid: uid, - Gid: gid, + UID: uid, + GID: gid, } config.Devices = append(config.Devices, device) } @@ -737,10 +737,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() @@ -752,8 +752,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 6b0457ede0c..916f24bd796 100644 --- a/libcontainer/specconv/spec_linux_test.go +++ b/libcontainer/specconv/spec_linux_test.go @@ -277,7 +277,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") } } @@ -715,8 +715,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 b194507903d..f4b1ac6d29f 100644 --- a/libcontainer/standard_init_linux.go +++ b/libcontainer/standard_init_linux.go @@ -44,7 +44,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/user/lookup_unix.go b/libcontainer/user/lookup_unix.go index 967717a1b1c..d00a4ae49b3 100644 --- a/libcontainer/user/lookup_unix.go +++ b/libcontainer/user/lookup_unix.go @@ -25,12 +25,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 }) } @@ -71,7 +71,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 }) } @@ -118,7 +118,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 @@ -134,7 +134,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 998daab0077..48a0a165d5f 100644 --- a/libcontainer/user/user.go +++ b/libcontainer/user/user.go @@ -27,8 +27,8 @@ var ( type User struct { Name string Pass string - Uid int - Gid int + UID int + GID int Gecos string Home string Shell string @@ -37,7 +37,7 @@ type User struct { type Group struct { Name string Pass string - Gid int + GID int List []string } @@ -139,7 +139,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) @@ -197,7 +197,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(text, &p.Name, &p.Pass, &p.Gid, &p.List) + parseLine(text, &p.Name, &p.Pass, &p.GID, &p.List) if filter == nil || filter(p) { out = append(out, p) @@ -211,9 +211,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 } @@ -265,15 +265,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 @@ -289,12 +289,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 @@ -303,7 +303,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) } @@ -312,8 +312,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 @@ -323,10 +323,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 } @@ -350,7 +350,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 @@ -363,7 +363,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. @@ -372,10 +372,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 } @@ -383,9 +383,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 } } } @@ -404,7 +404,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 } } @@ -421,9 +421,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 23bf46672c5..eb6e9d006b3 100644 --- a/libcontainer/user/user_test.go +++ b/libcontainer/user/user_test.go @@ -69,11 +69,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) } } @@ -89,11 +89,11 @@ this is just some garbage data if len(groups) != 3 { t.Fatalf("Expected 3 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)) } } @@ -114,9 +114,9 @@ odd:x:444: this is just some garbage data ` defaultExecUser := ExecUser{ - Uid: 8888, - Gid: 8888, - Sgids: []int{8888}, + UID: 8888, + GID: 8888, + SGIDs: []int{8888}, Home: "/8888", } @@ -127,72 +127,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, }, }, @@ -201,18 +201,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", }, }, @@ -297,9 +297,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", } @@ -313,9 +313,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", }, }, @@ -324,9 +324,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", }, }, @@ -335,9 +335,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", }, }, @@ -346,9 +346,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 5a1c0850351..819b3da2b54 100644 --- a/list.go +++ b/list.go @@ -133,7 +133,7 @@ func getContainers(context *cli.Context) ([]containerState, error) { if item.IsDir() { // This cast is safe on Linux. stat := item.Sys().(*syscall.Stat_t) - owner, err := user.LookupUid(int(stat.Uid)) + owner, err := user.LookupUID(int(stat.Uid)) if err != nil { owner.Name = fmt.Sprintf("#%d", stat.Uid) } diff --git a/restore.go b/restore.go index 01fa2c89d2d..3e59ae36bdb 100644 --- a/restore.go +++ b/restore.go @@ -125,18 +125,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 e678e220408..06ae6a9cfb2 100644 --- a/update.go +++ b/update.go @@ -274,30 +274,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 53ebc36bd97..d636dd2484e 100644 --- a/utils_linux.go +++ b/utils_linux.go @@ -70,9 +70,9 @@ func loadFactory(context *cli.Context) (libcontainer.Factory, error) { } return libcontainer.New(abs, cgroupManager, 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 @@ -258,7 +258,7 @@ type runner struct { container libcontainer.Container action ctAct notifySocket *notifySocket - criuOpts *libcontainer.CriuOpts + criuOpts *libcontainer.CRIUOpts logLevel string } @@ -397,7 +397,7 @@ const ( actRestore // Restore container ) -func startContainer(context *cli.Context, spec *specs.Spec, action ctAct, criuOpts *libcontainer.CriuOpts) (int, error) { +func startContainer(context *cli.Context, spec *specs.Spec, action ctAct, criuOpts *libcontainer.CRIUOpts) (int, error) { id := context.Args().First() if id == "" { return -1, errEmptyID