mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-15 17:50:49 +00:00
Merge pull request #254 from marquiz/devel/pmem
source/memory: detect NVDIMM DAX mode
This commit is contained in:
commit
d234ec12ac
2 changed files with 31 additions and 10 deletions
|
@ -278,6 +278,7 @@ See [configuration options](#configuration-options) for more information.
|
|||
| ------- | --------- | ------------------------------------------------------ |
|
||||
| numa | <br> | Multiple memory nodes i.e. NUMA architecture detected
|
||||
| nv | present | NVDIMM device(s) are present
|
||||
| nv | dax | NVDIMM region(s) configured in DAX mode are present
|
||||
|
||||
### Network Features
|
||||
|
||||
|
|
|
@ -44,11 +44,13 @@ func (s Source) Discover() (source.Features, error) {
|
|||
}
|
||||
|
||||
// Detect NVDIMM
|
||||
nv, err := hasNvdimm()
|
||||
nv, err := detectNvdimm()
|
||||
if err != nil {
|
||||
log.Printf("ERROR: failed to detect presence of NVDIMM: %s", err)
|
||||
} else if nv {
|
||||
features["nv.present"] = true
|
||||
log.Printf("ERROR: NVDIMM detection failed: %s", err)
|
||||
} else {
|
||||
for k, v := range nv {
|
||||
features["nv."+k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return features, nil
|
||||
|
@ -74,15 +76,33 @@ func isNuma() (bool, error) {
|
|||
return false, nil
|
||||
}
|
||||
|
||||
// Detect presence of NVDIMM devices
|
||||
func hasNvdimm() (bool, error) {
|
||||
// Detect NVDIMM devices and configuration
|
||||
func detectNvdimm() (map[string]bool, error) {
|
||||
features := make(map[string]bool)
|
||||
|
||||
// Check presence of physical devices
|
||||
devices, err := ioutil.ReadDir("/sys/class/nd/")
|
||||
if err == nil {
|
||||
if len(devices) > 0 {
|
||||
return true, nil
|
||||
features["present"] = true
|
||||
}
|
||||
} else if !os.IsNotExist(err) {
|
||||
return false, err
|
||||
} else if os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
return false, nil
|
||||
|
||||
// Check presence of DAX-configured regions
|
||||
devices, err = ioutil.ReadDir("/sys/bus/nd/devices/")
|
||||
if err == nil {
|
||||
for _, d := range devices {
|
||||
if strings.HasPrefix(d.Name(), "dax") {
|
||||
features["dax"] = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.Printf("WARNING: failed to detect NVDIMM configuration: %s", err)
|
||||
}
|
||||
|
||||
return features, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue