Skip to content

Commit

Permalink
Rename variables to have correct capitalization
Browse files Browse the repository at this point in the history
    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 <[email protected]>
  • Loading branch information
thaJeztah committed Jan 4, 2022
1 parent 38916c9 commit 900a3fc
Show file tree
Hide file tree
Showing 60 changed files with 463 additions and 463 deletions.
8 changes: 4 additions & 4 deletions checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func prepareImagePaths(context *cli.Context) (string, string, error) {
return imagePath, parentPath, nil
}

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

func setManageCgroupsMode(context *cli.Context, options *libcontainer.CriuOpts) {
func setManageCgroupsMode(context *cli.Context, options *libcontainer.CRIUOpts) {
if cgOpt := context.String("manage-cgroups-mode"); cgOpt != "" {
switch cgOpt {
case "soft":
Expand All @@ -148,7 +148,7 @@ var namespaceMapping = map[specs.LinuxNamespaceType]int{
specs.NetworkNamespace: unix.CLONE_NEWNET,
}

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

Expand Down
24 changes: 12 additions & 12 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ func convertLibcontainerStats(ls *libcontainer.Stats) *types.Stats {
return nil
}
var s types.Stats
s.Pids.Current = cg.PidsStats.Current
s.Pids.Limit = cg.PidsStats.Limit

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions libcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ config := &configs.Config{
Flags: defaultMountFlags | unix.MS_RDONLY,
},
},
UidMappings: []configs.IDMap{
UIDMappings: []configs.IDMap{
{
ContainerID: 0,
HostID: 1000,
Size: 65536,
},
},
GidMappings: []configs.IDMap{
GIDMappings: []configs.IDMap{
{
ContainerID: 0,
HostID: 1000,
Expand Down
40 changes: 20 additions & 20 deletions libcontainer/cgroups/fs/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
"golang.org/x/sys/unix"
)

type CpuGroup struct{}
type CPUGroup struct{}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

if err := cpu.Apply(path, r, 1234); err != nil {
t.Fatal(err)
Expand Down
12 changes: 6 additions & 6 deletions libcontainer/cgroups/fs/cpuacct.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func (s *CpuacctGroup) GetStats(path string, stats *cgroups.Stats) error {
return err
}

stats.CpuStats.CpuUsage.TotalUsage = totalUsage
stats.CpuStats.CpuUsage.PercpuUsage = percpuUsage
stats.CpuStats.CpuUsage.PercpuUsageInKernelmode = percpuUsageInKernelmode
stats.CpuStats.CpuUsage.PercpuUsageInUsermode = percpuUsageInUsermode
stats.CpuStats.CpuUsage.UsageInUsermode = userModeUsage
stats.CpuStats.CpuUsage.UsageInKernelmode = kernelModeUsage
stats.CPUStats.CPUUsage.TotalUsage = totalUsage
stats.CPUStats.CPUUsage.PerCPUUsage = percpuUsage
stats.CPUStats.CPUUsage.PerCPUUsageInKernelmode = percpuUsageInKernelmode
stats.CPUStats.CPUUsage.PerCPUUsageInUsermode = percpuUsageInUsermode
stats.CPUStats.CPUUsage.UsageInUsermode = userModeUsage
stats.CPUStats.CPUUsage.UsageInKernelmode = kernelModeUsage
return nil
}

Expand Down
24 changes: 12 additions & 12 deletions libcontainer/cgroups/fs/cpuacct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ 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,
},
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)
}
}

Expand All @@ -78,20 +78,20 @@ func TestCpuacctStatsWithoutUsageAll(t *testing.T) {
t.Fatal(err)
}

expectedStats := cgroups.CpuUsage{
expectedStats := cgroups.CPUUsage{
TotalUsage: uint64(12262454190222160),
PercpuUsage: []uint64{
PerCPUUsage: []uint64{
1564936537989058, 1583937096487821, 1604195415465681, 1596445226820187,
1481069084155629, 1478735613864327, 1477610593414743, 1476362015778086,
},
PercpuUsageInKernelmode: []uint64{},
PercpuUsageInUsermode: []uint64{},
PerCPUUsageInKernelmode: []uint64{},
PerCPUUsageInUsermode: []uint64{},
UsageInKernelmode: (uint64(291429664) * nanosecondsInSecond) / clockTicks,
UsageInUsermode: (uint64(452278264) * nanosecondsInSecond) / clockTicks,
}

if !reflect.DeepEqual(expectedStats, actualStats.CpuStats.CpuUsage) {
if !reflect.DeepEqual(expectedStats, actualStats.CPUStats.CPUUsage) {
t.Errorf("Expected CPU usage %#v but found %#v\n",
expectedStats, actualStats.CpuStats.CpuUsage)
expectedStats, actualStats.CPUStats.CPUUsage)
}
}
8 changes: 4 additions & 4 deletions libcontainer/cgroups/fs/cpuset.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func (s *CpusetGroup) Apply(path string, r *configs.Resources, pid int) error {
}

func (s *CpusetGroup) Set(path string, r *configs.Resources) error {
if r.CpusetCpus != "" {
if err := cgroups.WriteFile(path, "cpuset.cpus", r.CpusetCpus); err != nil {
if r.CPUSetCPUs != "" {
if err := cgroups.WriteFile(path, "cpuset.cpus", r.CPUSetCPUs); err != nil {
return err
}
}
if r.CpusetMems != "" {
if err := cgroups.WriteFile(path, "cpuset.mems", r.CpusetMems); err != nil {
if r.CPUSetMems != "" {
if err := cgroups.WriteFile(path, "cpuset.mems", r.CPUSetMems); err != nil {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions libcontainer/cgroups/fs/cpuset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestCPUSetSetCpus(t *testing.T) {
})

r := &configs.Resources{
CpusetCpus: cpusAfter,
CPUSetCPUs: cpusAfter,
}
cpuset := &CpusetGroup{}
if err := cpuset.Set(path, r); err != nil {
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestCPUSetSetMems(t *testing.T) {
})

r := &configs.Resources{
CpusetMems: memsAfter,
CPUSetMems: memsAfter,
}
cpuset := &CpusetGroup{}
if err := cpuset.Set(path, r); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion libcontainer/cgroups/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var subsystems = []subsystem{
&CpusetGroup{},
&DevicesGroup{},
&MemoryGroup{},
&CpuGroup{},
&CPUGroup{},
&CpuacctGroup{},
&PidsGroup{},
&BlkioGroup{},
Expand Down
2 changes: 1 addition & 1 deletion libcontainer/cgroups/fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func BenchmarkGetStats(b *testing.B) {
b.Fatal(err)
}
}
if st.CpuStats.CpuUsage.TotalUsage != 0 {
if st.CPUStats.CPUUsage.TotalUsage != 0 {
b.Fatalf("stats: %+v", st)
}
}
Loading

0 comments on commit 900a3fc

Please sign in to comment.