Accepting request 100614 from home:tabraham1:branches:Base:System

update to 1.32 and latest rescan-scsi-bus.sh (v1.56)

OBS-URL: https://build.opensuse.org/request/show/100614
OBS-URL: https://build.opensuse.org/package/show/Base:System/sg3_utils?expand=0&rev=12
This commit is contained in:
Cristian Rodríguez 2012-01-18 22:40:48 +00:00 committed by Git OBS Bridge
parent 6fefb36d70
commit b59d67f4bd
5 changed files with 363 additions and 154 deletions

View File

@ -1,9 +1,11 @@
#!/bin/bash #!/bin/bash
# Skript to rescan SCSI bus, using the # Skript to rescan SCSI bus, using the
# scsi add-single-device mechanism # scsi add-single-device mechanism
# (c) 1998--2008 Kurt Garloff <kurt@garloff.de>, GNU GPL v2 or later # (c) 1998--2010 Kurt Garloff <kurt@garloff.de>, GNU GPL v2 or v3
# (c) 2006--2008 Hannes Reinecke, GNU GPL v2 or later # (c) 2006--2008 Hannes Reinecke, GNU GPL v2 or later
# $Id: rescan-scsi-bus.sh,v 1.29 2008/10/29 10:03:04 garloff Exp $ # $Id: rescan-scsi-bus.sh,v 1.56 2012/01/14 22:23:53 garloff Exp $
SCAN_WILD_CARD=4294967295
setcolor () setcolor ()
{ {
@ -20,26 +22,53 @@ unsetcolor ()
yellow=""; norm="" yellow=""; norm=""
} }
# Output some text and return cursor to previous position
# (only works for simple strings)
# Stores length of string in LN and returns it
print_and_scroll_back ()
{
STRG="$1"
LN=${#STRG}
BK=""
declare -i cntr=0
while test $cntr -lt $LN; do BK="$BK\e[D"; let cntr+=1; done
echo -en "$STRG$BK"
return $LN
}
# Overwrite a text of length $1 (fallback to $LN) with whitespace
white_out ()
{
BK=""; WH=""
if test -n "$1"; then LN=$1; fi
declare -i cntr=0
while test $cntr -lt $LN; do BK="$BK\e[D"; WH="$WH "; let cntr+=1; done
echo -en "$WH$BK"
}
# Return hosts. sysfs must be mounted # Return hosts. sysfs must be mounted
findhosts_26 () findhosts_26 ()
{ {
hosts= hosts=`find /sys/class/scsi_host/host* -maxdepth 4 -type d -o -type l 2> /dev/null | awk -F'/' '{print $5}' | sed -e 's~host~~' | sort -nu`
for hostdir in /sys/class/scsi_host/host*; do scsi_host_data=`echo "$hosts" | sed -e 's~^~/sys/class/scsi_host/host~'`
for hostdir in $scsi_host_data; 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
hostname="qla2xxx" hostname="qla2xxx"
elif [ -f $hostdir/lpfc_drvr_version ] ; then elif [ -f $hostdir/lpfc_drvr_version ] ; then
hostname="lpfc" hostname="lpfc"
else else
hostname=`cat $hostdir/proc_name` hostname=`cat $hostdir/proc_name`
fi fi
hosts="$hosts $hostno" #hosts="$hosts $hostno"
echo "Host adapter $hostno ($hostname) found." echo "Host adapter $hostno ($hostname) found."
done done
if [ -z "$hosts" ] ; then if [ -z "$hosts" ] ; then
echo "No SCSI host adapters found in sysfs" echo "No SCSI host adapters found in sysfs"
exit 1; exit 1;
fi fi
# Not necessary just use double quotes around variable to preserve new lines
#hosts=`echo $hosts | tr ' ' '\n'`
} }
# Return hosts. /proc/scsi/HOSTADAPTER/? must exist # Return hosts. /proc/scsi/HOSTADAPTER/? must exist
@ -66,63 +95,72 @@ findhosts ()
printtype () printtype ()
{ {
local type=$1 local type=$1
case "$type" in case "$type" in
0) echo "Direct-Access " ;; 0) echo "Direct-Access " ;;
1) echo "Sequential-Access" ;; 1) echo "Sequential-Access" ;;
2) echo "Printer " ;; 2) echo "Printer " ;;
3) echo "Processor " ;; 3) echo "Processor " ;;
4) echo "WORM " ;; 4) echo "WORM " ;;
5) echo "CD-ROM " ;; 5) echo "CD-ROM " ;;
6) echo "Scanner " ;; 6) echo "Scanner " ;;
7) echo "Optical Device " ;; 7) echo "Optical Device " ;;
8) echo "Medium Changer " ;; 8) echo "Medium Changer " ;;
9) echo "Communications " ;; 9) echo "Communications " ;;
10) echo "Unknown " ;; 10) echo "Unknown " ;;
11) echo "Unknown " ;; 11) echo "Unknown " ;;
12) echo "RAID " ;; 12) echo "RAID " ;;
13) echo "Enclosure " ;; 13) echo "Enclosure " ;;
14) echo "Direct-Access-RBC" ;; 14) echo "Direct-Access-RBC" ;;
*) echo "Unknown " ;; *) echo "Unknown " ;;
esac esac
} }
print02i()
{
if [ "$1" = "*" ] ; then
echo "00"
else
printf "%02i" "$1"
fi
}
# 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.
procscsiscsi () procscsiscsi ()
{ {
if test -z "$1"; then LN=2; else LN=$1; fi if test -z "$1"; then LN=2; else LN=$1; fi
CHANNEL=`printf "%02i" $channel` CHANNEL=`print02i "$channel"`
ID=`printf "%02i" $id` ID=`print02i "$id"`
LUN=`printf "%02i" $lun` LUN=`print02i "$lun"`
if [ -d /sys/class/scsi_device ]; then if [ -d /sys/class/scsi_device ]; then
SCSIPATH="/sys/class/scsi_device/${host}:${channel}:${id}:${lun}" SCSIPATH="/sys/class/scsi_device/${host}:${channel}:${id}:${lun}"
if [ -d "$SCSIPATH" ] ; then if [ -d "$SCSIPATH" ] ; then
SCSISTR="Host: scsi${host} Channel: $CHANNEL Id: $ID Lun: $LUN" SCSISTR="Host: scsi${host} Channel: $CHANNEL Id: $ID Lun: $LUN"
if [ "$LN" -gt 0 ] ; then if [ "$LN" -gt 0 ] ; then
IVEND=$(cat ${SCSIPATH}/device/vendor) IVEND=$(cat ${SCSIPATH}/device/vendor)
IPROD=$(cat ${SCSIPATH}/device/model) IPROD=$(cat ${SCSIPATH}/device/model)
IPREV=$(cat ${SCSIPATH}/device/rev) IPREV=$(cat ${SCSIPATH}/device/rev)
SCSIDEV=$(printf ' Vendor: %-08s Model: %-16s Rev: %-4s' "$IVEND" "$IPROD" "$IPREV") SCSIDEV=$(printf ' Vendor: %-08s Model: %-16s Rev: %-4s' "$IVEND" "$IPROD" "$IPREV")
SCSISTR="$SCSISTR SCSISTR="$SCSISTR
$SCSIDEV" $SCSIDEV"
fi
if [ "$LN" -gt 1 ] ; then
ILVL=$(cat ${SCSIPATH}/device/scsi_level)
type=$(cat ${SCSIPATH}/device/type)
ITYPE=$(printtype $type)
SCSITMP=$(printf ' Type: %-16s ANSI SCSI revision: %02d' "$ITYPE" "$((ILVL - 1))")
SCSISTR="$SCSISTR
$SCSITMP"
fi
else
return 1
fi fi
if [ "$LN" -gt 1 ] ; then
ILVL=$(cat ${SCSIPATH}/device/scsi_level)
type=$(cat ${SCSIPATH}/device/type)
ITYPE=$(printtype $type)
SCSITMP=$(printf ' Type: %-16s ANSI SCSI revision: %02d' "$ITYPE" "$((ILVL - 1))")
SCSISTR="$SCSISTR
$SCSITMP"
fi
else
return 1
fi
else else
grepstr="scsi$host Channel: $CHANNEL Id: $ID Lun: $LUN" grepstr="scsi$host Channel: $CHANNEL Id: $ID Lun: $LUN"
SCSISTR=`cat /proc/scsi/scsi | grep -A$LN -e"$grepstr"` SCSISTR=`cat /proc/scsi/scsi | grep -A$LN -e"$grepstr"`
fi fi
if test -z "$SCSISTR"; then return 1; else return 0; fi if test -z "$SCSISTR"; then return 1; else return 0; fi
} }
@ -153,6 +191,7 @@ sgdevice24 ()
} }
# Find sg device that belongs to SCSI device $host $channel $id $lun # Find sg device that belongs to SCSI device $host $channel $id $lun
# and return in SGDEV
sgdevice () sgdevice ()
{ {
SGDEV= SGDEV=
@ -174,21 +213,38 @@ sgdevice ()
echo "scsi report-devs 0" >/proc/scsi/scsi echo "scsi report-devs 0" >/proc/scsi/scsi
fi fi
fi fi
} }
# Test if SCSI device is still responding to commands # Test if SCSI device is still responding to commands
testonline () testonline ()
{ {
: testonline : testonline
RC=0
if test ! -x /usr/bin/sg_turs; then return 0; fi if test ! -x /usr/bin/sg_turs; then return 0; fi
sgdevice sgdevice
if test -z "$SGDEV"; then return 0; fi if test -z "$SGDEV"; then return 0; fi
sg_turs /dev/$SGDEV >/dev/null 2>&1 sg_turs /dev/$SGDEV >/dev/null 2>&1
RC=$? RC=$?
# Handle in progress of becoming ready and unit attention -- wait at max 11s
declare -i ctr=0
if test $RC = 2 -o $RC = 6; then
RMB=`sg_inq /dev/$SGDEV | grep 'RMB=' | sed 's/^.*RMB=\(.\).*$/\1/'`
print_and_scroll_back "$host:$channel:$id:$lun $SGDEV ($RMB) "
fi
while test $RC = 2 -o $RC = 6 && test $ctr -le 8; do
if test $RC = 2 -a "$RMB" != "1"; then echo -n "."; let $LN+=1; sleep 1
else usleep 20000; fi
let ctr+=1
sg_turs /dev/$SGDEV >/dev/null 2>&1
RC=$?
done
if test $ctr != 0; then white_out; fi
# echo -e "\e[A\e[A\e[A${yellow}Test existence of $SGDEV = $RC ${norm} \n\n\n" # 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 if test $RC = 1; then return $RC; fi
# Reset RC (might be !=0 for passive paths)
RC=0
# OK, device online, compare INQUIRY string # OK, device online, compare INQUIRY string
INQ=`sg_inq $sg_len_arg /dev/$SGDEV` INQ=`sg_inq $sg_len_arg /dev/$SGDEV 2>/dev/null`
IVEND=`echo "$INQ" | grep 'Vendor identification:' | sed 's/^[^:]*: \(.*\)$/\1/'` IVEND=`echo "$INQ" | grep 'Vendor identification:' | sed 's/^[^:]*: \(.*\)$/\1/'`
IPROD=`echo "$INQ" | grep 'Product identification:' | sed 's/^[^:]*: \(.*\)$/\1/'` IPROD=`echo "$INQ" | grep 'Product identification:' | sed 's/^[^:]*: \(.*\)$/\1/'`
IPREV=`echo "$INQ" | grep 'Product revision level:' | sed 's/^[^:]*: \(.*\)$/\1/'` IPREV=`echo "$INQ" | grep 'Product revision level:' | sed 's/^[^:]*: \(.*\)$/\1/'`
@ -196,7 +252,7 @@ testonline ()
IPTYPE=`echo "$INQ" | sed -n 's/.* Device_type=\([0-9]*\) .*/\1/p'` IPTYPE=`echo "$INQ" | sed -n 's/.* Device_type=\([0-9]*\) .*/\1/p'`
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}LU not available (PQual $IPQUAL)${norm} \n\n\n"
return 2 return 2
fi fi
@ -204,24 +260,25 @@ testonline ()
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:${SCSISTR#* } \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
} }
# Test if SCSI device $host $channen $id $lun exists # Test if SCSI device $host $channen $id $lun exists
# Outputs description from /proc/scsi/scsi, returns SCSISTR # Outputs description from /proc/scsi/scsi (unless arg passed)
# Returns SCSISTR (empty if no dev)
testexist () testexist ()
{ {
: testexist : testexist
SCSISTR= SCSISTR=
if procscsiscsi; then if procscsiscsi && test -z "$1"; then
echo "$SCSISTR" | head -n1 echo "$SCSISTR" | head -n1
echo "$SCSISTR" | tail -n2 | pr -o4 -l1 echo "$SCSISTR" | tail -n2 | pr -o4 -l1
fi fi
@ -249,6 +306,7 @@ chanlist ()
channelsearch="$channelsearch $chan" channelsearch="$channelsearch $chan"
fi fi
done done
if test -z "$channelsearch"; then channelsearch="0"; fi
} }
# Returns the list of existing targets per host # Returns the list of existing targets per host
@ -278,23 +336,59 @@ idlist ()
done done
} }
# Returns the list of existing LUNs # Returns the list of existing LUNs from device $host $channel $id $lun
getluns () # and returns list to stdout
getluns()
{ {
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 1; fi
sg_luns -d /dev/$SGDEV | sed -n 's/.*lun=\(.*\)/\1/p' if test ! -x /usr/bin/sg_luns; then echo 0; return 1; fi
LLUN=`sg_luns /dev/$SGDEV 2>/dev/null | sed -n 's/ \(.*\)/\1/p'`
if test $? != 0; then echo 0; return 1; fi
#echo "$LLUN" | sed -n 's/.*lun=\(.*\)/\1/p'
for lun in $LLUN ; do
# Swap LUN number
l0=$(printf '%u' 0x$lun)
l1=$(( ($l0 >> 48) & 0xffff ))
l2=$(( ($l0 >> 32) & 0xffff ))
l3=$(( ($l0 >> 16) & 0xffff ))
l4=$(( $l0 & 0xffff ))
l0=$(( ( ( ($l4 * 0xffff) + $l3 ) * 0xffff + $l2 ) * 0xffff + $l1 ))
printf "%u\n" $l0
done
return 0
} }
# Perform scan on a single lun # Wait for udev to settle (create device nodes etc.)
udevadm_settle()
{
if test -x /sbin/udevadm; then
print_and_scroll_back " Calling udevadm settle (can take a while) "
/sbin/udevadm settle
white_out
elif test -x /sbin/udevsettle; then
print_and_scroll_back " Calling udevsettle (can take a while) "
/sbin/udevsettle
white_out
else
usleep 20000
fi
}
# Perform scan on a single lun $host $channel $id $lun
dolunscan() dolunscan()
{ {
SCSISTR= SCSISTR=
devnr="$host $channel $id $lun" devnr="$host $channel $id $lun"
echo "Scanning for device $devnr ..." echo -e " Scanning for device $devnr ... "
printf "${yellow}OLD: $norm" printf "${yellow}OLD: $norm"
testexist testexist
# Special case: lun 0 just got added (for reportlunscan),
# so make sure we correctly treat it as new
if test "$lun" = "0" -a "$1"; then
SCSISTR=""
printf "\r\e[A\e[A\e[A"
fi
: f $remove s $SCSISTR : f $remove s $SCSISTR
if test "$remove" -a "$SCSISTR"; then if test "$remove" -a "$SCSISTR"; then
# Device exists: Test whether it's still online # Device exists: Test whether it's still online
@ -307,10 +401,9 @@ dolunscan()
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
if test $RC -eq 1 -o $lun -eq 0 ; then # FIXME: Can we skip udevadm settle for removal?
# Try readding, should fail if device is gone #udevadm_settle
echo "$channel $id $lun" > /sys/class/scsi_host/host${host}/scan usleep 20000
fi
else else
echo "scsi remove-single-device $devnr" > /proc/scsi/scsi echo "scsi remove-single-device $devnr" > /proc/scsi/scsi
if test $RC -eq 1 -o $lun -eq 0 ; then if test $RC -eq 1 -o $lun -eq 0 ; then
@ -322,9 +415,10 @@ dolunscan()
if test $RC = 0 -o "$forcerescan" ; 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
udevadm_settle
fi fi
fi fi
printf "\r\x1b[A\x1b[A\x1b[A${yellow}OLD: $norm" printf "\r\e[A\e[A\e[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"
@ -337,13 +431,14 @@ dolunscan()
printf "\r${green}NEW: $norm" printf "\r${green}NEW: $norm"
if test -e /sys/class/scsi_host/host${host}/scan; then 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 echo "$channel $id $lun" > /sys/class/scsi_host/host${host}/scan 2> /dev/null
udevadm_settle
else else
echo "scsi add-single-device $devnr" > /proc/scsi/scsi echo "scsi add-single-device $devnr" > /proc/scsi/scsi
fi fi
testexist testexist
if test -z "$SCSISTR"; then if test -z "$SCSISTR"; then
# Device not present # Device not present
printf "\r\x1b[A"; printf "\r\e[A";
# Optimization: if lun==0, stop here (only if in non-remove mode) # Optimization: if lun==0, stop here (only if in non-remove mode)
if test $lun = 0 -a -z "$remove" -a $optscan = 1; then if test $lun = 0 -a -z "$remove" -a $optscan = 1; then
break; break;
@ -354,58 +449,95 @@ dolunscan()
fi fi
} }
# Perform report lun scan # Perform report lun scan on $host $channel $id using REPORT_LUNS
doreportlun() doreportlun()
{ {
lun=0 lun=0
SCSISTR= SCSISTR=
devnr="$host $channel $id $lun" devnr="$host $channel $id $lun"
echo "Scanning for device $devnr ..." echo -en " Scanning for device $devnr ...\r"
printf "${yellow}OLD: $norm" lun0added=
testexist #printf "${yellow}OLD: $norm"
# Phase one: If LUN0 does not exist, try to add
testexist -q
if test -z "$SCSISTR"; then if test -z "$SCSISTR"; then
# Device does not exist, try to add # 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 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 echo "$channel $id $lun" > /sys/class/scsi_host/host${host}/scan 2> /dev/null
udevadm_settle
else else
echo "scsi add-single-device $devnr" > /proc/scsi/scsi echo "scsi add-single-device $devnr" > /proc/scsi/scsi
fi fi
testexist testexist -q
if test -z "$SCSISTR"; then if test -n "$SCSISTR"; then
lun0added=1
#testonline
else
# Device not present # Device not present
printf "\r\x1b[A"; # return
lunsearch= # Find alternative LUN to send getluns to
return for dev in /sys/class/scsi_device/${host}:${channel}:${id}:*; do
[ -d "$dev" ] || continue
lun=${dev##*:}
break
done
fi fi
fi fi
lunsearch=`getluns` targetluns=`getluns`
REPLUNSTAT=$?
lunremove= lunremove=
#echo "getluns reports " $targetluns
olddev=`find /sys/class/scsi_device/ -name $host:$channel:$id:* 2>/dev/null`
oldluns=`echo "$olddev" | awk -F'/' '{print $5}' | awk -F':' '{print $4}'`
oldtargets="$targetluns"
# OK -- if we don't have a LUN to send a REPORT_LUNS to, we could
# fall back to wildcard scanning. Same thing if the device does not
# support REPORT_LUNS
# TODO: We might be better off to ALWAYS use wildcard scanning if
# it works
if test "$REPLUNSTAT" = "1"; then
if test -e /sys/class/scsi_host/host${host}/scan; then
echo "$channel $id -" > /sys/class/scsi_host/host${host}/scan 2> /dev/null
udevadm_settle
else
echo "scsi add-single-device $host $channel $id $SCAN_WILD_CARD" > /proc/scsi/scsi
fi
targetluns=`find /sys/class/scsi_device/ -name $host:$channel:$id:* 2>/dev/null | awk -F'/' '{print $5}' | awk -F':' '{print $4}' | sort -n`
let found+=`echo "$targetluns" | wc -l`
let found-=`echo "$olddev" | wc -l`
fi
if test -z "$targetluns"; then targetluns="$oldtargets"; fi
# Check existing luns # Check existing luns
for dev in /sys/class/scsi_device/${host}:${channel}:${id}:*; do for dev in $olddev; do
[ -d "$dev" ] || continue [ -d "$dev" ] || continue
lun=${dev##*:} lun=${dev##*:}
newsearch= newsearch=
oldsearch="$lunsearch" inlist=
for tmplun in $lunsearch; do # OK, is existing $lun (still) in reported list
for tmplun in $targetluns; do
if test $tmplun -eq $lun ; then if test $tmplun -eq $lun ; then
dolunscan inlist=1
dolunscan $lun0added
else else
newsearch="$newsearch $tmplun" newsearch="$newsearch $tmplun"
fi fi
done done
if [ "${#oldsearch}" = "${#newsearch}" ] ; then # OK, we have now done a lunscan on $lun and
# Stale lun # $newsearch is the old $targetluns without $lun
lunremove="$lunremove $lun" if [ -z "$inlist" ]; then
# Stale lun
lunremove="$lunremove $lun"
fi fi
lunsearch="$newsearch" # $lun removed from $lunsearch (echo for whitespace cleanup)
targetluns=`echo $newsearch`
done done
# Add new ones and check stale ones # Add new ones and check stale ones
for lun in $lunsearch $lunremove; do for lun in $targetluns $lunremove; do
dolunscan dolunscan $lun0added
done done
} }
# Perform search (scan $host) # Perform search (scan $host)
dosearch () dosearch ()
{ {
@ -428,14 +560,35 @@ dosearch ()
done done
} }
expandlist ()
{
list=$1
result=""
first=${list%%,*}
rest=${list#*,}
while test ! -z "$first"; do
beg=${first%%-*};
if test "$beg" = "$first"; then
result="$result $beg";
else
end=${first#*-}
result="$result `seq $beg $end`"
fi
test "$rest" = "$first" && rest=""
first=${rest%%,*}
rest=${rest#*,}
done
echo $result
}
# main # main
if test @$1 = @--help -o @$1 = @-h -o @$1 = @-?; then if test @$1 = @--help -o @$1 = @-h -o @$1 = @-?; then
echo "Usage: rescan-scsi-bus.sh [options] [host [host ...]]" echo "Usage: rescan-scsi-bus.sh [options] [host [host ...]]"
echo "Options:" echo "Options:"
echo " -l activates scanning for LUNs 0-7 [default: 0]" echo " -l activates scanning for LUNs 0--7 [default: 0]"
echo " -L NUM activates scanning for LUNs 0--NUM [default: 0]" echo " -L NUM activates scanning for LUNs 0--NUM [default: 0]"
echo " -w scan for target device IDs 0 .. 15 [default: 0-7]" echo " -w scan for target device IDs 0--15 [default: 0--7]"
echo " -c enables scanning of channels 0 1 [default: 0]" echo " -c enables scanning of channels 0 1 [default: 0 / all detected ones]"
echo " -r enables removing of devices [default: disabled]" echo " -r enables removing of devices [default: disabled]"
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"
@ -448,6 +601,11 @@ if test @$1 = @--help -o @$1 = @-h -o @$1 = @-?; then
echo "--channels=LIST: Scan only channel(s) in LIST" echo "--channels=LIST: Scan only channel(s) in LIST"
echo "--ids=LIST: Scan only target ID(s) in LIST" echo "--ids=LIST: Scan only target ID(s) in LIST"
echo "--luns=LIST: Scan only lun(s) in LIST" echo "--luns=LIST: Scan only lun(s) in LIST"
echo "--sync/nosync: Issue a sync / no sync [default: sync if remove]"
echo "--attachpq3: Tell kernel to attach sg to LUN 0 that reports PQ=3"
echo "--reportlun2: Tell kernel to try REPORT_LUN even on SCSI2 devices"
echo "--largelun: Tell kernel to support LUNs > 7 even on SCSI2 devs"
echo "--sparselun: Tell kernel to support sparse LUN numbering"
echo " Host numbers may thus be specified either directly on cmd line (deprecated) or" echo " Host numbers may thus be specified either directly on cmd line (deprecated) or"
echo " or with the --hosts=LIST parameter (recommended)." echo " or with the --hosts=LIST parameter (recommended)."
echo "LIST: A[-B][,C[-D]]... is a comma separated list of single values and ranges" echo "LIST: A[-B][,C[-D]]... is a comma separated list of single values and ranges"
@ -455,27 +613,6 @@ if test @$1 = @--help -o @$1 = @-h -o @$1 = @-?; then
exit 0 exit 0
fi fi
expandlist ()
{
list=$1
result=""
first=${list%%,*}
rest=${list#*,}
while test ! -z "$first"; do
beg=${first%%-*};
if test "$beg" = "$first"; then
result="$result $beg";
else
end=${first#*-}
result="$result `seq $beg $end`"
fi
test "$rest" = "$first" && rest=""
first=${rest%%,*}
rest=${rest#*,}
done
echo $result
}
if test ! -d /sys/class/scsi_host/ -a ! -d /proc/scsi/; then if test ! -d /sys/class/scsi_host/ -a ! -d /proc/scsi/; then
echo "Error: SCSI subsystem not active" echo "Error: SCSI subsystem not active"
exit 1 exit 1
@ -484,22 +621,30 @@ fi
# Make sure sg is there # Make sure sg is there
modprobe sg >/dev/null 2>&1 modprobe sg >/dev/null 2>&1
sg_version=$(sg_inq -V 2>&1 | cut -d " " -f 3) if test -x /usr/bin/sg_inq; then
sg_version=${sg_version##0.} sg_version=$(sg_inq -V 2>&1 | cut -d " " -f 3)
if [ "$sg_version" -lt 70 ] ; then sg_version=${sg_version##0.}
sg_len_arg="-36" #echo "\"$sg_version\""
if [ -z "$sg_version" -o "$sg_version" -lt 70 ] ; then
sg_len_arg="-36"
else
sg_len_arg="--len=36"
fi
else else
sg_len_arg="--len=36" echo "WARN: /usr/bin/sg_inq not present -- please install sg3_utils"
fi echo " or rescan-scsi-bus.sh might not fully work."
fi
# defaults # defaults
unsetcolor unsetcolor
lunsearch="" lunsearch=
idsearch=`seq 0 7` opt_idsearch=`seq 0 7`
channelsearch="" opt_channelsearch=
remove= remove=
forceremove= forceremove=
optscan=1 optscan=1
sync=1
declare -i scan_flags=0
if test -d /sys/class/scsi_host; then if test -d /sys/class/scsi_host; then
findhosts_26 findhosts_26
else else
@ -513,20 +658,26 @@ while test ! -z "$opt" -a -z "${opt##-*}"; do
case "$opt" in case "$opt" in
l) lunsearch=`seq 0 7` ;; l) lunsearch=`seq 0 7` ;;
L) lunsearch=`seq 0 $2`; shift ;; L) lunsearch=`seq 0 $2`; shift ;;
w) idsearch=`seq 0 15` ;; w) opt_idsearch=`seq 0 15` ;;
c) channelsearch="0 1" ;; c) opt_channelsearch="0 1" ;;
r) remove=1 ;; r) remove=1 ;;
i) lipreset=1 ;; i) lipreset=1 ;;
-remove) remove=1 ;; -remove) remove=1 ;;
-forcerescan) remove=1; forcerescan=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=};opt_channelsearch=`expandlist $arg` ;;
-ids=*) arg=${opt#-ids=}; idsearch=`expandlist $arg` ;; -ids=*) arg=${opt#-ids=}; opt_idsearch=`expandlist $arg` ;;
-luns=*) arg=${opt#-luns=}; lunsearch=`expandlist $arg` ;; -luns=*) arg=${opt#-luns=}; lunsearch=`expandlist $arg` ;;
-color) setcolor ;; -color) setcolor ;;
-nooptscan) optscan=0 ;; -nooptscan) optscan=0 ;;
-issue-lip) lipreset=1 ;; -issue-lip) lipreset=1 ;;
-sync) sync=2 ;;
-nosync) sync=0 ;;
-attachpq3) scan_flags=$(($scan_flags|0x1000000)) ;;
-reportlun2) scan_flags=$(($scan_flags|0x20000)) ;;
-largelun) scan_flags=$(($scan_flags|0x200)) ;;
-sparselun) scan_flags=$((scan_flags|0x40)) ;;
*) echo "Unknown option -$opt !" ;; *) echo "Unknown option -$opt !" ;;
esac esac
shift shift
@ -535,9 +686,26 @@ done
# Hosts given ? # Hosts given ?
if test "@$1" != "@"; then if test "@$1" != "@"; then
hosts=$*; hosts=$*
fi fi
if [ -d /sys/class/scsi_host -a ! -w /sys/class/scsi_host ]; then
echo "You need to run scsi-rescan-bus.sh as root"
exit 2
fi
if test "$sync" = 1 -a "$remove" = 1; then sync=2; fi
if test "$sync" = 2; then echo "Syncing file systems"; sync; fi
if test -w /sys/module/scsi_mod/parameters/default_dev_flags -a $scan_flags != 0; then
OLD_SCANFLAGS=`cat /sys/module/scsi_mod/parameters/default_dev_flags`
NEW_SCANFLAGS=$(($OLD_SCANFLAGS|$scan_flags))
if test "$OLD_SCANFLAGS" != "$NEW_SCANFLAGS"; then
echo -n "Temporarily setting kernel scanning flags from "
printf "0x%08x to 0x%08x\n" $OLD_SCANFLAGS $NEW_SCANFLAGS
echo $NEW_SCANFLAGS > /sys/module/scsi_mod/parameters/default_dev_flags
else
unset OLD_SCANFLAGS
fi
fi
echo "Scanning SCSI subsystem for new devices" echo "Scanning SCSI subsystem for new devices"
test -z "$remove" || echo " and remove devices that have disappeared" test -z "$remove" || echo " and remove devices that have disappeared"
declare -i found=0 declare -i found=0
@ -548,25 +716,40 @@ for host in $hosts; do
# It's pointless to do a target scan on FC # It's pointless to do a target scan on FC
if test -n "$lipreset" ; then if test -n "$lipreset" ; then
echo 1 > /sys/class/fc_host/host$host/issue_lip 2> /dev/null; echo 1 > /sys/class/fc_host/host$host/issue_lip 2> /dev/null;
echo "- - -" > /sys/class/scsi_host/host$host/scan 2> /dev/null; udevadm_settle
fi fi
channelsearch="" # We used to always trigger a rescan for FC to update channels and targets
idsearch="" # Commented out -- as discussed with Hannes we should rely
# on the main loop doing the scan, no need to do it here.
#echo "- - -" > /sys/class/scsi_host/host$host/scan 2> /dev/null;
#udevadm_settle
channelsearch=
idsearch=
else
channelsearch=$opt_channelsearch
idsearch=$opt_idsearch
fi fi
[ -n "$channelsearch" ] && echo -n "channels $channelsearch " [ -n "$channelsearch" ] && echo -n "channels $channelsearch "
echo -n "for " echo -n "for "
if [ -n "$idsearch" ] ; then if [ -n "$idsearch" ] ; then
echo -n " SCSI target IDs " $idsearch echo -n " SCSI target IDs " $idsearch
else else
echo -n " all SCSI target IDs" echo -n " all SCSI target IDs"
fi fi
if [ -n "$lunsearch" ] ; then if [ -n "$lunsearch" ] ; then
echo ", LUNs " $lunsearch echo ", LUNs " $lunsearch
else else
echo ", all LUNs" echo ", all LUNs"
fi fi
dosearch; dosearch
done done
if test -n "$OLD_SCANFLAGS"; then
echo $OLD_SCANFLAGS > /sys/module/scsi_mod/parameters/default_dev_flags
fi
echo "$found new device(s) found. " echo "$found new device(s) found. "
echo "$rmvd device(s) removed. " echo "$rmvd device(s) removed. "
# Local Variables:
# sh-basic-offset: 2
# End:

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8ea682e51dc45209d8af91366fb4a15ea553152ce8a57928fa00b33b8f091d68
size 696939

