-
Notifications
You must be signed in to change notification settings - Fork 364
Add support for /sys/class/mei/mei0
#792
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
Open
micgor32
wants to merge
9
commits into
prometheus:master
Choose a base branch
from
micgor32:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+248
−0
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fadce39
feat: add MEIClass for Management Engine Interface
micgor32 0c24e33
feat(testdata): update fixtures with sample mei data
micgor32 bac91d8
fix: remove perms check for mei
micgor32 cd6a546
feat: add test for MEIClass
micgor32 9ee1efc
chore: add license header and buildtag
micgor32 5422ec0
fix(mei): remove leftover DMI mentions
micgor32 9af651e
fix(testdata): remove trailing whitespace in dev_state
micgor32 4881da2
feat: add support for multiple MEI's
micgor32 3c27180
feat: update test for MEIClass
micgor32 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // Copyright The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //go:build linux | ||
|
|
||
| package sysfs | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/prometheus/procfs/internal/util" | ||
| ) | ||
|
|
||
| const meiClassPath = "class/mei" | ||
|
|
||
| type MEIDev struct { | ||
| Name *string | ||
| Dev *string | ||
| DevState *string | ||
| FWStatus *string | ||
| FWVersion *string | ||
| HBMVersion *string | ||
| HBMVersionDrv *string | ||
| Kind *string | ||
| Trc *string | ||
| TxQueueLimit *string | ||
| } | ||
|
|
||
| type MEIClass map[string]MEIDev | ||
|
|
||
| // MEIClass returns Management Engine Interface (MEI) information read from /sys/class/mei/. | ||
| func (fs FS) MEIClass() (*MEIClass, error) { | ||
| path := fs.sys.Path(meiClassPath) | ||
|
|
||
| subdirs, err := os.ReadDir(path) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to list MEI devices at %q: %w", path, err) | ||
| } | ||
|
|
||
| mei := make(MEIClass, len(subdirs)) | ||
| for _, d := range subdirs { | ||
| dev, err := fs.parseMEI(d.Name()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| mei[*dev.Name] = *dev | ||
| } | ||
|
|
||
| return &mei, nil | ||
| } | ||
|
|
||
| func (fs FS) parseMEI(meiDev string) (*MEIDev, error) { | ||
| path := fs.sys.Path(meiClassPath, meiDev) | ||
|
|
||
| files, err := os.ReadDir(path) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read directory %q: %w", path, err) | ||
| } | ||
|
|
||
| var mei MEIDev | ||
| mei.Name = &meiDev | ||
|
|
||
| for _, f := range files { | ||
| if !f.Type().IsRegular() { | ||
| continue | ||
| } | ||
|
|
||
| name := f.Name() | ||
| if name == "uevent" { | ||
| continue | ||
| } | ||
|
|
||
| filename := filepath.Join(path, name) | ||
| value, err := util.SysReadFile(filename) | ||
| if err != nil { | ||
| if os.IsPermission(err) { | ||
| continue | ||
| } | ||
|
|
||
| return nil, fmt.Errorf("failed to read file %q: %w", filename, err) | ||
| } | ||
|
|
||
| switch name { | ||
| case "dev": | ||
| mei.Dev = &value | ||
| case "dev_state": | ||
| mei.DevState = &value | ||
| case "fw_status": | ||
| mei.FWStatus = &value | ||
| case "fw_ver": | ||
| mei.FWVersion = &value | ||
| case "hbm_ver": | ||
| mei.HBMVersion = &value | ||
| case "hbm_ver_drv": | ||
| mei.HBMVersionDrv = &value | ||
| case "kind": | ||
| mei.Kind = &value | ||
| case "trc": | ||
| mei.Trc = &value | ||
| case "tx_queue_limit": | ||
| mei.TxQueueLimit = &value | ||
| } | ||
| } | ||
|
|
||
| return &mei, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //go:build linux | ||
|
|
||
| package sysfs | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| ) | ||
|
|
||
| func TestMEIClass(t *testing.T) { | ||
| fs, err := NewFS(sysTestFixtures) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| got, err := fs.MEIClass() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| name := "mei0" | ||
| dev := "244:0" | ||
| devState := "ENABLED" | ||
| fwStatus := "90000245\n00110500\n00000020\n00000000\n02F41F03\n40000000" | ||
| fwVer := "0:18.0.5.2098\n0:18.0.5.2098\n0:18.0.5.2098" | ||
| hbmVer := "2.2" | ||
| hbmVerDrv := "2.2" | ||
| kind := "mei" | ||
| trc := "00000889" | ||
| txQueueLimit := "50" | ||
|
|
||
| want := &MEIClass{ | ||
| "mei0": MEIDev{ | ||
| Name: &name, | ||
| Dev: &dev, | ||
| DevState: &devState, | ||
| FWStatus: &fwStatus, | ||
| FWVersion: &fwVer, | ||
| HBMVersion: &hbmVer, | ||
| HBMVersionDrv: &hbmVerDrv, | ||
| Kind: &kind, | ||
| Trc: &trc, | ||
| TxQueueLimit: &txQueueLimit, | ||
| }, | ||
| } | ||
|
|
||
| if diff := cmp.Diff(want, got); diff != "" { | ||
| t.Fatalf("unexpected MEI class (-want +got):\n%s", diff) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.