1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-10-30 23:21:08 +03:00

persistent links: add scsi tape links and usb path support

This commit is contained in:
Hannes Reinecke 2006-03-21 16:10:18 +01:00 committed by Kay Sievers
parent 0eb9e4a87e
commit 10a9bff1c3
2 changed files with 168 additions and 157 deletions

View File

@ -16,12 +16,13 @@ KERNEL=="hd*[!0-9]", IMPORT{program}="/sbin/ata_id --export $tempnode"
KERNEL=="hd*[!0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/ata-$env{ID_MODEL}_$env{ID_SERIAL}" KERNEL=="hd*[!0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/ata-$env{ID_MODEL}_$env{ID_SERIAL}"
KERNEL=="hd*[0-9]", IMPORT{parent}=="ID_*", SYMLINK+="disk/by-id/ata-$env{ID_MODEL}_$env{ID_SERIAL}-part%n" KERNEL=="hd*[0-9]", IMPORT{parent}=="ID_*", SYMLINK+="disk/by-id/ata-$env{ID_MODEL}_$env{ID_SERIAL}-part%n"
KERNEL=="sd*[!0-9]|sr*", SYSFS{ieee1394_id}=="*", ENV{ID_SERIAL}="$sysfs{ieee1394_id}", ENV{ID_BUS}="ieee1394" KERNEL=="sd*[!0-9]|sr*|st*", SYSFS{ieee1394_id}=="*", ENV{ID_SERIAL}="$sysfs{ieee1394_id}", ENV{ID_BUS}="ieee1394"
KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}=="", IMPORT{program}="/sbin/usb_id -x" KERNEL=="sd*[!0-9]|sr*|st*", ENV{ID_SERIAL}=="", IMPORT{program}="/sbin/usb_id -x"
KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}=="", IMPORT{program}="/sbin/scsi_id -g -x -s %p -d $tempnode" KERNEL=="sd*[!0-9]|sr*|st*", ENV{ID_SERIAL}=="", IMPORT{program}="/sbin/scsi_id -g -x -s %p -d $tempnode"
KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}=="", IMPORT{program}="/sbin/scsi_id -g -x -a -s %p -d $tempnode" KERNEL=="sd*[!0-9]|sr*|st*", ENV{ID_SERIAL}=="", IMPORT{program}="/sbin/scsi_id -g -x -a -s %p -d $tempnode"
KERNEL=="dasd*[!0-9]", IMPORT{program}="/sbin/dasd_id --export $tempnode" KERNEL=="dasd*[!0-9]", IMPORT{program}="/sbin/dasd_id --export $tempnode"
KERNEL=="sd*[!0-9]|sr*|dasd*[!0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}" KERNEL=="sd*[!0-9]|sr*|dasd*[!0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}"
KERNEL=="st*", ENV{ID_SERIAL}=="?*", SYMLINK+="tape/by-id/$env{ID_BUS}-$env{ID_SERIAL}"
# for partitions import parent information # for partitions import parent information
KERNEL=="sd*[0-9]|dasd*[0-9]", IMPORT{parent}=="ID_*" KERNEL=="sd*[0-9]|dasd*[0-9]", IMPORT{parent}=="ID_*"
@ -29,7 +30,8 @@ KERNEL=="sd*[0-9]|dasd*[0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{I
# by-path (shortest physical path) # 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=="*[!0-9]|sr*", ENV{ID_TYPE}=="?*", IMPORT{program}="/sbin/path_id %p", SYMLINK+="disk/by-path/$env{ID_PATH}"
KERNEL=="sr*", GOTO="persistent_disk_end" KERNEL=="st*", ENV{ID_TYPE}=="?*", IMPORT{program}="/sbin/path_id %p", SYMLINK+="tape/by-path/$env{ID_PATH}"
KERNEL=="sr*|st*", GOTO="persistent_disk_end"
KERNEL=="*[0-9]", IMPORT{parent}=="ID_*" KERNEL=="*[0-9]", IMPORT{parent}=="ID_*"
KERNEL=="*[0-9]", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n" KERNEL=="*[0-9]", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n"

View File