3
sg3_utils-1.32.tar.bz2 Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a16ff8dab5605c2322d642956866e51cf529cc4d5460f701d42a49a85d6fbeb0
size 693023

View File

@ -1,3 +1,27 @@
-------------------------------------------------------------------
Mon Jan 16 19:59:42 UTC 2012 - tabraham@novell.com
- Update to version 1.32
+ sg_sanitize: new utility for command added in sb3r27
+ sg_sat_identify: add '--ident' to output WWN
+ sg_ses: major rework of descriptor output
+ add --index, --descriptor, --join, --clear, --get, and --set
options
+ sg_raw: exit status corrections
+ sg_decode_sense: add --nospace and --hex options
+ sg_logs: fix bug with large --maxlen
+ zero response length when resid implies it is invalid
+ add scope field to lb provisioning lpage (sb3r27)
+ sg_inq: sync version descriptors with spc4r31
+ sb_lib_data: sync asc/ascq codes with spc4r31
+ sg_vpd: add LBPRZ field in LP provisioning VPD page
+ sg_format: allow format of pdt 7 (some MO drives)
+ sg_cmd_basic: sg_cmds_process_resp() handle status good
with a sense key other than no_sense (e.g. completed)
+ add README.iscsi
- Updated rescan-scsi-bus.sh to v1.56
------------------------------------------------------------------- -------------------------------------------------------------------
Thu Mar 10 08:47:43 UTC 2011 - coolo@novell.com Thu Mar 10 08:47:43 UTC 2011 - coolo@novell.com

