Skip to content

Commit b2bde72

Browse files
sysfs: add link_layer property to InfiniBandPort (#700)
* sysfs: add link_layer property to InfiniBandPort Signed-off-by: Thomas Barrett <[email protected]> * Update sysfs/class_infiniband.go Co-authored-by: Ben Kochie <[email protected]> Signed-off-by: Thomas Barrett <[email protected]> --------- Signed-off-by: Thomas Barrett <[email protected]> Signed-off-by: Thomas Barrett <[email protected]> Co-authored-by: Ben Kochie <[email protected]>
1 parent 9479c29 commit b2bde72

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

sysfs/class_infiniband.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ type InfiniBandHwCounters struct {
110110
type InfiniBandPort struct {
111111
Name string
112112
Port uint
113+
LinkLayer string // String representation from /sys/class/infiniband/<Name>/ports/<Port>/link_layer
113114
State string // String representation from /sys/class/infiniband/<Name>/ports/<Port>/state
114115
StateID uint // ID from /sys/class/infiniband/<Name>/ports/<Port>/state
115116
PhysState string // String representation from /sys/class/infiniband/<Name>/ports/<Port>/phys_state
@@ -252,6 +253,13 @@ func (fs FS) parseInfiniBandPort(name string, port string) (*InfiniBandPort, err
252253
ibp := InfiniBandPort{Name: name, Port: uint(portNumber)}
253254

254255
portPath := fs.sys.Path(infinibandClassPath, name, "ports", port)
256+
257+
linkLayer, err := os.ReadFile(filepath.Join(portPath, "link_layer"))
258+
if err != nil {
259+
return nil, err
260+
}
261+
ibp.LinkLayer = strings.TrimSpace(string(linkLayer))
262+
255263
content, err := os.ReadFile(filepath.Join(portPath, "state"))
256264
if err != nil {
257265
return nil, err

sysfs/class_infiniband_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ func TestInfiniBandClass(t *testing.T) {
174174
HCAType: "",
175175
Ports: map[uint]InfiniBandPort{
176176
1: {
177+
LinkLayer: "InfiniBand",
177178
Name: "hfi1_0",
178179
Port: 1,
179180
State: "ACTIVE",
@@ -210,6 +211,7 @@ func TestInfiniBandClass(t *testing.T) {
210211
HCAType: "MT4099",
211212
Ports: map[uint]InfiniBandPort{
212213
1: {
214+
LinkLayer: "InfiniBand",
213215
Name: "mlx4_0",
214216
Port: 1,
215217
State: "ACTIVE",
@@ -238,6 +240,7 @@ func TestInfiniBandClass(t *testing.T) {
238240
},
239241
},
240242
2: {
243+
LinkLayer: "InfiniBand",
241244
Name: "mlx4_0",
242245
Port: 2,
243246
State: "ACTIVE",
@@ -275,6 +278,7 @@ func TestInfiniBandClass(t *testing.T) {
275278
NodeGUID: "0a7f:bc12:45ef:d23b",
276279
Ports: map[uint]InfiniBandPort{
277280
1: {
281+
LinkLayer: "InfiniBand",
278282
Name: "mlx5_0",
279283
Port: 1,
280284
State: "ACTIVE",

testdata/fixtures.ttar

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5787,6 +5787,11 @@ Lines: 1
57875787
0
57885788
Mode: 644
57895789
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5790+
Path: fixtures/sys/class/infiniband/hfi1_0/ports/1/link_layer
5791+
Lines: 1
5792+
InfiniBand
5793+
Mode: 644
5794+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57905795
Path: fixtures/sys/class/infiniband/hfi1_0/ports/1/phys_state
57915796
Lines: 1
57925797
5: LinkUp
@@ -5914,6 +5919,11 @@ Lines: 1
59145919
0
59155920
Mode: 644
59165921
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5922+
Path: fixtures/sys/class/infiniband/mlx4_0/ports/1/link_layer
5923+
Lines: 1
5924+
InfiniBand
5925+
Mode: 644
5926+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59175927
Path: fixtures/sys/class/infiniband/mlx4_0/ports/1/phys_state
59185928
Lines: 1
59195929
5: LinkUp
@@ -6018,6 +6028,12 @@ Mode: 644
60186028
Path: fixtures/sys/class/infiniband/mlx4_0/ports/2/counters/symbol_error
60196029
Lines: 1
60206030
0
6031+
Mode: 644
6032+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6033+
Path: fixtures/sys/class/infiniband/mlx4_0/ports/2/link_layer
6034+
Lines: 2
6035+
InfiniBand
6036+
60216037
Mode: 644
60226038
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
60236039
Path: fixtures/sys/class/infiniband/mlx4_0/ports/2/phys_state
@@ -6300,6 +6316,11 @@ Lines: 1
63006316
742114
63016317
Mode: 644
63026318
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6319+
Path: fixtures/sys/class/infiniband/mlx5_0/ports/1/link_layer
6320+
Lines: 1
6321+
InfiniBand
6322+
Mode: 644
6323+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63036324
Path: fixtures/sys/class/infiniband/mlx5_0/ports/1/phys_state
63046325
Lines: 1
63056326
4: ACTIVE

0 commit comments

Comments
 (0)