- update to version 1.28

- added fixes from RHEL to rescan-scsi-bus.sh
- added scsi-rescan symlink to the rescan-scsi-bus.sh script
This commit is contained in:
Dan Horák 2009-10-22 12:48:53 +00:00
parent f8dd63d5df
commit be434889f9
4 changed files with 438 additions and 7 deletions

View File

@ -1,2 +1,2 @@
sg3_utils-1.27.tgz
sg3_utils-1.28.tgz
rescan-scsi-bus.sh-1.29

419
rescan-scsi-bus-fixes.patch Normal file
View File

@ -0,0 +1,419 @@
From 9aebc83c6dc1e1c824552792bab7f9edac6d41a6 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Dan=20Hor=C3=A1k?= <dan@danny.cz>
Date: Tue, 7 Jul 2009 14:22:27 +0200
Subject: [PATCH] suse patch 090127
---
rescan-scsi-bus.sh | 104 +++++++++++++++++++++++++++++----------------------
1 files changed, 59 insertions(+), 45 deletions(-)
diff --git a/rescan-scsi-bus.sh b/rescan-scsi-bus.sh
index 4378e20..ce61ab2 100644
--- a/rescan-scsi-bus.sh
+++ b/rescan-scsi-bus.sh
@@ -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` ;;
--
1.6.0.6
From 9390109b3b86afe2ff7b260f483e3463d70c851c Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Dan=20Hor=C3=A1k?= <dan@danny.cz>
Date: Tue, 7 Jul 2009 15:25:54 +0200
Subject: [PATCH] netapp - fixes in doreportlun
---
rescan-scsi-bus.sh | 64 ++++++++++++++++++++++++++++++++++------------------
1 files changed, 42 insertions(+), 22 deletions(-)
diff --git a/rescan-scsi-bus.sh b/rescan-scsi-bus.sh
index ce61ab2..a939b1d 100644
--- a/rescan-scsi-bus.sh
+++ b/rescan-scsi-bus.sh
@@ -357,37 +357,57 @@ dolunscan()
# Perform report lun scan
doreportlun()
{
- lun=0
+ lun=
SCSISTR=
- devnr="$host $channel $id $lun"
- echo "Scanning for device $devnr ..."
- printf "${yellow}OLD: $norm"
- testexist
- if test -z "$SCSISTR"; then
- # Device does not exist, try to add
- printf "\r${green}NEW: $norm"
- if test -e /sys/class/scsi_host/host${host}/scan; then
- echo "$channel $id $lun" > /sys/class/scsi_host/host${host}/scan 2> /dev/null
- else
- echo "scsi add-single-device $devnr" > /proc/scsi/scsi
- fi
+ for dev in /sys/class/scsi_device/${host}:${channel}:${id}:*; do
+ if [ -d "$dev" ]; then
+ lun=${dev##*:}
+ break
+ else
+ continue
+ fi
+ done
+ #If not a single LUN is present then assign lun=0
+ if [ -z $lun ]; then
+ lun=0
+ devnr="$host $channel $id $lun"
+ echo "Scanning for device $devnr ..."
+ printf "${yellow}OLD: $norm"
testexist
if test -z "$SCSISTR"; then
- # Device not present
- printf "\r\x1b[A";
- lunsearch=
- return
+ # Device does not exist, try to add
+ printf "\r${green}NEW: $norm"
+ if test -e /sys/class/scsi_host/host${host}/scan; then
+ echo "$channel $id $lun" > /sys/class/scsi_host/host${host}/scan 2> /dev/null
+ else
+ echo "scsi add-single-device $devnr" > /proc/scsi/scsi
+ fi
+ testexist
+ if test -z "$SCSISTR"; then
+ # Device not present
+ printf "\r\x1b[A";
+ lunsearch=
+ return
+ fi
fi
fi
- lunsearch=`getluns`
+ flag=0
+ lun_search="`getluns`"
+ # Set flag=1 if all the LUNs are removed
+ if [ "${#lun_search}" = "1" ]; then
+ flag=1
+ fi
lunremove=
# Check existing luns
for dev in /sys/class/scsi_device/${host}:${channel}:${id}:*; do
[ -d "$dev" ] || continue
lun=${dev##*:}
+ if [ "$flag" = "1" ]; then
+ lunremove="$lunremove $lun"
+ fi
newsearch=
- oldsearch="$lunsearch"
- for tmplun in $lunsearch; do
+ oldsearch="$lun_search"
+ for tmplun in $lun_search; do
if test $tmplun -eq $lun ; then
dolunscan
else
@@ -398,10 +418,10 @@ doreportlun()
# Stale lun
lunremove="$lunremove $lun"
fi
- lunsearch="$newsearch"
+ lun_search="$newsearch"
done
# Add new ones and check stale ones
- for lun in $lunsearch $lunremove; do
+ for lun in $lun_search $lunremove; do
dolunscan
done
}
--
1.6.0.6
From ffb5528871e9bdd35cccaec26734a2faeb585fdc Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Dan=20Hor=C3=A1k?= <dan@danny.cz>
Date: Tue, 7 Jul 2009 15:37:23 +0200
Subject: [PATCH] netapp - LIP is not required to do a scan on FC
---
rescan-scsi-bus.sh | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/rescan-scsi-bus.sh b/rescan-scsi-bus.sh
index a939b1d..0754004 100644
--- a/rescan-scsi-bus.sh
+++ b/rescan-scsi-bus.sh
@@ -565,11 +565,10 @@ declare -i rmvd=0
for host in $hosts; do
echo -n "Scanning host $host "
if test -e /sys/class/fc_host/host$host ; then
- # It's pointless to do a target scan on FC
if test -n "$lipreset" ; then
echo 1 > /sys/class/fc_host/host$host/issue_lip 2> /dev/null;
- echo "- - -" > /sys/class/scsi_host/host$host/scan 2> /dev/null;
fi
+ echo "- - -" > /sys/class/scsi_host/host$host/scan 2> /dev/null;
channelsearch=""
idsearch=""
fi
--
1.6.0.6
From 50cab941cd1faa063326e3dd56f111430d05debc Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Dan=20Hor=C3=A1k?= <dan@danny.cz>
Date: Wed, 8 Jul 2009 10:39:56 +0200
Subject: [PATCH] space before getluns call is required
---
rescan-scsi-bus.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/rescan-scsi-bus.sh b/rescan-scsi-bus.sh
index 0754004..9f7036f 100644
--- a/rescan-scsi-bus.sh
+++ b/rescan-scsi-bus.sh
@@ -392,7 +392,7 @@ doreportlun()
fi
fi
flag=0
- lun_search="`getluns`"
+ lun_search=" `getluns`"
# Set flag=1 if all the LUNs are removed
if [ "${#lun_search}" = "1" ]; then
flag=1
--
1.6.0.6

View File

@ -1,13 +1,15 @@
%define rescan_version 1.29
%define rescan_script rescan-scsi-bus.sh
Summary: Utilities for devices that use SCSI command sets
Name: sg3_utils
Version: 1.27
Release: 2%{?dist}
Version: 1.28
Release: 1%{?dist}
License: GPLv2+ and BSD
Group: Applications/System
Source0: http://sg.danny.cz/sg/p/sg3_utils-%{version}.tgz
Source1: http://www.garloff.de/kurt/linux/rescan-scsi-bus.sh-%{rescan_version}
Source1: http://www.garloff.de/kurt/linux/%{rescan_script}-%{rescan_version}
Patch100: rescan-scsi-bus-fixes.patch
URL: http://sg.danny.cz/sg/sg3_utils.html
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Requires: %{name}-libs = %{version}-%{release}
@ -47,6 +49,10 @@ developing applications.
%prep
%setup -q
# rescan-scsi-bus.sh
cp -p %{SOURCE1} %{rescan_script}
%patch100 -p1 -b .orig
%build
%configure --disable-static
@ -62,7 +68,8 @@ make %{?_smp_mflags}
make install DESTDIR=$RPM_BUILD_ROOT
rm -rf $RPM_BUILD_ROOT/%{_libdir}/*.la
install -p -m 755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/rescan-scsi-bus.sh
install -p -m 755 %{rescan_script} $RPM_BUILD_ROOT%{_bindir}
( cd $RPM_BUILD_ROOT%{_bindir}; ln -sf %{rescan_script} scsi-rescan )
%clean
@ -91,6 +98,11 @@ rm -rf $RPM_BUILD_ROOT
%changelog
* Thu Oct 22 2009 Dan Horák <dan@danny.cz> - 1.28-1
- update to version 1.28
- added fixes from RHEL to rescan-scsi-bus.sh
- added scsi-rescan symlink to the rescan-scsi-bus.sh script
* Sun Jul 26 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.27-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild

View File

@ -1,2 +1,2 @@
de42374a6ba11258f1963134542af12c sg3_utils-1.27.tgz
e59d5eb56475e2443b6188cf50ac8f67 sg3_utils-1.28.tgz
679aa223710bddffe40d0cfc700009b7 rescan-scsi-bus.sh-1.29