Update go-nvlib dependency to v0.0.0-20230818092907-09424fdc8884

This change updates go-nvlib to include logic to skip NVIDIA PCI-E
devices where the name or class id is not known.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar
2023-08-18 11:31:37 +02:00
parent 7affdafcd3
commit 546f810159
6 changed files with 53 additions and 4 deletions

View File

@@ -0,0 +1,29 @@
/**
# Copyright (c) NVIDIA CORPORATION. All rights reserved.
#
# 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.
**/
package nvpci
import "log"
type logger interface {
Warningf(string, ...interface{})
}
type simpleLogger struct{}
func (l simpleLogger) Warningf(format string, v ...interface{}) {
log.Printf("WARNING: "+format, v)
}

View File

@@ -39,6 +39,10 @@ const (
PCI3dControllerClass uint32 = 0x030200
// PCINvSwitchClass represents the PCI class for NVSwitches
PCINvSwitchClass uint32 = 0x068000
// UnknownDeviceString is the device name to set for devices not found in the PCI database
UnknownDeviceString = "UNKNOWN_DEVICE"
// UnknownClassString is the class name to set for devices not found in the PCI database
UnknownClassString = "UNKNOWN_CLASS"
)
// Interface allows us to get a list of all NVIDIA PCI devices
@@ -64,6 +68,7 @@ type ResourceInterface interface {
}
type nvpci struct {
logger logger
pciDevicesRoot string
pcidbPath string
}
@@ -130,6 +135,9 @@ func New(opts ...Option) Interface {
for _, opt := range opts {
opt(n)
}
if n.logger == nil {
n.logger = &simpleLogger{}
}
if n.pciDevicesRoot == "" {
n.pciDevicesRoot = PCIDevicesRoot
}
@@ -139,6 +147,13 @@ func New(opts ...Option) Interface {
// Option defines a function for passing options to the New() call
type Option func(*nvpci)
// WithLogger provides an Option to set the logger for the library
func WithLogger(logger logger) Option {
return func(n *nvpci) {
n.logger = logger
}
}
// WithPCIDevicesRoot provides an Option to set the root path
// for PCI devices on the system.
func WithPCIDevicesRoot(root string) Option {
@@ -304,11 +319,13 @@ func (p *nvpci) GetGPUByPciBusID(address string) (*NvidiaPCIDevice, error) {
deviceName, err := pciDB.GetDeviceName(uint16(vendorID), uint16(deviceID))
if err != nil {
return nil, fmt.Errorf("unable to get device name: %v", err)
p.logger.Warningf("unable to get device name: %v\n", err)
deviceName = UnknownDeviceString
}
className, err := pciDB.GetClassName(uint32(classID))
if err != nil {
return nil, fmt.Errorf("unable to get class name for device: %v", err)
p.logger.Warningf("unable to get class name for device: %v\n", err)
className = UnknownClassString
}
nvdevice := &NvidiaPCIDevice{