Skip to content

Commit

Permalink
usbmanager: fix read usb address for network cards
Browse files Browse the repository at this point in the history
reading the usb address of the network device connected via usb
failed and set the UsbAddress of the ioBundle to an empty string;
at the same time it set the PCI address of the ioBundle to the
PCI address of the usb controller.
This made the usbmanager think it is a PCI passthrough rule for
this device and therefore usbmanager prevented all other usb devices
connected to that controller from passthrough.

Signed-off-by: Christoph Ostarek <[email protected]>
  • Loading branch information
christoph-zededa authored and eriknordmark committed Nov 20, 2023
1 parent bc8e13e commit 883407d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/pillar/types/ifnametopci.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -82,7 +83,19 @@ func ifNameToPciAndUsbAddr(log *base.LogObject, ifName string) (string, string,
return "", usbAddr, err
}

busnum, portnum, err := ExtractUSBBusnumPort(link)
ifPathLink, err := os.Readlink(ifPath)
if err != nil {
log.Warnf("readlink of %s failed: %+v", ifPath, err)
ifPathLink = ifPath
}
// convert from /sys/class/net/... to path including PCI address and USB address
// (e.g.: /devices/pci0000:00/0000:00:14.0/usb2/)
absIfPathLink, err := filepath.Abs(filepath.Join(ifPathLink, link))
if err != nil {
absIfPathLink = link
log.Warnf("getting absolute path of %s failed: %+v", link, err)
}
busnum, portnum, err := ExtractUSBBusnumPort(absIfPathLink)
if err == nil {
usbAddr = fmt.Sprintf("%d:%s", busnum, portnum)
}
Expand Down

0 comments on commit 883407d

Please sign in to comment.