Skip to content

Commit

Permalink
cpu: Take cgroupsv1 into account when reading misc.capacity
Browse files Browse the repository at this point in the history
We've been only considering cgroupsv2 when trying to read misc.capacity.
However, there are still a bunch of systems out there relying on
cgroupsv1.

Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
  • Loading branch information
fidencio committed Jul 19, 2023
1 parent 5f181cc commit 8ed5a23
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions source/cpu/security_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,22 @@ func sevParameterEnabled(parameter string) bool {

func getCgroupMiscCapacity(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

Check warning on line 136 in source/cpu/security_amd64.go

View check run for this annotation

Codecov / codecov/patch

source/cpu/security_amd64.go#L127-L136

Added lines #L127 - L136 were not covered by tests
}
}

miscCgroups := hostpath.SysfsDir.Path("fs/cgroup/misc.capacity")
f, err := os.Open(miscCgroups)
if err != nil {
return totalResources
}
defer f.Close()

r := bufio.NewReader(f)
for {
Expand Down

0 comments on commit 8ed5a23

Please sign in to comment.