OBS User unknown 2008-09-13 10:13:23 +00:00 committed by Git OBS Bridge
parent f65fd122aa
commit 61750adfe6
3 changed files with 53 additions and 43 deletions

View File

@ -1,9 +1,9 @@
#!/bin/bash
# Skript to rescan SCSI bus, using the
# scsi add-single-device mechanism
# (w) 1998-03-19 Kurt Garloff <kurt@garloff.de> (c) GNU GPL
# (w) 2003-07-16 Kurt Garloff <garloff@suse.de> (c) GNU GPL
# $Id: rescan-scsi-bus.sh,v 1.24 2006/07/29 12:34:11 garloff Exp $
# (c) 1998--2008 Kurt Garloff <kurt@garloff.de>, GNU GPL v2 or later
# (c) 2006--2008 Hannes Reinecke, GNU GPL v2 or later
# $Id: rescan-scsi-bus.sh,v 1.28 2008/09/12 18:28:02 garloff Exp $
setcolor ()
{
@ -39,7 +39,8 @@ findhosts_26 ()
fi
hosts="$hosts $hostno"
echo "Host adapter $hostno ($hostname) found."
done
done
hosts=`echo $hosts | sed 's/ /\n/g' | sort -n`
}
# Return hosts. /proc/scsi/HOSTADAPTER/? must exist
@ -64,29 +65,6 @@ 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.
@ -111,7 +89,24 @@ $SCSIDEV"
if [ "$LN" -gt 1 ] ; then
ILVL=$(cat ${SCSIPATH}/device/scsi_level)
type=$(cat ${SCSIPATH}/device/type)
ITYPE=$(printtype $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
SCSITMP=$(printf ' Type: %-16s ANSI SCSI revision: %02d' "$ITYPE" "$((ILVL - 1))")
SCSISTR="$SCSISTR
$SCSITMP"
@ -200,18 +195,17 @@ testonline ()
return 1
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:${SCSISTR#* } \nto: $STR ${norm}\n\n\n"
return 0
echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nfrom:${TMPSTR#* } \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 0
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
}
@ -297,18 +291,17 @@ dolunscan()
# Device exists: Test whether it's still online
# (testonline returns 1 if it's gone or has changed)
testonline
RC=$?
if test $RC = 1 -o ! -z "$forceremove"; then
if test $? = 1 -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 readding, should fail if device is gone
# Try reading, should fail if device is gone
echo "$channel $id $lun" > /sys/class/scsi_host/host${host}/scan
else
echo "scsi remove-single-device $devnr" > /proc/scsi/scsi
# Try readding, should fail if device is gone
# Try reading, should fail if device is gone
echo "scsi add-single-device $devnr" > /proc/scsi/scsi
fi
fi
@ -317,6 +310,7 @@ dolunscan()
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
@ -380,7 +374,10 @@ doreportlun()
oldsearch="$lunsearch"
for tmplun in $lunsearch; do
if test $tmplun -eq $lun ; then
dolunscan
# Optimization: don't scan lun 0 again
if [ $lun -ne 0 ]; then
dolunscan
fi
else
newsearch="$newsearch $tmplun"
fi
@ -408,7 +405,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
@ -486,7 +483,7 @@ fi
unsetcolor
lunsearch=""
idsearch=`seq 0 7`
channelsearch=""
channelsearch="0"
remove=
forceremove=
optscan=1

View File

@ -1,3 +1,11 @@
-------------------------------------------------------------------
Fri Sep 12 20:29:08 CEST 2008 - garloff@suse.de
- Update rescan-scsi-bus.sh script to 1.28:
* Merge fixes from Hannes
* Minor cleanups
* Sort hosts numerically
-------------------------------------------------------------------
Tue Aug 12 18:25:43 CEST 2008 - garloff@suse.de

View File

@ -27,7 +27,7 @@ Provides: scsi
Obsoletes: scsi <= 1.7_2.38_1.25_0.19_1.02_0.93
AutoReqProv: on
Version: 1.27
Release: 1
Release: 12
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
@ -53,7 +53,7 @@ Authors:
%package devel
License: BSD 3-Clause; GPL v2 or later
Summary: A collection of tools that send SCSI commands to devices
Group: Hardware/Other
Group: Development/Libraries/C and C++
AutoReqProv: on
Requires: %name = %version
@ -224,6 +224,11 @@ test ! -z "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != "/" && rm -rf $RPM_BUILD_ROO
rm -rf $RPM_BUILD_DIR/sg3_utils-%{sgver}
%changelog
* Fri Sep 12 2008 garloff@suse.de
- Update rescan-scsi-bus.sh script to 1.28:
* Merge fixes from Hannes
* Minor cleanups
* Sort hosts numerically
* Tue Aug 12 2008 garloff@suse.de
- Update to sg3_utils-1.27:
* Adapted to linux-2.6.26 (sg_map26)