Skip to content
Open
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
46 changes: 46 additions & 0 deletions scripts/ofpathname
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ ofpathname_to_logical()
usb ) of2l_usb ;;
nvme ) of2l_nvme ;;
nvmf ) of2l_nvmf ;;
pci* ) of2l_pci ;;
esac

if [[ -z $LOGICAL_DEVNAME ]]; then
Expand All @@ -1227,6 +1228,51 @@ ofpathname_to_logical()
echo $LOGICAL_DEVNAME
}

#
# of2l_pci
# Conversion routine for OF path => logical name for pci devices
#

of2l_pci() {
# Example: DEVNAME=/pci@800000020000048/pci15b3,1003@0
# You may want to extract the PCI address and try to find a matching device

# Extract PCI address.
local pci_addr
pci_addr=$(echo "$DEVICE" | grep -o '[0-9a-fA-F]\{4\},[0-9a-fA-F]\{4\}@[0-9]\+')

if [[ -z "$pci_addr" ]]; then
# Could not extract PCI address
LOGICAL_DEVNAME=""
return
fi

# Try to find the corresponding device in /sys/bus/pci/devices
for sysdev in /sys/bus/pci/devices/*; do
if grep -qi "$pci_addr" "$sysdev/uevent" 2>/dev/null; then
# Try to find a block device under this PCI device
for blockdev in "$sysdev"/block/*; do
if [[ -b "/dev/$(basename "$blockdev")" ]]; then
LOGICAL_DEVNAME="/dev/$(basename "$blockdev")"
return
fi
done
# Or try to find a network device
for netdev in "$sysdev"/net/*; do
if [[ -d "$netdev" ]]; then
LOGICAL_DEVNAME="$(basename "$netdev")"
return
fi
done
fi
done

# If nothing found
LOGICAL_DEVNAME=""

echo $LOGICAL_DEVNAME
}

#
# of2l_ide
# Conversion routine for OF path => logical name for ide devices
Expand Down