Update vendoring

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-06-14 17:55:18 +02:00
parent 743d290577
commit bcf3a70174
6 changed files with 95 additions and 27 deletions

2
go.mod
View File

@ -12,7 +12,7 @@ require (
github.com/sirupsen/logrus v1.9.0 github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.1 github.com/stretchr/testify v1.8.1
github.com/urfave/cli/v2 v2.3.0 github.com/urfave/cli/v2 v2.3.0
gitlab.com/nvidia/cloud-native/go-nvlib v0.0.0-20230522132528-649703f6b386 gitlab.com/nvidia/cloud-native/go-nvlib v0.0.0-20230613182322-7663cf900f0a
golang.org/x/mod v0.5.0 golang.org/x/mod v0.5.0
golang.org/x/sys v0.7.0 golang.org/x/sys v0.7.0
) )

4
go.sum
View File

@ -77,8 +77,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
gitlab.com/nvidia/cloud-native/go-nvlib v0.0.0-20230522132528-649703f6b386 h1:byHxP+mlgNQ4GX31owfgCIq5fJCsdJMchiJHGuM2rxw= gitlab.com/nvidia/cloud-native/go-nvlib v0.0.0-20230613182322-7663cf900f0a h1:lceJVurLqiWFdxK6KMDw+SIwrAsFW/af44XrNlbGw78=
gitlab.com/nvidia/cloud-native/go-nvlib v0.0.0-20230522132528-649703f6b386/go.mod h1:KYZksBgh18o+uzgnpDazzG4LVYtnfB96VXHMXypEtik= gitlab.com/nvidia/cloud-native/go-nvlib v0.0.0-20230613182322-7663cf900f0a/go.mod h1:KYZksBgh18o+uzgnpDazzG4LVYtnfB96VXHMXypEtik=
golang.org/x/mod v0.5.0 h1:UG21uOlmZabA4fW5i7ZX6bjw1xELEGg/ZLgZq9auk/Q= golang.org/x/mod v0.5.0 h1:UG21uOlmZabA4fW5i7ZX6bjw1xELEGg/ZLgZq9auk/Q=
golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -44,7 +44,7 @@ func NewMockNvpci() (mock *MockNvpci, rerr error) {
}() }()
mock = &MockNvpci{ mock = &MockNvpci{
NewFrom(rootDir).(*nvpci), New(WithPCIDevicesRoot(rootDir)).(*nvpci),
} }
return mock, nil return mock, nil

View File

