OBS User unknown 2009-01-27 01:24:59 +00:00 committed by Git OBS Bridge
parent 0063936dbf
commit 869168037c
3 changed files with 74 additions and 47 deletions

View File

@ -24,10 +24,6 @@ unsetcolor ()
findhosts_26 () findhosts_26 ()
{ {
hosts= hosts=
if ! ls /sys/class/scsi_host/host* >/dev/null 2>&1; then
echo "No SCSI host adapters found in sysfs"
exit 1;
fi
for hostdir in /sys/class/scsi_host/host*; do for hostdir in /sys/class/scsi_host/host*; do
hostno=${hostdir#/sys/class/scsi_host/host} hostno=${hostdir#/sys/class/scsi_host/host}
if [ -f $hostdir/isp_name ] ; then if [ -f $hostdir/isp_name ] ; then
@ -39,8 +35,11 @@ findhosts_26 ()
fi fi
hosts="$hosts $hostno" hosts="$hosts $hostno"
echo "Host adapter $hostno ($hostname) found." echo "Host adapter $hostno ($hostname) found."
done done
hosts=`echo $hosts | sed 's/ /\n/g' | sort -n` if [ -z "$hosts" ] ; then
echo "No SCSI host adapters found in sysfs"
exit 1;
fi
} }
# Return hosts. /proc/scsi/HOSTADAPTER/? must exist # Return hosts. /proc/scsi/HOSTADAPTER/? must exist
@ -65,6 +64,29 @@ findhosts ()
done done
} }
printtype ()
{
local type=$1
case "$type" in
0) echo "Direct-Access " ;;
1) echo "Sequential-Access" ;;
2) echo "Printer " ;;
3) echo "Processor " ;;
4) echo "WORM " ;;
5) echo "CD-ROM " ;;
6) echo "Scanner " ;;
7) echo "Optical Device " ;;
8) echo "Medium Changer " ;;
9) echo "Communications " ;;
10) echo "Unknown " ;;
11) echo "Unknown " ;;
12) echo "RAID " ;;
13) echo "Enclosure " ;;
14) echo "Direct-Access-RBC" ;;
*) echo "Unknown " ;;
esac
}
# Get /proc/scsi/scsi info for device $host:$channel:$id:$lun # Get /proc/scsi/scsi info for device $host:$channel:$id:$lun
# Optional parameter: Number of lines after first (default = 2), # Optional parameter: Number of lines after first (default = 2),
# result in SCSISTR, return code 1 means empty. # result in SCSISTR, return code 1 means empty.
@ -89,24 +111,7 @@ $SCSIDEV"
if [ "$LN" -gt 1 ] ; then if [ "$LN" -gt 1 ] ; then
ILVL=$(cat ${SCSIPATH}/device/scsi_level) ILVL=$(cat ${SCSIPATH}/device/scsi_level)
type=$(cat ${SCSIPATH}/device/type) type=$(cat ${SCSIPATH}/device/type)
case "$type" in ITYPE=$(printtype $type)
0) ITYPE="Direct-Access " ;;
1) ITYPE="Sequential-Access" ;;
2) ITYPE="Printer " ;;
3) ITYPE="Processor " ;;
4) ITYPE="WORM " ;;
5) ITYPE="CD-ROM " ;;
6) ITYPE="Scanner " ;;
7) ITYPE="Optical Device " ;;
8) ITYPE="Medium Changer " ;;
9) ITYPE="Communications " ;;
10) ITYPE="Unknown " ;;
11) ITYPE="Unknown " ;;
12) ITYPE="RAID " ;;
13) ITYPE="Enclosure " ;;
14) ITYPE="Direct-Access-RBC" ;;
*) ITYPE="Unknown " ;;
esac
SCSITMP=$(printf ' Type: %-16s ANSI SCSI revision: %02d' "$ITYPE" "$((ILVL - 1))") SCSITMP=$(printf ' Type: %-16s ANSI SCSI revision: %02d' "$ITYPE" "$((ILVL - 1))")
SCSISTR="$SCSISTR SCSISTR="$SCSISTR
$SCSITMP" $SCSITMP"
@ -192,20 +197,21 @@ testonline ()
IPQUAL=`echo "$INQ" | sed -n 's/ *PQual=\([0-9]*\) Device.*/\1/p'` IPQUAL=`echo "$INQ" | sed -n 's/ *PQual=\([0-9]*\) Device.*/\1/p'`
if [ "$IPQUAL" != 0 ] ; then if [ "$IPQUAL" != 0 ] ; then
echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nLU not available (PQual $IPQUAL)${norm}\n\n\n" echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nLU not available (PQual $IPQUAL)${norm}\n\n\n"
return 1 return 2
fi fi
TYPE=$(printtype $IPTYPE)
procscsiscsi procscsiscsi
TMPSTR=`echo "$SCSISTR" | grep 'Vendor:'` TMPSTR=`echo "$SCSISTR" | grep 'Vendor:'`
if [ "$TMPSTR" != "$STR" ]; then if [ "$TMPSTR" != "$STR" ]; then
echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nfrom:${TMPSTR#* } \nto: $STR ${norm}\n\n\n" echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nfrom:${SCSISTR#* } \nto: $STR ${norm}\n\n\n"
return 1 return 1
fi fi
TMPSTR=`echo "$SCSISTR" | sed -n 's/.*Type: *\(.*\) *ANSI.*/\1/p'` TMPSTR=`echo "$SCSISTR" | sed -n 's/.*Type: *\(.*\) *ANSI.*/\1/p'`
if [ $TMPSTR != $TYPE ] ; then if [ $TMPSTR != $TYPE ] ; then
echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nfrom:${TMPSTR} \nto: $TYPE ${norm}\n\n\n" echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nfrom:${TMPSTR} \nto: $TYPE ${norm}\n\n\n"
return 1 return 1
fi fi
return $RC return $RC
} }
@ -230,6 +236,7 @@ chanlist ()
local tmpchan local tmpchan
for dev in /sys/class/scsi_device/${host}:* ; do for dev in /sys/class/scsi_device/${host}:* ; do
[ -d $dev ] || continue;
hcil=${dev##*/} hcil=${dev##*/}
cil=${hcil#*:} cil=${hcil#*:}
chan=${cil%%:*} chan=${cil%%:*}
@ -254,6 +261,7 @@ idlist ()
local tmpid local tmpid
for dev in /sys/class/scsi_device/${host}:${channel}:* ; do for dev in /sys/class/scsi_device/${host}:${channel}:* ; do
[ -d $dev ] || continue;
hcil=${dev##*/} hcil=${dev##*/}
cil=${hcil#*:} cil=${hcil#*:}
il=${cil#*:} il=${cil#*:}
@ -261,6 +269,7 @@ idlist ()
for tmpid in $idsearch ; do for tmpid in $idsearch ; do
if test "$target" -eq $tmpid ; then if test "$target" -eq $tmpid ; then
target= target=
break
fi fi
done done
if test -n "$target" ; then if test -n "$target" ; then
@ -272,9 +281,9 @@ idlist ()
# Returns the list of existing LUNs # Returns the list of existing LUNs
getluns () getluns ()
{ {
if test ! -x /usr/bin/sg_luns; then return; fi if test ! -x /usr/bin/sg_luns; then return ""; fi
sgdevice sgdevice
if test -z "$SGDEV"; then return; fi if test -z "$SGDEV"; then return ""; fi
sg_luns -d /dev/$SGDEV | sed -n 's/.*lun=\(.*\)/\1/p' sg_luns -d /dev/$SGDEV | sed -n 's/.*lun=\(.*\)/\1/p'
} }
@ -291,31 +300,36 @@ dolunscan()
# Device exists: Test whether it's still online # Device exists: Test whether it's still online
# (testonline returns 1 if it's gone or has changed) # (testonline returns 1 if it's gone or has changed)
testonline testonline
if test $? = 1 -o ! -z "$forceremove"; then RC=$?
if test $RC != 0 -o ! -z "$forceremove"; then
echo -en "\r\e[A\e[A\e[A${red}REM: " echo -en "\r\e[A\e[A\e[A${red}REM: "
echo "$SCSISTR" | head -n1 echo "$SCSISTR" | head -n1
echo -e "${norm}\e[B\e[B" echo -e "${norm}\e[B\e[B"
if test -e /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device; then if test -e /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device; then
echo 1 > /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device/delete echo 1 > /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device/delete
# Try reading, should fail if device is gone if test $RC -eq 1 -o $lun -eq 0 ; then
echo "$channel $id $lun" > /sys/class/scsi_host/host${host}/scan # Try readding, should fail if device is gone
echo "$channel $id $lun" > /sys/class/scsi_host/host${host}/scan
fi
else else
echo "scsi remove-single-device $devnr" > /proc/scsi/scsi echo "scsi remove-single-device $devnr" > /proc/scsi/scsi
# Try reading, should fail if device is gone if test $RC -eq 1 -o $lun -eq 0 ; then
echo "scsi add-single-device $devnr" > /proc/scsi/scsi # Try readding, should fail if device is gone
echo "scsi add-single-device $devnr" > /proc/scsi/scsi
fi
fi fi
fi fi
if test $RC = 0 ; then if test $RC = 0 -o "$forcerescan" ; then
if test -e /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device; then if test -e /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device; then
echo 1 > /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device/rescan echo 1 > /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device/rescan
fi fi
fi fi
printf "\r\x1b[A\x1b[A\x1b[A${yellow}OLD: $norm" printf "\r\x1b[A\x1b[A\x1b[A${yellow}OLD: $norm"
testexist testexist
if test -z "$SCSISTR"; then if test -z "$SCSISTR"; then
printf "\r${red}DEL: $norm\r\n\n" printf "\r${red}DEL: $norm\r\n\n"
let rmvd+=1; let rmvd+=1;
return 1
fi fi
fi fi
if test -z "$SCSISTR"; then if test -z "$SCSISTR"; then
@ -368,16 +382,14 @@ doreportlun()
lunsearch=`getluns` lunsearch=`getluns`
lunremove= lunremove=
# Check existing luns # Check existing luns
for dev in /sys/class/scsi_device/$host\:$channel\:$id\:*; do for dev in /sys/class/scsi_device/${host}:${channel}:${id}:*; do
[ -d "$dev" ] || continue
lun=${dev##*:} lun=${dev##*:}
newsearch= newsearch=
oldsearch="$lunsearch" oldsearch="$lunsearch"
for tmplun in $lunsearch; do for tmplun in $lunsearch; do
if test $tmplun -eq $lun ; then if test $tmplun -eq $lun ; then
# Optimization: don't scan lun 0 again dolunscan
if [ $lun -ne 0 ]; then
dolunscan
fi
else else
newsearch="$newsearch $tmplun" newsearch="$newsearch $tmplun"
fi fi
@ -405,7 +417,7 @@ dosearch ()
idlist idlist
fi fi
for id in $idsearch; do for id in $idsearch; do
if test -z "$lunsearch"; then if test -z "$lunsearch" ; then
doreportlun doreportlun
else else
for lun in $lunsearch; do for lun in $lunsearch; do
@ -428,6 +440,7 @@ if test @$1 = @--help -o @$1 = @-h -o @$1 = @-?; then
echo " -i issue a FibreChannel LIP reset [default: disabled]" echo " -i issue a FibreChannel LIP reset [default: disabled]"
echo "--remove: same as -r" echo "--remove: same as -r"
echo "--issue-lip: same as -i" echo "--issue-lip: same as -i"
echo "--forcerescan: Rescan existing devices"
echo "--forceremove: Remove and readd every device (DANGEROUS)" echo "--forceremove: Remove and readd every device (DANGEROUS)"
echo "--nooptscan: don't stop looking for LUNs is 0 is not found" echo "--nooptscan: don't stop looking for LUNs is 0 is not found"
echo "--color: use coloured prefixes OLD/NEW/DEL" echo "--color: use coloured prefixes OLD/NEW/DEL"
@ -483,7 +496,7 @@ fi
unsetcolor unsetcolor
lunsearch="" lunsearch=""
idsearch=`seq 0 7` idsearch=`seq 0 7`
channelsearch="0" channelsearch=""
remove= remove=
forceremove= forceremove=
optscan=1 optscan=1
@ -505,6 +518,7 @@ while test ! -z "$opt" -a -z "${opt##-*}"; do
r) remove=1 ;; r) remove=1 ;;
i) lipreset=1 ;; i) lipreset=1 ;;
-remove) remove=1 ;; -remove) remove=1 ;;
-forcerescan) remove=1; forcerescan=1 ;;
-forceremove) remove=1; forceremove=1 ;; -forceremove) remove=1; forceremove=1 ;;
-hosts=*) arg=${opt#-hosts=}; hosts=`expandlist $arg` ;; -hosts=*) arg=${opt#-hosts=}; hosts=`expandlist $arg` ;;
-channels=*) arg=${opt#-channels=};channelsearch=`expandlist $arg` ;; -channels=*) arg=${opt#-channels=};channelsearch=`expandlist $arg` ;;

View File

@ -1,3 +1,11 @@
-------------------------------------------------------------------
Mon Jan 26 15:30:31 CET 2009 - hare@suse.de
- Fixes to rescan-scsi-bus.sh:
* Implement '--forcerescan' to force a rescan of existing devices
* Handle LUN changes correctly
* Check variables before evaluation
------------------------------------------------------------------- -------------------------------------------------------------------
Wed Oct 29 11:05:47 CET 2008 - garloff@suse.de Wed Oct 29 11:05:47 CET 2008 - garloff@suse.de

View File

@ -1,7 +1,7 @@
# #
# spec file for package sg3_utils (Version 1.27) # spec file for package sg3_utils (Version 1.27)
# #
# Copyright (c) 2008 SUSE LINUX Products GmbH, Nuernberg, Germany. # Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany.
# #
# All modifications and additions to the file contributed by third parties # All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed # remain the property of their copyright owners, unless otherwise agreed
@ -28,7 +28,7 @@ Obsoletes: scsi <= 1.7_2.38_1.25_0.19_1.02_0.93
AutoReqProv: on AutoReqProv: on
PreReq: %insserv_prereq PreReq: %insserv_prereq
Version: 1.27 Version: 1.27
Release: 16 Release: 18
Summary: A collection of tools that send SCSI commands to devices Summary: A collection of tools that send SCSI commands to devices
Source: http://sg.torque.net/sg/p/sg3_utils-%{sgver}.tar.bz2 Source: http://sg.torque.net/sg/p/sg3_utils-%{sgver}.tar.bz2
Source2: http://www.garloff.de/kurt/linux/rescan-scsi-bus.sh Source2: http://www.garloff.de/kurt/linux/rescan-scsi-bus.sh
@ -225,6 +225,11 @@ test ! -z "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != "/" && rm -rf $RPM_BUILD_ROO
rm -rf $RPM_BUILD_DIR/sg3_utils-%{sgver} rm -rf $RPM_BUILD_DIR/sg3_utils-%{sgver}
%changelog %changelog
* Mon Jan 26 2009 hare@suse.de
- Fixes to rescan-scsi-bus.sh:
* Implement '--forcerescan' to force a rescan of existing devices
* Handle LUN changes correctly
* Check variables before evaluation
* Wed Oct 29 2008 garloff@suse.de * Wed Oct 29 2008 garloff@suse.de
- rescan-scsi-bus.sh 1.29: - rescan-scsi-bus.sh 1.29:
* Fix error in script (returning "" does not work) * Fix error in script (returning "" does not work)