Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pci: add and use LookupDevice #240

Merged
merged 1 commit into from
Apr 12, 2021
Merged
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
10 changes: 10 additions & 0 deletions pkg/pci/pci.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ func New(opts ...*option.Option) (*Info, error) {
return info, nil
}

// lookupDevice gets a device from cached data
func (info *Info) lookupDevice(address string) *Device {
for _, dev := range info.Devices {
if dev.Address == address {
return dev
}
}
return nil
Comment on lines +176 to +181
Copy link
Owner

Choose a reason for hiding this comment

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

just move this into GetDevice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure thing!

}

// simple private struct used to encapsulate PCI information in a top-level
// "pci" YAML/JSON map/object key
type pciPrinter struct {
Expand Down
9 changes: 7 additions & 2 deletions pkg/pci/pci_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,14 @@ func findPCIProgrammingInterface(
}

// GetDevice returns a pointer to a Device struct that describes the PCI
// device at the requested address. If no such device could be found, returns
// nil
// device at the requested address. If no such device could be found, returns nil.
func (info *Info) GetDevice(address string) *Device {
// check cached data first
if dev := info.lookupDevice(address); dev != nil {
return dev
}

// no cached data, let's get the information from system.
fp := getDeviceModaliasPath(info.ctx, address)
if fp == "" {
info.ctx.Warn("error finding modalias info for device %q", address)
Expand Down