Skip to content

Commit

Permalink
cpu: Add retrieveCgroupMiscCapacityValue() for legibility
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
fidencio committed Jul 19, 2023
1 parent 8ed5a23 commit 1f6e31c
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions source/cpu/security_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -167,3 +151,20 @@ func getCgroupMiscCapacity(resource string) int64 {

return totalResources
}

func getCgroupMiscCapacity(resource string) int64 {
var totalResources int64 = -1

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 totalResources
}

0 comments on commit 1f6e31c

Please sign in to comment.