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

View File

@ -1,7 +1,7 @@
#
# 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
# 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
PreReq: %insserv_prereq
Version: 1.27
Release: 16
Release: 18
Summary: A collection of tools that send SCSI commands to devices
Source: http://sg.torque.net/sg/p/sg3_utils-%{sgver}.tar.bz2
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}
%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
- rescan-scsi-bus.sh 1.29:
* Fix error in script (returning "" does not work)