Skip to content

Commit

Permalink
infiniband: do not fail if board_id is not present (#556)
Browse files Browse the repository at this point in the history
Whilst a large majority do, not _all_ InfiniBand drivers expose a
board_id in sysfs.

Signed-off-by: Daniel Swarbrick <[email protected]>
  • Loading branch information
dswarbrick authored Sep 22, 2023
1 parent 647e50e commit b2168a3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions sysfs/class_infiniband.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,24 @@ func (fs FS) InfiniBandClass() (InfiniBandClass, error) {
}

// Parse one InfiniBand device.
// Refer to https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-infiniband
func (fs FS) parseInfiniBandDevice(name string) (*InfiniBandDevice, error) {
path := fs.sys.Path(infinibandClassPath, name)
device := InfiniBandDevice{Name: name}

for _, f := range [...]string{"board_id", "fw_ver", "hca_type"} {
// fw_ver is exposed by all InfiniBand drivers since kernel version 4.10.
value, err := util.SysReadFile(filepath.Join(path, "fw_ver"))
if err != nil {
return nil, fmt.Errorf("failed to read HCA firmware version: %w", err)
}
device.FirmwareVersion = value

// Not all InfiniBand drivers expose all of these.
for _, f := range [...]string{"board_id", "hca_type"} {
name := filepath.Join(path, f)
value, err := util.SysReadFile(name)
if err != nil {
// Not all InfiniBand drivers provide hca_type.
if os.IsNotExist(err) && (f == "hca_type") {
if os.IsNotExist(err) {
continue
}
return nil, fmt.Errorf("failed to read file %q: %w", name, err)
Expand All @@ -139,8 +147,6 @@ func (fs FS) parseInfiniBandDevice(name string) (*InfiniBandDevice, error) {
switch f {
case "board_id":
device.BoardID = value
case "fw_ver":
device.FirmwareVersion = value
case "hca_type":
device.HCAType = value
}
Expand Down

0 comments on commit b2168a3

Please sign in to comment.