path_id: add bus to USB path

This commit is contained in:
Hannes Reinecke 2006-03-22 12:21:49 +01:00 committed by Kay Sievers
parent 63645a3dfc
commit 24c27caf82
3 changed files with 241 additions and 298 deletions

1
TODO
View File

@ -17,4 +17,3 @@ udev version:
(we rely on the kernel "uevent" triggers of kernel 2.6.15 and no longer
want to guess event properties from sysfs like udevstart is doing it)
o remove use of "device" link in path_id

View File

@ -29,8 +29,7 @@ KERNEL=="sd*[0-9]|dasd*[0-9]", IMPORT{parent}=="ID_*"
KERNEL=="sd*[0-9]|dasd*[0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}-part%n"
# by-path (shortest physical path)
KERNEL=="*[!0-9]|sr*", ENV{ID_TYPE}=="?*", IMPORT{program}="/sbin/path_id %p", SYMLINK+="disk/by-path/$env{ID_PATH}"
KERNEL=="st*", ENV{ID_TYPE}=="?*", IMPORT{program}="/sbin/path_id %p", SYMLINK+="tape/by-path/$env{ID_PATH}"
KERNEL=="*[!0-9]|sr*|st*", ENV{ID_TYPE}=="?*", IMPORT{program}="/sbin/path_id %p", SYMLINK+="disk/by-path/$env{ID_PATH}"
KERNEL=="sr*|st*", GOTO="persistent_storage_end"
KERNEL=="*[0-9]", IMPORT{parent}=="ID_*"
KERNEL=="*[0-9]", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n"

117
extras/path_id Normal file → Executable file
View File

