Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sysfs/class_infiniband.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ type InfiniBandHwCounters struct {
// /sys/class/infiniband/<Name>/ports/<Port>
// for a single port of one InfiniBand device.
type InfiniBandPort struct {
LinkLayer string
Name string
Port uint
Comment on lines +110 to 112
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LinkLayer string
Name string
Port uint
Name string
Port uint
LinkLayer string // String representation from /sys/class/infiniband/<Name>/ports/<Port>/link_layer

State string // String representation from /sys/class/infiniband/<Name>/ports/<Port>/state
Expand Down Expand Up @@ -248,6 +249,13 @@ func (fs FS) parseInfiniBandPort(name string, port string) (*InfiniBandPort, err
ibp := InfiniBandPort{Name: name, Port: uint(portNumber)}

portPath := fs.sys.Path(infinibandClassPath, name, "ports", port)

linkLayer, err := os.ReadFile(filepath.Join(portPath, "link_layer"))
if err != nil {
return nil, err
}
ibp.LinkLayer = strings.TrimSpace(string(linkLayer))

content, err := os.ReadFile(filepath.Join(portPath, "state"))
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions sysfs/class_infiniband_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func TestInfiniBandClass(t *testing.T) {
HCAType: "",
Ports: map[uint]InfiniBandPort{
1: {
LinkLayer: "InfiniBand",
Name: "hfi1_0",
Port: 1,
State: "ACTIVE",
Expand Down Expand Up @@ -210,6 +211,7 @@ func TestInfiniBandClass(t *testing.T) {
HCAType: "MT4099",
Ports: map[uint]InfiniBandPort{
1: {
LinkLayer: "InfiniBand",
Name: "mlx4_0",
Port: 1,
State: "ACTIVE",
Expand Down Expand Up @@ -238,6 +240,7 @@ func TestInfiniBandClass(t *testing.T) {
},
},
2: {
LinkLayer: "InfiniBand",
Name: "mlx4_0",
Port: 2,
State: "ACTIVE",
Expand Down Expand Up @@ -274,6 +277,7 @@ func TestInfiniBandClass(t *testing.T) {
HCAType: "MT4118",
Ports: map[uint]InfiniBandPort{
1: {
LinkLayer: "InfiniBand",
Name: "mlx5_0",
Port: 1,
State: "ACTIVE",
Expand Down
21 changes: 21 additions & 0 deletions testdata/fixtures.ttar
Original file line number Diff line number Diff line change
Expand Up @@ -5748,6 +5748,11 @@ Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/class/infiniband/hfi1_0/ports/1/link_layer
Lines: 1
InfiniBand
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/class/infiniband/hfi1_0/ports/1/phys_state
Lines: 1
5: LinkUp
Expand Down Expand Up @@ -5875,6 +5880,11 @@ Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/class/infiniband/mlx4_0/ports/1/link_layer
Lines: 1
InfiniBand
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/class/infiniband/mlx4_0/ports/1/phys_state
Lines: 1
5: LinkUp
Expand Down Expand Up @@ -5979,6 +5989,12 @@ Mode: 644
Path: fixtures/sys/class/infiniband/mlx4_0/ports/2/counters/symbol_error
Lines: 1
0
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/class/infiniband/mlx4_0/ports/2/link_layer
Lines: 2
InfiniBand

Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/class/infiniband/mlx4_0/ports/2/phys_state
Expand Down Expand Up @@ -6256,6 +6272,11 @@ Lines: 1
742114
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/class/infiniband/mlx5_0/ports/1/link_layer
Lines: 1
InfiniBand
Mode: 644
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Path: fixtures/sys/class/infiniband/mlx5_0/ports/1/phys_state
Lines: 1
4: ACTIVE
Expand Down