Browse code

Merge pull request #15380 from calavera/remove_sys_info_pointers

Remove pointers from the SysInfo struct.

Alexandre Beslic authored on 2015/08/18 10:40:54
Showing 2 changed files
... ...
@@ -6,10 +6,10 @@ type SysInfo struct {
6 6
 	// Whether the kernel supports AppArmor or not
7 7
 	AppArmor bool
8 8
 
9
-	*cgroupMemInfo
10
-	*cgroupCPUInfo
11
-	*cgroupBlkioInfo
12
-	*cgroupCpusetInfo
9
+	cgroupMemInfo
10
+	cgroupCPUInfo
11
+	cgroupBlkioInfo
12
+	cgroupCpusetInfo
13 13
 
14 14
 	// Whether IPv4 forwarding is supported or not, if this was disabled, networking will not work
15 15
 	IPv4ForwardingDisabled bool
... ...
@@ -35,89 +35,96 @@ func New(quiet bool) *SysInfo {
35 35
 	return sysInfo
36 36
 }
37 37
 
38
-func checkCgroupMem(quiet bool) *cgroupMemInfo {
39
-	info := &cgroupMemInfo{}
38
+// checkCgroupMem reads the memory information from the memory cgroup mount point.
39
+func checkCgroupMem(quiet bool) cgroupMemInfo {
40 40
 	mountPoint, err := cgroups.FindCgroupMountpoint("memory")
41 41
 	if err != nil {
42 42
 		if !quiet {
43 43
 			logrus.Warnf("Your kernel does not support cgroup memory limit: %v", err)
44 44
 		}
45
-		return info
45
+		return cgroupMemInfo{}
46 46
 	}
47
-	info.MemoryLimit = true
48 47
 
49
-	info.SwapLimit = cgroupEnabled(mountPoint, "memory.memsw.limit_in_bytes")
50
-	if !quiet && !info.SwapLimit {
48
+	swapLimit := cgroupEnabled(mountPoint, "memory.memsw.limit_in_bytes")
49
+	if !quiet && !swapLimit {
51 50
 		logrus.Warn("Your kernel does not support swap memory limit.")
52 51
 	}
53
-	info.OomKillDisable = cgroupEnabled(mountPoint, "memory.oom_control")
54
-	if !quiet && !info.OomKillDisable {
52
+	oomKillDisable := cgroupEnabled(mountPoint, "memory.oom_control")
53
+	if !quiet && !oomKillDisable {
55 54
 		logrus.Warnf("Your kernel does not support oom control.")
56 55
 	}
57
-	info.MemorySwappiness = cgroupEnabled(mountPoint, "memory.swappiness")
58
-	if !quiet && !info.MemorySwappiness {
56
+	memorySwappiness := cgroupEnabled(mountPoint, "memory.swappiness")
57
+	if !quiet && !memorySwappiness {
59 58
 		logrus.Warnf("Your kernel does not support memory swappiness.")
60 59
 	}
61 60
 
62
-	return info
61
+	return cgroupMemInfo{
62
+		MemoryLimit:      true,
63
+		SwapLimit:        swapLimit,
64
+		OomKillDisable:   oomKillDisable,
65
+		MemorySwappiness: memorySwappiness,
66
+	}
63 67
 }
64 68
 
65
-func checkCgroupCPU(quiet bool) *cgroupCPUInfo {
66
-	info := &cgroupCPUInfo{}
69
+// checkCgroupCPU reads the cpu information from the cpu cgroup mount point.
70
+func checkCgroupCPU(quiet bool) cgroupCPUInfo {
67 71
 	mountPoint, err := cgroups.FindCgroupMountpoint("cpu")
68 72
 	if err != nil {
69 73
 		if !quiet {
70 74
 			logrus.Warn(err)
71 75
 		}
72
-		return info
76
+		return cgroupCPUInfo{}
73 77
 	}
74 78
 
75
-	info.CPUShares = cgroupEnabled(mountPoint, "cpu.shares")
76
-	if !quiet && !info.CPUShares {
79
+	cpuShares := cgroupEnabled(mountPoint, "cpu.shares")
80
+	if !quiet && !cpuShares {
77 81
 		logrus.Warn("Your kernel does not support cgroup cpu shares")
78 82
 	}
79 83
 
80
-	info.CPUCfsPeriod = cgroupEnabled(mountPoint, "cpu.cfs_period_us")
81
-	if !quiet && !info.CPUCfsPeriod {
84
+	cpuCfsPeriod := cgroupEnabled(mountPoint, "cpu.cfs_period_us")
85
+	if !quiet && !cpuCfsPeriod {
82 86
 		logrus.Warn("Your kernel does not support cgroup cfs period")
83 87
 	}
84 88
 
85
-	info.CPUCfsQuota = cgroupEnabled(mountPoint, "cpu.cfs_quota_us")
86
-	if !quiet && !info.CPUCfsQuota {
89
+	cpuCfsQuota := cgroupEnabled(mountPoint, "cpu.cfs_quota_us")
90
+	if !quiet && !cpuCfsQuota {
87 91
 		logrus.Warn("Your kernel does not support cgroup cfs quotas")
88 92
 	}
89
-	return info
93
+	return cgroupCPUInfo{
94
+		CPUShares:    cpuShares,
95
+		CPUCfsPeriod: cpuCfsPeriod,
96
+		CPUCfsQuota:  cpuCfsQuota,
97
+	}
90 98
 }
91 99
 
92
-func checkCgroupBlkioInfo(quiet bool) *cgroupBlkioInfo {
93
-	info := &cgroupBlkioInfo{}
100
+// checkCgroupBlkioInfo reads the blkio information from the blkio cgroup mount point.
101
+func checkCgroupBlkioInfo(quiet bool) cgroupBlkioInfo {
94 102
 	mountPoint, err := cgroups.FindCgroupMountpoint("blkio")
95 103
 	if err != nil {
96 104
 		if !quiet {
97 105
 			logrus.Warn(err)
98 106
 		}
99
-		return info
107
+		return cgroupBlkioInfo{}
100 108
 	}
101 109
 
102
-	info.BlkioWeight = cgroupEnabled(mountPoint, "blkio.weight")
103
-	if !quiet && !info.BlkioWeight {
110
+	w := cgroupEnabled(mountPoint, "blkio.weight")
111
+	if !quiet && !w {
104 112
 		logrus.Warn("Your kernel does not support cgroup blkio weight")
105 113
 	}
106
-	return info
114
+	return cgroupBlkioInfo{BlkioWeight: w}
107 115
 }
108 116
 
109
-func checkCgroupCpusetInfo(quiet bool) *cgroupCpusetInfo {
110
-	info := &cgroupCpusetInfo{}
117
+// checkCgroupCpusetInfo reads the cpuset information from the cpuset cgroup mount point.
118
+func checkCgroupCpusetInfo(quiet bool) cgroupCpusetInfo {
111 119
 	_, err := cgroups.FindCgroupMountpoint("cpuset")
112 120
 	if err != nil {
113 121
 		if !quiet {
114 122
 			logrus.Warn(err)
115 123
 		}
116
-		return info
124
+		return cgroupCpusetInfo{}
117 125
 	}
118 126
 
119
-	info.Cpuset = true
120
-	return info
127
+	return cgroupCpusetInfo{Cpuset: true}
121 128
 }
122 129
 
123 130
 func cgroupEnabled(mountPoint, name string) bool {