From b2168a3e6e6e1ae29130c442e76887cbb4b62d52 Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Fri, 22 Sep 2023 17:29:12 +0200 Subject: [PATCH] infiniband: do not fail if board_id is not present (#556) Whilst a large majority do, not _all_ InfiniBand drivers expose a board_id in sysfs. Signed-off-by: Daniel Swarbrick --- sysfs/class_infiniband.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sysfs/class_infiniband.go b/sysfs/class_infiniband.go index 652b544b..4c10fe72 100644 --- a/sysfs/class_infiniband.go +++ b/sysfs/class_infiniband.go @@ -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) @@ -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 }