Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu: Take cgroupsv1 into account when reading misc.capacity #1265

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions source/cpu/security_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +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

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)
r := bufio.NewReader(miscCgroupPath)
for {
line, _, err := r.ReadLine()
if err != nil {
Expand All @@ -158,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
}