Skip to content
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
9 changes: 9 additions & 0 deletions pkg/option/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ type Options struct {
// custom pcidb.WithOption settings, instead of letting ghw load the PCI
// database automatically.
PCIDB *pcidb.PCIDB

// Filter USB devices by uevent file path in sysfs
USBUeventPath string
}

func (o *Options) Warn(msg string, args ...interface{}) {
Expand Down Expand Up @@ -156,6 +159,12 @@ func WithPCIDB(pcidb *pcidb.PCIDB) Option {
}
}

func WithUSBUeventPath(path string) Option {

Choose a reason for hiding this comment

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

I don't see how and where this is used...

Choose a reason for hiding this comment

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

Also it seems weird to add this as an option for all device classes

Copy link
Author

Choose a reason for hiding this comment

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

It is used here: https://github.com/christoph-zededa/eve/blob/usbmanager_use_ghw/pkg/pillar/cmd/usbmanager/scanusb.go#L97

Also it seems weird to add this as an option for all device classes

I thought the same, but then I saw https://github.com/zededa/ghw/blob/main/pkg/option/option.go#L153

return func(opts *Options) {
opts.USBUeventPath = path
}
}

// PathOverrides is a map, keyed by the string name of a mount path, of override paths
type PathOverrides map[string]string

Expand Down
27 changes: 14 additions & 13 deletions pkg/usb/usb.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ import (
)

type Device struct {
Driver string `json:"driver"`
Type string `json:"type"`
VendorID string `json:"vendor_id"`
ProductID string `json:"product_id"`
Product string `json:"product"`
RevisionID string `json:"revision_id"`
Interface string `json:"interface"`
Devnum string `json:"devnum"`
Parent bus.BusParent `json:"parent,omitempty"`
Class string `json:"class"`
Subclass string `json:"subclass"`
Protocol string `json:"protocol"`
Controller string `json:"controller,omitempty"`
Driver string `json:"driver"`
Type string `json:"type"`
VendorID string `json:"vendor_id"`
ProductID string `json:"product_id"`
Product string `json:"product"`
RevisionID string `json:"revision_id"`
Interface string `json:"interface"`
Devnum string `json:"devnum"`
Parent bus.BusParent `json:"parent,omitempty"`
Class string `json:"class"`
Subclass string `json:"subclass"`
Protocol string `json:"protocol"`
Controller string `json:"controller,omitempty"`
UEventFilePath string
usbAddress.Address
}

Expand Down
11 changes: 8 additions & 3 deletions pkg/usb/usb_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (i *Info) load(opts *option.Options) error {
return fmt.Errorf("error(s) happened during reading usb info: %+v", errs)
}

func fillUSBFromUevent(dir string, dev *Device) (err error) {
ueventFp, err := os.Open(filepath.Join(dir, "uevent"))
func fillUSBFromUevent(dev *Device) (err error) {
ueventFp, err := os.Open(dev.UEventFilePath)
if err != nil {
return
}
Expand Down Expand Up @@ -112,7 +112,12 @@ func usbs(opts *option.Options) ([]*Device, []error) {

dev := Device{}

err = fillUSBFromUevent(fullDir, &dev)
dev.UEventFilePath = filepath.Join(fullDir, "uevent")
if opts.USBUeventPath != "" && opts.USBUeventPath != dev.UEventFilePath {
continue
}

err = fillUSBFromUevent(&dev)
if err != nil {
errs = append(errs, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/usb/usb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ MODALIAS=usb:v046ApA087d0101dc00dsc00dp00ic03isc01ip02in00
}

var d Device
err = fillUSBFromUevent(usbDir, &d)
err = fillUSBFromUevent(&d)
if err != nil {
t.Fatalf("could not fill USB info from uevent file: %v", err)
}
Expand Down