View File

@ -1,7 +1,7 @@
# #
# spec file for package sg3_utils (Version 1.29) # spec file for package sg3_utils
# #
# Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany. # Copyright (c) 2012 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
@ -16,21 +16,21 @@
# #
Url: http://sg.torque.net/sg/sg3_utils.html Url: http://sg.danny.cz/sg/sg3_utils.html
Name: sg3_utils Name: sg3_utils
%define sgver 1.31 %define sgver 1.32
License: BSD3c(or similar) ; GPLv2 ; GPLv2+ License: BSD-3-Clause ; GPL-2.0 ; GPL-2.0+
Group: Hardware/Other Group: Hardware/Other
Provides: sg_utils Provides: sg_utils
Provides: scsi Provides: scsi
Obsoletes: scsi <= 1.7_2.38_1.25_0.19_1.02_0.93 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.31 Version: 1.32
Release: 1 Release: 1
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.danny.cz/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
BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRoot: %{_tmppath}/%{name}-%{version}-build
@ -43,7 +43,7 @@ ATAPI cd/dvd drives and SATA disks that connect via a translation layer
or a bridge device are examples of devices that use SCSI command sets. or a bridge device are examples of devices that use SCSI command sets.
%package devel %package devel
License: BSD3c(or similar) ; GPLv2+ License: BSD-3-Clause ; GPL-2.0+
Summary: A collection of tools that send SCSI commands to devices Summary: A collection of tools that send SCSI commands to devices
Group: Development/Libraries/C and C++ Group: Development/Libraries/C and C++
AutoReqProv: on AutoReqProv: on
@ -88,7 +88,7 @@ install -m 755 %{S:2} $RPM_BUILD_ROOT%{_bindir}
%attr(755,root,root) %{_bindir}/sg_map %attr(755,root,root) %{_bindir}/sg_map
%attr(755,root,root) %{_bindir}/sg_turs %attr(755,root,root) %{_bindir}/sg_turs
%attr(755,root,root) %{_bindir}/sg_test_rwbuf %attr(755,root,root) %{_bindir}/sg_test_rwbuf
#%attr(755,root,root) %{_bindir}/scsi_devfs_scan #%%attr(755,root,root) %%{_bindir}/scsi_devfs_scan
%attr(755,root,root) %{_bindir}/sgm_dd %attr(755,root,root) %{_bindir}/sgm_dd
%attr(755,root,root) %{_bindir}/sg_read %attr(755,root,root) %{_bindir}/sg_read
%attr(755,root,root) %{_bindir}/sg_logs %attr(755,root,root) %{_bindir}/sg_logs
@ -133,6 +133,7 @@ install -m 755 %{S:2} $RPM_BUILD_ROOT%{_bindir}
%attr(755,root,root) %{_bindir}/sg_write_same %attr(755,root,root) %{_bindir}/sg_write_same
%attr(755,root,root) %{_bindir}/sg_decode_sense %attr(755,root,root) %{_bindir}/sg_decode_sense
%attr(755,root,root) %{_bindir}/sg_referrals %attr(755,root,root) %{_bindir}/sg_referrals
%attr(755,root,root) %{_bindir}/sg_sanitize
%doc %{_mandir}/man8/sg_dd.8.gz %doc %{_mandir}/man8/sg_dd.8.gz
%doc %{_mandir}/man8/sgp_dd.8.gz %doc %{_mandir}/man8/sgp_dd.8.gz
%doc %{_mandir}/man8/sgm_dd.8.gz %doc %{_mandir}/man8/sgm_dd.8.gz
@ -145,7 +146,7 @@ install -m 755 %{S:2} $RPM_BUILD_ROOT%{_bindir}
%doc %{_mandir}/man8/sg_turs.8.gz %doc %{_mandir}/man8/sg_turs.8.gz
%doc %{_mandir}/man8/sg_inq.8.gz %doc %{_mandir}/man8/sg_inq.8.gz
%doc %{_mandir}/man8/sg_test_rwbuf.8.gz %doc %{_mandir}/man8/sg_test_rwbuf.8.gz
#%doc %{_mandir}/man8/scsi_devfs_scan.8.gz #%%doc %%{_mandir}/man8/scsi_devfs_scan.8.gz
%doc %{_mandir}/man8/sg_start.8.gz %doc %{_mandir}/man8/sg_start.8.gz
%doc %{_mandir}/man8/sg_reset.8.gz %doc %{_mandir}/man8/sg_reset.8.gz
%doc %{_mandir}/man8/sg_modes.8.gz %doc %{_mandir}/man8/sg_modes.8.gz
@ -191,6 +192,7 @@ install -m 755 %{S:2} $RPM_BUILD_ROOT%{_bindir}
%doc %{_mandir}/man8/sg_write_same.8.gz %doc %{_mandir}/man8/sg_write_same.8.gz
%doc %{_mandir}/man8/sg_decode_sense.8.gz %doc %{_mandir}/man8/sg_decode_sense.8.gz
%doc %{_mandir}/man8/sg_referrals.8.gz %doc %{_mandir}/man8/sg_referrals.8.gz
%doc %{_mandir}/man8/sg_sanitize.8.gz
%attr(755,root,root) %{_libdir}/libsgutils2.so.* %attr(755,root,root) %{_libdir}/libsgutils2.so.*
%files devel %files devel