1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-18 22:33:09 +00:00

source: perform all sysfs discovery under host sysfs

Be consistent and do all sysfs based feature discovery under the same
sysfs directory.
This commit is contained in:
Markus Lehtonen 2020-05-20 14:32:07 +03:00
parent 248859c64d
commit 67d7887949
8 changed files with 23 additions and 24 deletions

View file

@ -19,15 +19,10 @@ package cpu
import ( import (
"io/ioutil" "io/ioutil"
"log" "log"
"path"
"sigs.k8s.io/node-feature-discovery/source" "sigs.k8s.io/node-feature-discovery/source"
) )
const (
cpuDevicesBaseDir = "/sys/bus/cpu/devices"
)
// Configuration file options // Configuration file options
type cpuidConfig struct { type cpuidConfig struct {
AttributeBlacklist []string `json:"attributeBlacklist,omitempty"` AttributeBlacklist []string `json:"attributeBlacklist,omitempty"`
@ -137,14 +132,15 @@ func (s Source) Discover() (source.Features, error) {
// Check if any (online) CPUs have thread siblings // Check if any (online) CPUs have thread siblings
func haveThreadSiblings() (bool, error) { func haveThreadSiblings() (bool, error) {
files, err := ioutil.ReadDir(cpuDevicesBaseDir)
files, err := ioutil.ReadDir(source.SysfsDir.Path("bus/cpu/devices"))
if err != nil { if err != nil {
return false, err return false, err
} }
for _, file := range files { for _, file := range files {
// Try to read siblings from topology // Try to read siblings from topology
siblings, err := ioutil.ReadFile(path.Join(cpuDevicesBaseDir, file.Name(), "topology/thread_siblings_list")) siblings, err := ioutil.ReadFile(source.SysfsDir.Path("bus/cpu/devices", file.Name(), "topology/thread_siblings_list"))
if err != nil { if err != nil {
return false, err return false, err
} }

View file

@ -20,11 +20,11 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path"
"strconv" "strconv"
"strings" "strings"
"sigs.k8s.io/node-feature-discovery/pkg/cpuid" "sigs.k8s.io/node-feature-discovery/pkg/cpuid"
"sigs.k8s.io/node-feature-discovery/source"
) )
const ( const (
@ -38,13 +38,14 @@ func discoverSSTBF() (bool, error) {
nominalBaseFrequency := int(freqInfo.EAX) nominalBaseFrequency := int(freqInfo.EAX)
// Loop over all CPUs in the system // Loop over all CPUs in the system
files, err := ioutil.ReadDir(cpuDevicesBaseDir) files, err := ioutil.ReadDir(source.SysfsDir.Path("bus/cpu/devices"))
if err != nil { if err != nil {
return false, err return false, err
} }
for _, file := range files { for _, file := range files {
// Try to read effective base frequency of each cpu in the system // Try to read effective base frequency of each cpu in the system
filePath := path.Join(cpuDevicesBaseDir, file.Name(), "cpufreq/base_frequency") filePath := source.SysfsDir.Path("bus/cpu/devices", file.Name(), "cpufreq/base_frequency")
data, err := ioutil.ReadFile(filePath) data, err := ioutil.ReadFile(filePath)
if os.IsNotExist(err) { if os.IsNotExist(err) {
// Ignore missing file and continue to check other CPUs // Ignore missing file and continue to check other CPUs

View file

@ -20,6 +20,8 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"runtime" "runtime"
"sigs.k8s.io/node-feature-discovery/source"
) )
// Discover p-state related features such as turbo boost. // Discover p-state related features such as turbo boost.
@ -31,7 +33,7 @@ func detectPstate() (map[string]string, error) {
} }
// Only looking for turbo boost for now... // Only looking for turbo boost for now...
bytes, err := ioutil.ReadFile("/sys/devices/system/cpu/intel_pstate/no_turbo") bytes, err := ioutil.ReadFile(source.SysfsDir.Path("devices/system/cpu/intel_pstate/no_turbo"))
if err != nil { if err != nil {
return nil, fmt.Errorf("can't detect whether turbo boost is enabled: %s", err.Error()) return nil, fmt.Errorf("can't detect whether turbo boost is enabled: %s", err.Error())
} }

View file

@ -22,6 +22,8 @@ import (
"log" "log"
"path" "path"
"strings" "strings"
"sigs.k8s.io/node-feature-discovery/source"
) )
type PciDeviceInfo map[string]string type PciDeviceInfo map[string]string
@ -72,10 +74,10 @@ func readPciDevInfo(devPath string, deviceAttrSpec map[string]bool) (PciDeviceIn
// "class" attribute is considered mandatory. // "class" attribute is considered mandatory.
// DetectPci() will fail if the retrieval of a mandatory attribute fails. // DetectPci() will fail if the retrieval of a mandatory attribute fails.
func DetectPci(deviceAttrSpec map[string]bool) (map[string][]PciDeviceInfo, error) { func DetectPci(deviceAttrSpec map[string]bool) (map[string][]PciDeviceInfo, error) {
const basePath = "/sys/bus/pci/devices/" sysfsBasePath := source.SysfsDir.Path("bus/pci/devices")
devInfo := make(map[string][]PciDeviceInfo) devInfo := make(map[string][]PciDeviceInfo)
devices, err := ioutil.ReadDir(basePath) devices, err := ioutil.ReadDir(sysfsBasePath)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -84,7 +86,7 @@ func DetectPci(deviceAttrSpec map[string]bool) (map[string][]PciDeviceInfo, erro
// Iterate over devices // Iterate over devices
for _, device := range devices { for _, device := range devices {
info, err := readPciDevInfo(path.Join(basePath, device.Name()), deviceAttrSpec) info, err := readPciDevInfo(path.Join(sysfsBasePath, device.Name()), deviceAttrSpec)
if err != nil { if err != nil {
log.Print(err) log.Print(err)
continue continue

View file

@ -32,7 +32,7 @@ func (s Source) Discover() (source.Features, error) {
features := source.Features{} features := source.Features{}
// Check if any iommu devices are available // Check if any iommu devices are available
devices, err := ioutil.ReadDir("/sys/class/iommu/") devices, err := ioutil.ReadDir(source.SysfsDir.Path("class/iommu/"))
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to check for IOMMU support: %v", err) return nil, fmt.Errorf("Failed to check for IOMMU support: %v", err)
} }

View file

@ -60,7 +60,7 @@ func (s Source) Discover() (source.Features, error) {
func isNuma() (bool, error) { func isNuma() (bool, error) {
// Find out how many nodes are online // Find out how many nodes are online
// Multiple nodes is a sign of NUMA // Multiple nodes is a sign of NUMA
bytes, err := ioutil.ReadFile("/sys/devices/system/node/online") bytes, err := ioutil.ReadFile(source.SysfsDir.Path("devices/system/node/online"))
if err != nil { if err != nil {
return false, err return false, err
} }
@ -81,7 +81,7 @@ func detectNvdimm() (map[string]bool, error) {
features := make(map[string]bool) features := make(map[string]bool)
// Check presence of physical devices // Check presence of physical devices
devices, err := ioutil.ReadDir("/sys/class/nd/") devices, err := ioutil.ReadDir(source.SysfsDir.Path("class/nd"))
if err == nil { if err == nil {
if len(devices) > 0 { if len(devices) > 0 {
features["present"] = true features["present"] = true
@ -93,7 +93,7 @@ func detectNvdimm() (map[string]bool, error) {
} }
// Check presence of DAX-configured regions // Check presence of DAX-configured regions
devices, err = ioutil.ReadDir("/sys/bus/nd/devices/") devices, err = ioutil.ReadDir(source.SysfsDir.Path("bus/nd/devices"))
if err == nil { if err == nil {
for _, d := range devices { for _, d := range devices {
if strings.HasPrefix(d.Name(), "dax") { if strings.HasPrefix(d.Name(), "dax") {

View file

@ -44,8 +44,7 @@ func (s Source) Discover() (source.Features, error) {
// iterating through network interfaces to obtain their respective number of virtual functions // iterating through network interfaces to obtain their respective number of virtual functions
for _, netInterface := range netInterfaces { for _, netInterface := range netInterfaces {
if strings.Contains(netInterface.Flags.String(), "up") && !strings.Contains(netInterface.Flags.String(), "loopback") { if strings.Contains(netInterface.Flags.String(), "up") && !strings.Contains(netInterface.Flags.String(), "loopback") {
totalVfsPath := "/sys/class/net/" + netInterface.Name + "/device/sriov_totalvfs" totalBytes, err := ioutil.ReadFile(source.SysfsDir.Path("class/net", netInterface.Name, "device/sriov_totalvfs"))
totalBytes, err := ioutil.ReadFile(totalVfsPath)
if err != nil { if err != nil {
log.Printf("SR-IOV not supported for network interface: %s: %v", netInterface.Name, err) log.Printf("SR-IOV not supported for network interface: %s: %v", netInterface.Name, err)
continue continue
@ -60,8 +59,7 @@ func (s Source) Discover() (source.Features, error) {
log.Printf("SR-IOV capability is detected on the network interface: %s", netInterface.Name) log.Printf("SR-IOV capability is detected on the network interface: %s", netInterface.Name)
log.Printf("%d maximum supported number of virtual functions on network interface: %s", t, netInterface.Name) log.Printf("%d maximum supported number of virtual functions on network interface: %s", t, netInterface.Name)
features["sriov.capable"] = true features["sriov.capable"] = true
numVfsPath := "/sys/class/net/" + netInterface.Name + "/device/sriov_numvfs" numBytes, err := ioutil.ReadFile(source.SysfsDir.Path("class/net", netInterface.Name, "device/sriov_numvfs"))
numBytes, err := ioutil.ReadFile(numVfsPath)
if err != nil { if err != nil {
log.Printf("SR-IOV not configured for network interface: %s: %s", netInterface.Name, err) log.Printf("SR-IOV not configured for network interface: %s: %s", netInterface.Name, err)
continue continue

View file

@ -34,10 +34,10 @@ func (s Source) Discover() (source.Features, error) {
features := source.Features{} features := source.Features{}
// Check if there is any non-rotational block devices attached to the node // Check if there is any non-rotational block devices attached to the node
blockdevices, err := ioutil.ReadDir("/sys/block/") blockdevices, err := ioutil.ReadDir(source.SysfsDir.Path("block"))
if err == nil { if err == nil {
for _, bdev := range blockdevices { for _, bdev := range blockdevices {
fname := "/sys/block/" + bdev.Name() + "/queue/rotational" fname := source.SysfsDir.Path("block", bdev.Name(), "queue/rotational")
bytes, err := ioutil.ReadFile(fname) bytes, err := ioutil.ReadFile(fname)
if err != nil { if err != nil {
return nil, fmt.Errorf("can't read rotational status: %s", err.Error()) return nil, fmt.Errorf("can't read rotational status: %s", err.Error())