@ -104,7 +104,7 @@ case "$DEVPATH" in
;; ;;
esac esac
get_port () { get_port_offset () {
local type offset port local type offset port
type=$1 type=$1
offset=$2 offset=$2
@ -113,9 +113,28 @@ get_port () {
port="${i#$type}" port="${i#$type}"
if [ "$port" -lt "$offset" ] ; then offset=$port ; fi if [ "$port" -lt "$offset" ] ; then offset=$port ; fi
done done
if [ "$port" != "0" ] ; then echo $offset
echo $(($2 - $offset)) }
fi
handle_pci () {
local DEV=$1
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;;
esac
done
d="pci-$pci_id-$d"
D="$host_dev_path"
RESULT=0
} }
handle_block_ide () { handle_block_ide () {
@ -124,42 +143,15 @@ handle_block_ide () {
local port idedev idecontroller local port idedev idecontroller
# IDE # IDE
: DEV $DEV : DEV $DEV
d=$DEV
case "$DEV" in port=${DEV##*/}
# remove ide-scsi part, leave only channel info idedev=${DEV%/*}
*/ide[0-9]*/host[0-9]*) idecontroller=${idedev%/*}
while [ ! -z "$d" ] ; do
case "$d" in
*/host[0-9]*)
d="${d%/*}"
continue
;;
*)
break
;;
esac
done
;;
esac
idedev=$d
while [ ! -z "$d" ] ; do
case "$d" in
*/ide[0-9]*)
port="${d##*/}"
d="${d%/*}"
continue
;;
*)
break
;;
esac
done
idecontroller=$d
# port info if the controller has more than one interface # port info if the controller has more than one interface
port="${port#ide}" port="${port#ide}"
: port $port d $d : port $port d $d
: idedev $idedev kernel_port $port : idedev $idedev kernel_port $port
case "${idedev##*.}" in case "${port#*.}" in
0) 0)
channel=0 channel=0
;; ;;
@ -169,85 +161,82 @@ handle_block_ide () {
*) *)
echo "Error: $idedev is neither master or slave" >&2 echo "Error: $idedev is neither master or slave" >&2
esac esac
case "$d" in
*:mac-io/*)
: mac-io: $d
d="`echo $d | sed -e 's@^.*:mac-io[^:]\+:\([^/]\+\).*@mac-io_\1@'`"
;;
/sys/devices)
# PCMCIA devices
ifname=${full_sysfs_path##*/}
set -- `sed -n "/$ifname/p" /var/lib/pcmcia/stab`
d="pcmcia-$1"
;;
*)
d="pci-${d##*/}"
# d="`echo $d | sed -e 's@^.*/\([^/]\{1,\}\)/.@pci-\1@'`"
;;
esac
cd $idecontroller cd $idecontroller
port="`get_port ide $port`" offset="`get_port_offset ide ${port%.*}`"
cd "$OPWD" cd "$OPWD"
: hardware_port $port : port offset $offset
if [ -z "$port" ] ; then port=$((${port%.*} - $offset))
d="${d}-ide-0:$channel" if [ "$d" ] ; then
d="ide-${port}:$channel-$d"
else else
d="${d}-ide-${port}:$channel" d="ide-${port}:$channel"
fi fi
D=$idecontroller
RESULT=0 RESULT=0
} }
handle_block_scsi () { handle_block_scsi () {
: handle_block_scsi $* : handle_block_scsi $*
local DEV=$1 local DEV=$1
local cil controller_port controller_dev local cil controller_port controller_dev
# SCSI device # SCSI device
cil="${DEV##*/}" cil="${DEV##*/}"
cil="${cil#*:}" cil="${cil#*:}"
controller_dev=$DEV target_dev=${DEV%/*}
while [ ! -z "$controller_dev" ] ; do target_id=${target_dev##*/target}
case "$controller_dev" in cd "$target_dev"
*/host[0-9]*) target_num=0
controller_port=$controller_dev for tid in ${target_id}* ; do
controller_dev="${controller_dev%/*}" target_num=$(( $target_num + 1 ))
;;
*) break ;;
esac
done done
controller_port=${target_dev%/*}
controller_dev="${controller_port%/*}"
: controller_dev $controller_dev : controller_dev $controller_dev
: controller_port $controller_port : controller_port $controller_port
# a host controller may have more than one interface/port # a host controller may have more than one interface/port
controller_port="${controller_port##*/}" controller_port="${controller_port##*/host}"
controller_port="${controller_port##host}"
# #
case "$controller_dev" in
# grand central, old powermacs
*:gc/*)
adapter="`echo $controller_dev | sed -e 's@/[^/]\{1,\}$@@;s@^.*/@@;s@^.*:@@'`"
bus="gc"
;;
# PARISC devices
*parisc*)
adapter="${controller_dev##*/}"
bus=parisc;
;;
*)
adapter="${controller_dev##*/}"
bus="pci"
;;
esac
cd "$controller_dev" cd "$controller_dev"
controller_port="`get_port host $controller_port`" controller_offset=$(get_port_offset host $controller_port)
cd "$OPWD" cd "$OPWD"
d="$bus-$adapter" controller_port=$(( $controller_port - $controller_offset))
if [ -z "$controller_port" ] ; then scsi_id="scsi-${controller_port}:${cil}"
controller_port=0
if [ "$d" ] ; then
d="${scsi_id}-$d"
else
d="$scsi_id"
fi fi
d="${d}-scsi-${controller_port}:${cil}"
D="$controller_dev"
RESULT=0 RESULT=0
} }
handle_block_firewire () {
:handle_block_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_block_fc $* : handle_block_fc $*
local DEV=$1 local DEV=$1
@ -278,13 +267,10 @@ handle_block_fc () {
lun="0x${tmp_lun3}${tmp_lun2}${tmp_lun1}${tmp_lun0}" lun="0x${tmp_lun3}${tmp_lun2}${tmp_lun1}${tmp_lun0}"
fi fi
controller_dev="${fc_tgt_path%/host[0-9]*}" controller_dev="${fc_tgt_path%/host[0-9]*}"
adapter="${controller_dev##*/}"
bus="pci" # FC devices are always endpoints
d="$bus-$adapter" d="fc-${wwpn}:${lun}"
if [ -z "$controller_port" ] ; then D="$controller_dev"
controller_port=0
fi
d="${d}-fc-${wwpn}:${lun}"
RESULT=0 RESULT=0
} }
@ -323,57 +309,46 @@ handle_block_sas () {
sas_rphy_address="$rphy_address:$rphy_id" sas_rphy_address="$rphy_address:$rphy_id"
controller_dev="${sas_host_path%/host[0-9]*}" controller_dev="${sas_host_path%/host[0-9]*}"
adapter="${controller_dev##*/}"
bus="pci" # SAS devices are always endpoints
d="$bus-$adapter" d="sas-${sas_phy_address}-${sas_rphy_address}"
d="${d}-sas-${sas_phy_address}-${sas_rphy_address}" D="$controller_dev"
RESULT=0 RESULT=0
} }
handle_block_usb_storage () { handle_usb () {
: handle_block_usb_storage $* : handle_usb $*
local DEV=$1 local DEV=$1
cil="${DEV##*/}" cd -P $1
cil="${cil#*:}" DEV=${PWD}
controller_dev=$DEV port_id=${DEV##*/}
while [ ! -z "$controller_dev" ] ; do port_num=${port_id#*-}
case "$controller_dev" in host_dev_path=$DEV
*/host[0-9]*) while [ ! -z "$host_dev_path" ] ; do
controller_dev="${controller_dev%/*}" case "$host_dev_path" in
*/usb*)
usb_host_path=$host_dev_path
host_dev_path="${host_dev_path%/*}"
;; ;;
*) break ;; *) break ;;
esac esac
done done
: controller_dev $controller_dev : host_dev_path $host_dev_path
# usb_host_num=${usb_host_path##*/usb}
# usb-storage devs have a serial number, hopefully unique
serial= cd "$host_dev_path"
if [ -f $controller_dev/../serial ] ; then usb_host_offset=$(get_port_offset usb $usb_host_num)
serial="`sed -e 's@^[ -]\{1,\}\|[ -]\{1,\}$@@g;s@[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789-]@@g' < $controller_dev/../serial`" usb_host_port=$(($usb_host_num - $usb_host_offset))
: serial XXX_${serial}_XXX cd "$OPWD"
d="usb-$serial"
serial="`echo $serial | sed -e 's@[ 0]\{1,\}@@g'`" if [ "$d" ] ; then
d="usb-$usb_host_port:$port_num-${d}"
else
d="usb-$usb_host_port:$port_num"
fi fi
if [ -z "$serial" ] ; then
# no serial, broken device D="$host_dev_path"
# has eventually binary junk in vpd
identifier=
if [ -f $controller_dev/../product ] ; then
product="`sed -e 's@^[ -]\{1,\}\|[ -]\{1,\}$@@g;s@[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789-]@@g' < $controller_dev/../product`"
fi
if [ -f $controller_dev/../manufacturer ] ; then
manufacturer="`sed -e 's@^[ -]\{1,\}\|[ -]\{1,\}$@@g;s@[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789-]@@g' < $controller_dev/../manufacturer`"
fi
if [ -z "$product" -o -z "$manufacturer" ] ; then
read idvendor < $controller_dev/../idVendor
read idproduct < $controller_dev/../idProduct
identifier="0x${idvendor}-0x${idproduct}"
else
identifier="${manufacturer}-${product}"
fi
d="usb-${identifier}"
fi
d="$d:$cil"
RESULT=0 RESULT=0
} }
@ -406,13 +381,11 @@ handle_block () {
full_sysfs_device_path="`pwd -P`" full_sysfs_device_path="`pwd -P`"
cd "$OPWD" cd "$OPWD"
D=$full_sysfs_device_path D=$full_sysfs_device_path
while [ ! -z "$D" ] ; do
case "$D" in case "$D" in
*/ide[0-9]/[0-9].[0-9]*|*/ide[0-9][0-9]/[0-9][0-9].[0-9]*) */ide[0-9]/[0-9].[0-9]*|*/ide[0-9][0-9]/[0-9][0-9].[0-9]*)
handle_block_ide "$D" handle_block_ide "$D"
;; ;;
*/usb[0-9]*/[0-9]*/host[0-9]*/[0-9]*:[0-9]*:[0-9]*:[0-9]*)
handle_block_usb_storage "$D"
;;
*/css0/*) */css0/*)
if [ -r $full_sysfs_device_path/wwpn ]; then if [ -r $full_sysfs_device_path/wwpn ]; then
read wwpn < $full_sysfs_device_path/wwpn read wwpn < $full_sysfs_device_path/wwpn
@ -434,6 +407,7 @@ handle_block () {
d="$bus-$adapter" d="$bus-$adapter"
RESULT=0 RESULT=0
fi fi
D=
;; ;;
*/rport-[0-9]*:[0-9]*-[0-9]*/*) */rport-[0-9]*:[0-9]*-[0-9]*/*)
handle_block_fc "$D" handle_block_fc "$D"
@ -441,15 +415,20 @@ handle_block () {
*/phy-[0-9]*:[0-9]*/*) */phy-[0-9]*:[0-9]*/*)
handle_block_sas "$D" handle_block_sas "$D"
;; ;;
*/fw-host[0-9]*/*)
handle_block_firewire "$D"
;;
*/host[0-9]*/[0-9]*:[0-9]*:[0-9]*:[0-9]*) */host[0-9]*/[0-9]*:[0-9]*:[0-9]*:[0-9]*)
# check for ieee1394 sbp2 handle_block_scsi "$D"
if test -f $D/ieee1394_id ; then ;;
read ieee1394_id < $D/ieee1394_id */usb[0-9]*/[0-9]*/*)
d="`echo ieee1394-${ieee1394_id} | sed -e 's@:@-@g'`" handle_usb "$D"
RESULT=0 ;;
else */pci[0-9]*:[0-9]*)
handle_block_scsi "$D" handle_pci "$D"
fi ;;
*/devices)
D=
;; ;;
*) *)
: not handled : not handled
@ -457,14 +436,44 @@ handle_block () {
return return
;; ;;
esac esac
done
if [ "$TYPE" == "scsi_tape" ] ; then
devname=${full_sysfs_path##*/}
rewind="${devname%%st*}"
mode="${devname##*st}"
case "$mode" in
*l)
mode="l"
;;
*m)
mode="m"
;;
*a)
mode="a"
;;
*)
mode=""
;;
esac
if [ "$d" ]; then
d="$d-${rewind}st${mode}"
fi
fi
echo "ID_PATH=$d" echo "ID_PATH=$d"
} }
case "$TYPE" in case "$TYPE" in
block) block)
handle_block handle_block
;; ;;
*) scsi_tape)
handle_block
;;
input)
handle_usb $SYSFS$DEVPATH/device
;;
*)
RESULT=1 RESULT=1
;; ;;
esac esac