1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

cpu: Add retrieveCgroupMiscCapacityValue() for legibility

Let's refactor part of the getCgroupMiscCapacity() out to its own
retrieveCgroupMiscCapacityValue(), for the legibility sake.

Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
Fabiano Fidêncio 2023-07-19 11:17:37 +02:00
parent 8ed5a2343f
commit 7532ac3192

View file

@ -122,26 +122,10 @@ func sevParameterEnabled(parameter string) bool {
return false
}
func getCgroupMiscCapacity(resource string) int64 {
func retrieveCgroupMiscCapacityValue(miscCgroupPath *os.File, resource string) int64 {
var totalResources int64 = -1
var err error = nil
var f *os.File = nil
miscCgroupsPaths := []string{"fs/cgroup/misc.capacity", "fs/cgroup/misc/misc.capacity"}
for _, miscCgroupsPath := range miscCgroupsPaths {
miscCgroups := hostpath.SysfsDir.Path(miscCgroupsPath)
f, err = os.Open(miscCgroups)
if err == nil {
defer f.Close()
break
}
}
if err != nil {
return totalResources
}
r := bufio.NewReader(f)
r := bufio.NewReader(miscCgroupPath)
for {
line, _, err := r.ReadLine()
if err != nil {
@ -167,3 +151,18 @@ func getCgroupMiscCapacity(resource string) int64 {
return totalResources
}
func getCgroupMiscCapacity(resource string) int64 {
miscCgroupsPaths := []string{"fs/cgroup/misc.capacity", "fs/cgroup/misc/misc.capacity"}
for _, miscCgroupsPath := range miscCgroupsPaths {
miscCgroups := hostpath.SysfsDir.Path(miscCgroupsPath)
f, err := os.Open(miscCgroups)
if err == nil {
defer f.Close()
return retrieveCgroupMiscCapacityValue(f, resource)
}
}
return -1
}