Skip to content

Commit

Permalink
Merge pull request #84 from swatisehgal/update-reloctablesysfs
Browse files Browse the repository at this point in the history
Add RelocatableSysFS IsBlockDeviceHidden
  • Loading branch information
openshift-merge-bot[bot] authored Mar 13, 2024
2 parents 7bdfd70 + 547939e commit 561f81d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/machineinformer/relocatablesysfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const (
nodeDirPattern = "node*[0-9]"

nodeDistance = "distance"
hidden = "hidden"

//HugePagesNrFile name of nr_hugepages file in sysfs
HugePagesNrFile = "nr_hugepages"
Expand Down Expand Up @@ -93,6 +94,27 @@ func (fs RelocatableSysFs) GetDistances(nodePath string) (string, error) {
return strings.TrimSpace(string(nodeDistances)), err
}

// See: https://github.com/google/cadvisor/blob/v0.48.1/utils/sysfs/sysfs.go#L218-L236
func (fs RelocatableSysFs) IsBlockDeviceHidden(name string) (bool, error) {
// See: https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-block
// https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git
// - c8487d854ba5 ("lsblk: Ignore hidden devices")
path := filepath.Join(fs.root, blockDir, name, hidden)
hidden, err := os.ReadFile(path)
if err != nil && os.IsNotExist(err) {
// older OS may not have /hidden sysfs entry, so for sure
// it is not a hidden device...
return false, nil
}
if err != nil {
return false, fmt.Errorf("failed to read %s: %w", path, err)
}
if string(hidden) == "1" {
return true, nil
}
return false, nil
}

func (fs RelocatableSysFs) GetNodesPaths() ([]string, error) {
pathPattern := filepath.Join(fs.root, nodeDir, nodeDirPattern)
return filepath.Glob(pathPattern)
Expand Down

0 comments on commit 561f81d

Please sign in to comment.