Skip to content

Commit

Permalink
Assuming that missing online file indicates CONFIG_HOTPLUG_CPU=n
Browse files Browse the repository at this point in the history
Signed-off-by: Maciej "Iwan" Iwanowski <maciej.iwanowski@critical.today>
  • Loading branch information
iwankgb committed Nov 29, 2020
1 parent ac63c56 commit e45f35d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
8 changes: 1 addition & 7 deletions utils/sysfs/sysfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -341,7 +340,7 @@ func (fs *realSysFs) IsCPUOnline(dir string) bool {
if err != nil {
pathErr, ok := err.(*os.PathError)
if ok {
if errors.Is(pathErr.Unwrap(), os.ErrNotExist) && isZeroCPU(dir) {
if errors.Is(pathErr.Unwrap(), os.ErrNotExist) {
return true
}
}
Expand All @@ -352,8 +351,3 @@ func (fs *realSysFs) IsCPUOnline(dir string) bool {
return len(trimmed) == 1 && trimmed[0] == 49
}

func isZeroCPU(dir string) bool {
regex := regexp.MustCompile("cpu([0-9]*)")
matches := regex.FindStringSubmatch(dir)
return len(matches) == 2 && matches[1] == "0"
}
2 changes: 1 addition & 1 deletion utils/sysfs/sysfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ func TestIsCPUOnlineNoFileAndCPU0MustBeOnline(t *testing.T) {
assert.True(t, online)

online = sysFs.IsCPUOnline("./testdata/missing_online/node0/cpu33")
assert.False(t, online)
assert.True(t, online)
}

0 comments on commit e45f35d

Please sign in to comment.