@ -1,9 +1,9 @@
#!/bin/sh
# provide the shortest possible unique hardware path to a block device
# for the udev persistent disk device naming scheme
# provide the shortest possible unique hardware path to a device
# for the Linux Persistent Device Naming scheme
#
# Copyright (C) 2005 SUSE Linux Products GmbH
# Copyright (C) 2005-2006 SUSE Linux Products GmbH
# Author:
# Hannes Reinecke <hare@suse.de>
#
@ -12,53 +12,12 @@
# Free Software Foundation version 2 of the License.
#
# to be called from a udev rule to return the name for a symlink
# DEVPATH=/block/sda/sda3 path_id
# DEVPATH=<devpath>; path_id
# path_id <devpath>
# examples for all block devices on a system:
# for i in `find /sys/class/block`; do DEVPATH="`echo $i | sed -e 's@^/sys\|/dev@@g'`"; path_id; done
# SCSI cdrom
# /class/block/sr0 -> /devices/pci0002:30/0002:30:0c.0/host0/target0:0:0/0:0:1:0
# pci-0002:30:0c.0-scsi-0:0:1:0
#
# SCSI disk
# /class/block/sda -> /devices/pci0002:30/0002:30:0c.0/host0/target0:0:0/0:0:4:0
# pci-0002:30:0c.0-scsi-0:0:4:0
#
# SATA disk, 4 channels per controller
# /class/block/sda -> /devices/pci0001:00/0001:00:07.0/0001:05:0c.0/host0/target0:0:0/0:0:0:0
# pci-0001:05:0c.0-scsi-0:0:0:0
#
# IDE disk
# /class/block/hda -> /devices/pci0002:02/0002:02:0d.0/ide0/0.0
# pci-0002:02:0d.0-ide-0.0
#
# IDE cdrom on a Mac ASIC:
# /class/block/hdc -> /devices/pci0001:01/0001:01:17.0/0.80000000:mac-io/0.00020000:ata-3/ide1/1.0
# mac-io_ata-3_master
#
# IDE cdrom on a Mac ASIC, with ide-scsi:
# /class/block/sr0 -> /devices/pci0001:01/0001:01:17.0/0.80000000:mac-io/0.0001f000:ata-4/ide0/0.1/host2/target2:0:0/2:0:0:0
# mac-io_ata-4_slave
# USB CDrom drive without 'serial' number:
# reusing 'product' and 'manufacturer' string, if available
# /class/block/sr0 -> /devices/pci0001:00/0001:00:04.0/0001:02:0b.0/usb4/4-2/4-2:1.0/host4/4:0:0:0
# usb-storage-odd-Freecom-USIDERev930:0:0:0
# devices may have several interfaces on one PCI device, like IDE:
# pci-0001:00:04.0_ide1-master
# pci-0001:00:04.0_ide2-master
# pci-0001:00:04.0_ide2-slave
# they are marked as ports, it is expected that the driver shows
# ide1 even if there is nothing connected to either master or slave
# interface
#
# match order is important.
# first IDE to find ide-scsi devices, then SCSI
# first usb-storage, then firewire sbp2, then the rest
SYSFS=/sys
RESULT=1
TYPE=
@ -121,29 +80,28 @@ handle_pci () {
cd -P $1
DEV=${PWD}
pci_id=${DEV##*/}
host_dev_path=$DEV
while [ ! -z "$host_dev_path" ] ; do
case "$host_dev_path" in
*/pci[0-9]*)
host_dev_path=${host_dev_path%/*}
;;
*) break;;
*)
break
;;
esac
done
d="pci-$pci_id-$d"
D="$host_dev_path"
RESULT=0
}
handle_block_ide () {
: handle_block_ide $*
handle_ide () {
: handle_ide $*
local DEV=$1
local port idedev idecontroller
# IDE
: DEV $DEV
port=${DEV##*/}
idedev=${DEV%/*}
idecontroller=${idedev%/*}
@ -160,8 +118,8 @@ handle_block_ide () {
;;
*)
echo "Error: $idedev is neither master or slave" >&2
;;
esac
cd $idecontroller
offset="`get_port_offset ide ${port%.*}`"
cd "$OPWD"
@ -176,8 +134,8 @@ handle_block_ide () {
RESULT=0
}
handle_block_scsi () {
: handle_block_scsi $*
handle_scsi () {
: handle_scsi $*
local DEV=$1
local cil controller_port controller_dev
# SCSI device
@ -190,10 +148,8 @@ handle_block_scsi () {
for tid in ${target_id}* ; do
target_num=$(( $target_num + 1 ))
done
controller_port=${target_dev%/*}
controller_dev="${controller_port%/*}"
: controller_dev $controller_dev
: controller_port $controller_port
# a host controller may have more than one interface/port
@ -204,41 +160,35 @@ handle_block_scsi () {
cd "$OPWD"
controller_port=$(( $controller_port - $controller_offset))
scsi_id="scsi-${controller_port}:${cil}"
if [ "$d" ] ; then
d="${scsi_id}-$d"
else
d="$scsi_id"
fi
D="$controller_dev"
RESULT=0
}
handle_block_firewire () {
:handle_block_firewire $*
handle_firewire () {
:handle_firewire $*
local DEV=$1
if [ -f "$D/ieee1394_id" ] ; then
read ieee1394_id < $D/ieee1394_id
fi
if [ -z "$ieee1394_id" ] ; then
: no IEEE1394 ID
RESULT=1
return
fi
fw_host_dev=${DEV%/fw-host*}
# IEEE1394 devices are always endpoints
d="ieee1394-0x$ieee1394_id"
D="$fw_host_dev"
RESULT=0
}
handle_block_fc () {
: handle_block_fc $*
handle_fc () {
: handle_fc $*
local DEV=$1
local cil controller_port controller_dev
# SCSI-FC device
@ -260,22 +210,20 @@ handle_block_fc () {
tmp_lun2=$(printf "%04x" $(( ($fc_tgt_lun >> 16) & 0xFFFF)))
tmp_lun1="0000"
tmp_lun0="0000"
if (($fc_tgt_lun == 0)) ; then
lun="0x0000000000000000"
else
lun="0x${tmp_lun3}${tmp_lun2}${tmp_lun1}${tmp_lun0}"
fi
controller_dev="${fc_tgt_path%/host[0-9]*}"
# FC devices are always endpoints
d="fc-${wwpn}:${lun}"
D="$controller_dev"
RESULT=0
}
handle_block_sas () {
: handle_block_sas $*
handle_sas () {
: handle_sas $*
local DEV=$1
local cil adapter controller_dev
# SAS device
@ -307,13 +255,10 @@ handle_block_sas () {
return
fi
sas_rphy_address="$rphy_address:$rphy_id"
controller_dev="${sas_host_path%/host[0-9]*}"
# SAS devices are always endpoints
d="sas-${sas_phy_address}-${sas_rphy_address}"
D="$controller_dev"
RESULT=0
}
@ -331,7 +276,9 @@ handle_usb () {
usb_host_path=$host_dev_path
host_dev_path="${host_dev_path%/*}"
;;
*) break ;;
*)
break
;;
esac
done
: host_dev_path $host_dev_path
@ -341,18 +288,16 @@ handle_usb () {
usb_host_offset=$(get_port_offset usb $usb_host_num)
usb_host_port=$(($usb_host_num - $usb_host_offset))
cd "$OPWD"
if [ "$d" ] ; then
d="usb-$usb_host_port:$port_num-${d}"
else
d="usb-$usb_host_port:$port_num"
fi
D="$host_dev_path"
RESULT=0
}
handle_block () {
handle_device () {
full_sysfs_path="$SYSFS$DEVPATH"
if [ -L $full_sysfs_path/subsystem ]; then
# new sysfs block layout
@ -384,7 +329,7 @@ handle_block () {
while [ ! -z "$D" ] ; do
case "$D" in
*/ide[0-9]/[0-9].[0-9]*|*/ide[0-9][0-9]/[0-9][0-9].[0-9]*)
handle_block_ide "$D"
handle_ide "$D"
;;
*/css0/*)
if [ -r $full_sysfs_device_path/wwpn ]; then
@ -410,16 +355,16 @@ handle_block () {
D=
;;
*/rport-[0-9]*:[0-9]*-[0-9]*/*)
handle_block_fc "$D"
handle_fc "$D"
;;
*/phy-[0-9]*:[0-9]*/*)
handle_block_sas "$D"
handle_sas "$D"
;;
*/fw-host[0-9]*/*)
handle_block_firewire "$D"
handle_firewire "$D"
;;
*/host[0-9]*/[0-9]*:[0-9]*:[0-9]*:[0-9]*)
handle_block_scsi "$D"
handle_scsi "$D"
;;
*/usb[0-9]*/[0-9]*/*)
handle_usb "$D"
@ -437,7 +382,6 @@ handle_block () {
;;
esac
done
if [ "$TYPE" == "scsi_tape" ] ; then
devname=${full_sysfs_path##*/}
rewind="${devname%%st*}"
@ -464,19 +408,20 @@ handle_block () {
case "$TYPE" in
block)
handle_block
handle_device
echo "ID_PATH=$d"
;;
scsi_tape)
handle_block
handle_device
echo "ID_PATH=$d"
;;
input)
handle_usb $SYSFS$DEVPATH/device
handle_device
echo "ID_PATH=$d"
;;
*)
RESULT=1
;;
esac
exit $RESULT