@ -65,6 +65,7 @@ type ResourceInterface interface {
type nvpci struct { type nvpci struct {
pciDevicesRoot string pciDevicesRoot string
pcidbPath string
} }
var _ Interface = (*nvpci)(nil) var _ Interface = (*nvpci)(nil)
@ -124,14 +125,33 @@ func (d *NvidiaPCIDevice) Reset() error {
} }
// New interface that allows us to get a list of all NVIDIA PCI devices // New interface that allows us to get a list of all NVIDIA PCI devices
func New() Interface { func New(opts ...Option) Interface {
return NewFrom(PCIDevicesRoot) n := &nvpci{}
for _, opt := range opts {
opt(n)
}
if n.pciDevicesRoot == "" {
n.pciDevicesRoot = PCIDevicesRoot
}
return n
} }
// NewFrom interface allows us to get a list of all NVIDIA PCI devices at a specific root directory // Option defines a function for passing options to the New() call
func NewFrom(root string) Interface { type Option func(*nvpci)
return &nvpci{
pciDevicesRoot: root, // WithPCIDevicesRoot provides an Option to set the root path
// for PCI devices on the system.
func WithPCIDevicesRoot(root string) Option {
return func(n *nvpci) {
n.pciDevicesRoot = root
}
}
// WithPCIDatabasePath provides an Option to set the path
// to the pciids database file.
func WithPCIDatabasePath(path string) Option {
return func(n *nvpci) {
n.pcidbPath = path
} }
} }
@ -282,6 +302,15 @@ func (p *nvpci) GetGPUByPciBusID(address string) (*NvidiaPCIDevice, error) {
pciDB := pciids.NewDB() pciDB := pciids.NewDB()
deviceName, err := pciDB.GetDeviceName(uint16(vendorID), uint16(deviceID))
if err != nil {
return nil, fmt.Errorf("unable to get device name: %v", err)
}
className, err := pciDB.GetClassName(uint32(classID))
if err != nil {
return nil, fmt.Errorf("unable to get class name for device: %v", err)
}
nvdevice := &NvidiaPCIDevice{ nvdevice := &NvidiaPCIDevice{
Path: devicePath, Path: devicePath,
Address: address, Address: address,
@ -294,8 +323,8 @@ func (p *nvpci) GetGPUByPciBusID(address string) (*NvidiaPCIDevice, error) {
Config: config, Config: config,
Resources: resources, Resources: resources,
IsVF: isVF, IsVF: isVF,
DeviceName: pciDB.GetDeviceName(uint16(vendorID), uint16(deviceID)), DeviceName: deviceName,
ClassName: pciDB.GetClassName(uint32(classID)), ClassName: className,
} }
return nvdevice, nil return nvdevice, nil

View File

@ -172,24 +172,48 @@ type parser struct {
} }
} }
// Various locations of pci.ids for different distributions. These may be more
// up to date then the embedded pci.ids db
var defaultPCIdbPaths = []string{
"/usr/share/misc/pci.ids", // Ubuntu
"/usr/local/share/pci.ids", // RHEL like with manual update
"/usr/share/hwdata/pci.ids", // RHEL like
"/usr/share/pci.ids", // SUSE
}
// This is a fallback if all of the locations fail // This is a fallback if all of the locations fail
//go:embed default_pci.ids //go:embed default_pci.ids
var defaultPCIdb []byte var defaultPCIdb []byte
// NewDB Parse the PCI DB in its default locations or use the default // NewDB Parse the PCI DB in its default locations or use the default
// builtin pci.ids db. // builtin pci.ids db.
func NewDB() Interface { func NewDB(opts ...Option) Interface {
// Various locations of pci.ids for differente distributions these may be more db := &pcidb{}
// up to date then the embedded pci.ids db for _, opt := range opts {
pcidbs := []string{ opt(db)
"/usr/share/misc/pci.ids", // Ubuntu
"/usr/local/share/pci.ids", // RHEL like with manual update
"/usr/share/hwdata/pci.ids", // RHEL like
"/usr/share/pci.ids", // SUSE
} }
pcidbs := defaultPCIdbPaths
if db.path != "" {
pcidbs = append([]string{db.path}, defaultPCIdbPaths...)
}
return newParser(pcidbs).parse() return newParser(pcidbs).parse()
} }
// Option defines a function for passing options to the NewDB() call
type Option func(*pcidb)
// WithFilePath provides an Option to set the file path
// for the pciids database used by pciids interface.
// The file path provided takes precedence over all other
// paths.
func WithFilePath(path string) Option {
return func(db *pcidb) {
db.path = path
}
}
// newParser will attempt to read the db pci.ids from well known places or fall // newParser will attempt to read the db pci.ids from well known places or fall
// back to an internal db // back to an internal db
func newParser(pcidbs []string) *parser { func newParser(pcidbs []string) *parser {
@ -229,24 +253,39 @@ var _ Interface = (*pcidb)(nil)
// Interface returns textual description of specific attributes of PCI devices // Interface returns textual description of specific attributes of PCI devices
type Interface interface { type Interface interface {
GetDeviceName(uint16, uint16) string GetDeviceName(uint16, uint16) (string, error)
GetClassName(uint32) string GetClassName(uint32) (string, error)
} }
// GetDeviceName return the textual description of the PCI device // GetDeviceName return the textual description of the PCI device
func (d *pcidb) GetDeviceName(vendorID uint16, deviceID uint16) string { func (d *pcidb) GetDeviceName(vendorID uint16, deviceID uint16) (string, error) {
return d.vendors[vendorID].devices[deviceID].name vendor, ok := d.vendors[vendorID]
if !ok {
return "", fmt.Errorf("failed to find vendor with id '%x'", vendorID)
}
device, ok := vendor.devices[deviceID]
if !ok {
return "", fmt.Errorf("failed to find device with id '%x'", deviceID)
}
return device.name, nil
} }
// GetClassName resturn the textual description of the PCI device class // GetClassName resturn the textual description of the PCI device class
func (d *pcidb) GetClassName(classID uint32) string { func (d *pcidb) GetClassName(classID uint32) (string, error) {
return d.classes[classID].name class, ok := d.classes[classID]
if !ok {
return "", fmt.Errorf("failed to find class with id '%x'", classID)
}
return class.name, nil
} }
// pcidb The complete set of PCI vendors and PCI classes // pcidb The complete set of PCI vendors and PCI classes
type pcidb struct { type pcidb struct {
vendors map[uint16]vendor vendors map[uint16]vendor
classes map[uint32]class classes map[uint32]class
path string
} }
// vendor PCI vendors/devices/subVendors/SubDevices // vendor PCI vendors/devices/subVendors/SubDevices

2
vendor/modules.txt vendored
View File

@ -62,7 +62,7 @@ github.com/syndtr/gocapability/capability
github.com/urfave/cli/v2 github.com/urfave/cli/v2
# github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb # github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb
## explicit ## explicit
# gitlab.com/nvidia/cloud-native/go-nvlib v0.0.0-20230522132528-649703f6b386 # gitlab.com/nvidia/cloud-native/go-nvlib v0.0.0-20230613182322-7663cf900f0a
## explicit; go 1.20 ## explicit; go 1.20
gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/device gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/device
gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info