diff --git a/.cvsignore b/.cvsignore index 23c6d95..ad9f887 100644 --- a/.cvsignore +++ b/.cvsignore @@ -1,2 +1,2 @@ sg3_utils-1.28.tgz -rescan-scsi-bus.sh-1.29 +rescan-scsi-bus.sh-1.35 diff --git a/rescan-scsi-bus-fixes.patch b/rescan-scsi-bus-fixes.patch index f5452ec..1c08b52 100644 --- a/rescan-scsi-bus-fixes.patch +++ b/rescan-scsi-bus-fixes.patch @@ -1,275 +1,17 @@ -From 9aebc83c6dc1e1c824552792bab7f9edac6d41a6 Mon Sep 17 00:00:00 2001 -From: =?utf-8?q?Dan=20Hor=C3=A1k?= -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?= -Date: Tue, 7 Jul 2009 15:25:54 +0200 -Subject: [PATCH] netapp - fixes in doreportlun +From 38842b5eafcd85bc91d96e2b2d0b99ea8864d907 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Dan=20Hor=C3=A1k?= +Date: Thu, 14 Jan 2010 12:50:05 +0100 +Subject: [PATCH 1/4] 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 +index af1f843..8d52e39 100644 --- a/rescan-scsi-bus.sh +++ b/rescan-scsi-bus.sh -@@ -357,37 +357,57 @@ dolunscan() +@@ -371,38 +371,58 @@ dolunscan() # Perform report lun scan doreportlun() { @@ -278,11 +20,11 @@ index ce61ab2..a939b1d 100644 SCSISTR= - devnr="$host $channel $id $lun" - echo "Scanning for device $devnr ..." -- printf "${yellow}OLD: $norm" -- testexist +- #printf "${yellow}OLD: $norm" +- testexist -q - if test -z "$SCSISTR"; then - # Device does not exist, try to add -- printf "\r${green}NEW: $norm" +- #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 @@ -302,7 +44,7 @@ index ce61ab2..a939b1d 100644 + devnr="$host $channel $id $lun" + echo "Scanning for device $devnr ..." + printf "${yellow}OLD: $norm" - testexist + testexist -1 if test -z "$SCSISTR"; then - # Device not present - printf "\r\x1b[A"; @@ -323,6 +65,7 @@ index ce61ab2..a939b1d 100644 + return + fi fi + #testonline fi - lunsearch=`getluns` + flag=0 @@ -336,9 +79,9 @@ index ce61ab2..a939b1d 100644 for dev in /sys/class/scsi_device/${host}:${channel}:${id}:*; do [ -d "$dev" ] || continue lun=${dev##*:} -+ if [ "$flag" = "1" ]; then -+ lunremove="$lunremove $lun" -+ fi ++ if [ "$flag" = "1" ]; then ++ lunremove="$lunremove $lun" ++ fi newsearch= - oldsearch="$lunsearch" - for tmplun in $lunsearch; do @@ -347,7 +90,7 @@ index ce61ab2..a939b1d 100644 if test $tmplun -eq $lun ; then dolunscan else -@@ -398,10 +418,10 @@ doreportlun() +@@ -413,10 +433,10 @@ doreportlun() # Stale lun lunremove="$lunremove $lun" fi @@ -361,22 +104,22 @@ index ce61ab2..a939b1d 100644 done } -- -1.6.0.6 +1.6.5.2 -From ffb5528871e9bdd35cccaec26734a2faeb585fdc Mon Sep 17 00:00:00 2001 -From: =?utf-8?q?Dan=20Hor=C3=A1k?= -Date: Tue, 7 Jul 2009 15:37:23 +0200 -Subject: [PATCH] netapp - LIP is not required to do a scan on FC +From 0e94e0c27d575f18a57938b9d98dfe02d8c11eb9 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Dan=20Hor=C3=A1k?= +Date: Thu, 14 Jan 2010 12:50:59 +0100 +Subject: [PATCH 2/4] 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 +index 8d52e39..13e9283 100644 --- a/rescan-scsi-bus.sh +++ b/rescan-scsi-bus.sh -@@ -565,11 +565,10 @@ declare -i rmvd=0 +@@ -587,11 +587,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 @@ -390,23 +133,23 @@ index a939b1d..0754004 100644 idsearch="" fi -- -1.6.0.6 +1.6.5.2 -From 50cab941cd1faa063326e3dd56f111430d05debc Mon Sep 17 00:00:00 2001 -From: =?utf-8?q?Dan=20Hor=C3=A1k?= -Date: Wed, 8 Jul 2009 10:39:56 +0200 -Subject: [PATCH] space before getluns call is required +From c3b67a28289bb010d141e172a184982c40e2fff2 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Dan=20Hor=C3=A1k?= +Date: Thu, 14 Jan 2010 12:51:31 +0100 +Subject: [PATCH 3/4] 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 +index 13e9283..26a9853 100644 --- a/rescan-scsi-bus.sh +++ b/rescan-scsi-bus.sh -@@ -392,7 +392,7 @@ doreportlun() - fi +@@ -407,7 +407,7 @@ doreportlun() + #testonline fi flag=0 - lun_search="`getluns`" @@ -415,5 +158,37 @@ index 0754004..9f7036f 100644 if [ "${#lun_search}" = "1" ]; then flag=1 -- -1.6.0.6 +1.6.5.2 + +From 5c10b085e2e83f371eddee16937157b0e7f63d5b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Dan=20Hor=C3=A1k?= +Date: Thu, 14 Jan 2010 15:15:34 +0100 +Subject: [PATCH 4/4] wait for device + +When a device reports "unit attention" state after calling sg_turs, then wait until the device comes online or a timeout is reached. +--- + rescan-scsi-bus.sh | 8 ++++++-- + 1 files changed, 6 insertions(+), 2 deletions(-) + +diff --git a/rescan-scsi-bus.sh b/rescan-scsi-bus.sh +index 26a9853..23fba7d 100644 +--- a/rescan-scsi-bus.sh ++++ b/rescan-scsi-bus.sh +@@ -195,8 +195,12 @@ testonline () + if test ! -x /usr/bin/sg_turs; then return 0; fi + sgdevice + if test -z "$SGDEV"; then return 0; fi +- sg_turs /dev/$SGDEV >/dev/null 2>&1 +- RC=$? ++ for t in 1 2 3 4 5; do ++ sg_turs /dev/$SGDEV >/dev/null 2>&1 ++ RC=$? ++ [ $RC -ne 6 ] && break ++ sleep $t ++ done + # echo -e "\e[A\e[A\e[A${yellow}Test existence of $SGDEV = $RC ${norm} \n\n\n" + if test $RC = 1; then return $RC; fi + # OK, device online, compare INQUIRY string +-- +1.6.5.2 diff --git a/sg3_utils.spec b/sg3_utils.spec index 5dc537a..bf0493e 100644 --- a/sg3_utils.spec +++ b/sg3_utils.spec @@ -1,10 +1,10 @@ -%define rescan_version 1.29 +%define rescan_version 1.35 %define rescan_script rescan-scsi-bus.sh Summary: Utilities for devices that use SCSI command sets Name: sg3_utils Version: 1.28 -Release: 1%{?dist} +Release: 2%{?dist} License: GPLv2+ and BSD Group: Applications/System Source0: http://sg.danny.cz/sg/p/sg3_utils-%{version}.tgz @@ -98,6 +98,10 @@ rm -rf $RPM_BUILD_ROOT %changelog +* Thu Jan 14 2010 Dan Horák - 1.28-2 +- include rescan-scsi-bus script 1.35 +- rebase patches and add fix for issue mentioned in #538787 + * Thu Oct 22 2009 Dan Horák - 1.28-1 - update to version 1.28 - added fixes from RHEL to rescan-scsi-bus.sh diff --git a/sources b/sources index a83fc2f..587797a 100644 --- a/sources +++ b/sources @@ -1,2 +1,2 @@ e59d5eb56475e2443b6188cf50ac8f67 sg3_utils-1.28.tgz -679aa223710bddffe40d0cfc700009b7 rescan-scsi-bus.sh-1.29 +51c796b2a1682f6f6f61ed6965f51ef5 rescan-scsi-bus.sh-1.35