Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/bin
File: rescan-scsi-bus.sh
#!/bin/bash
[0] Fix | Delete
# Script to rescan SCSI bus, using the scsi add-single-device mechanism.
[1] Fix | Delete
# (c) 1998--2010 Kurt Garloff <kurt@garloff.de>, GNU GPL v2 or v3
[2] Fix | Delete
# (c) 2006--2018 Hannes Reinecke, GNU GPL v2 or later
[3] Fix | Delete
# $Id: rescan-scsi-bus.sh,v 1.57 2012/03/31 14:08:48 garloff Exp $
[4] Fix | Delete
[5] Fix | Delete
VERSION="20180615"
[6] Fix | Delete
SCAN_WILD_CARD=4294967295
[7] Fix | Delete
[8] Fix | Delete
setcolor ()
[9] Fix | Delete
{
[10] Fix | Delete
red="\e[0;31m"
[11] Fix | Delete
green="\e[0;32m"
[12] Fix | Delete
yellow="\e[0;33m"
[13] Fix | Delete
bold="\e[0;1m"
[14] Fix | Delete
norm="\e[0;0m"
[15] Fix | Delete
}
[16] Fix | Delete
[17] Fix | Delete
unsetcolor ()
[18] Fix | Delete
{
[19] Fix | Delete
red=""; green=""
[20] Fix | Delete
yellow=""; norm=""
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
echo_debug()
[24] Fix | Delete
{
[25] Fix | Delete
if [ $debug -eq 1 ] ; then
[26] Fix | Delete
echo "$1"
[27] Fix | Delete
fi
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
# Output some text and return cursor to previous position
[31] Fix | Delete
# (only works for simple strings)
[32] Fix | Delete
# Stores length of string in LN and returns it
[33] Fix | Delete
print_and_scroll_back ()
[34] Fix | Delete
{
[35] Fix | Delete
STRG="$1"
[36] Fix | Delete
LN=${#STRG}
[37] Fix | Delete
BK=""
[38] Fix | Delete
declare -i cntr=0
[39] Fix | Delete
while test $cntr -lt $LN; do BK="$BK\e[D"; let cntr+=1; done
[40] Fix | Delete
echo -en "$STRG$BK"
[41] Fix | Delete
return $LN
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
# Overwrite a text of length $LN with whitespace
[45] Fix | Delete
white_out ()
[46] Fix | Delete
{
[47] Fix | Delete
BK=""; WH=""
[48] Fix | Delete
declare -i cntr=0
[49] Fix | Delete
while test $cntr -lt $LN; do BK="$BK\e[D"; WH="$WH "; let cntr+=1; done
[50] Fix | Delete
echo -en "$WH$BK"
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
# Return hosts. sysfs must be mounted
[54] Fix | Delete
findhosts_26 ()
[55] Fix | Delete
{
[56] Fix | Delete
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`
[57] Fix | Delete
scsi_host_data=`echo "$hosts" | sed -e 's~^~/sys/class/scsi_host/host~'`
[58] Fix | Delete
for hostdir in $scsi_host_data; do
[59] Fix | Delete
hostno=${hostdir#/sys/class/scsi_host/host}
[60] Fix | Delete
if [ -f $hostdir/isp_name ] ; then
[61] Fix | Delete
hostname="qla2xxx"
[62] Fix | Delete
elif [ -f $hostdir/lpfc_drvr_version ] ; then
[63] Fix | Delete
hostname="lpfc"
[64] Fix | Delete
else
[65] Fix | Delete
hostname=`cat $hostdir/proc_name`
[66] Fix | Delete
fi
[67] Fix | Delete
#hosts="$hosts $hostno"
[68] Fix | Delete
echo_debug "Host adapter $hostno ($hostname) found."
[69] Fix | Delete
done
[70] Fix | Delete
if [ -z "$hosts" ] ; then
[71] Fix | Delete
echo "No SCSI host adapters found in sysfs"
[72] Fix | Delete
exit 1;
[73] Fix | Delete
fi
[74] Fix | Delete
# Not necessary just use double quotes around variable to preserve new lines
[75] Fix | Delete
#hosts=`echo $hosts | tr ' ' '\n'`
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
# Return hosts. /proc/scsi/HOSTADAPTER/? must exist
[79] Fix | Delete
findhosts ()
[80] Fix | Delete
{
[81] Fix | Delete
hosts=
[82] Fix | Delete
for driverdir in /proc/scsi/*; do
[83] Fix | Delete
driver=${driverdir#/proc/scsi/}
[84] Fix | Delete
if test $driver = scsi -o $driver = sg -o $driver = dummy -o $driver = device_info; then continue; fi
[85] Fix | Delete
for hostdir in $driverdir/*; do
[86] Fix | Delete
name=${hostdir#/proc/scsi/*/}
[87] Fix | Delete
if test $name = add_map -o $name = map -o $name = mod_parm; then continue; fi
[88] Fix | Delete
num=$name
[89] Fix | Delete
driverinfo=$driver
[90] Fix | Delete
if test -r "$hostdir/status"; then
[91] Fix | Delete
num=$(printf '%d\n' "$(sed -n 's/SCSI host number://p' "$hostdir/status")")
[92] Fix | Delete
driverinfo="$driver:$name"
[93] Fix | Delete
fi
[94] Fix | Delete
hosts="$hosts $num"
[95] Fix | Delete
echo "Host adapter $num ($driverinfo) found."
[96] Fix | Delete
done
[97] Fix | Delete
done
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
printtype ()
[101] Fix | Delete
{
[102] Fix | Delete
local type=$1
[103] Fix | Delete
[104] Fix | Delete
case "$type" in
[105] Fix | Delete
0) echo "Direct-Access" ;;
[106] Fix | Delete
1) echo "Sequential-Access" ;;
[107] Fix | Delete
2) echo "Printer" ;;
[108] Fix | Delete
3) echo "Processor" ;;
[109] Fix | Delete
4) echo "WORM" ;;
[110] Fix | Delete
5) echo "CD-ROM" ;;
[111] Fix | Delete
6) echo "Scanner" ;;
[112] Fix | Delete
7) echo "Optical-Device" ;;
[113] Fix | Delete
8) echo "Medium-Changer" ;;
[114] Fix | Delete
9) echo "Communications" ;;
[115] Fix | Delete
10) echo "Unknown" ;;
[116] Fix | Delete
11) echo "Unknown" ;;
[117] Fix | Delete
12) echo "RAID" ;;
[118] Fix | Delete
13) echo "Enclosure" ;;
[119] Fix | Delete
14) echo "Direct-Access-RBC" ;;
[120] Fix | Delete
*) echo "Unknown" ;;
[121] Fix | Delete
esac
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
print02i()
[125] Fix | Delete
{
[126] Fix | Delete
if [ "$1" = "*" ] ; then
[127] Fix | Delete
echo "00"
[128] Fix | Delete
else
[129] Fix | Delete
printf "%02i" "$1"
[130] Fix | Delete
fi
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
# Get /proc/scsi/scsi info for device $host:$channel:$id:$lun
[134] Fix | Delete
# Optional parameter: Number of lines after first (default = 2),
[135] Fix | Delete
# result in SCSISTR, return code 1 means empty.
[136] Fix | Delete
procscsiscsi ()
[137] Fix | Delete
{
[138] Fix | Delete
if test -z "$1"; then LN=2; else LN=$1; fi
[139] Fix | Delete
CHANNEL=`print02i "$channel"`
[140] Fix | Delete
ID=`print02i "$id"`
[141] Fix | Delete
LUN=`print02i "$lun"`
[142] Fix | Delete
if [ -d /sys/class/scsi_device ]; then
[143] Fix | Delete
SCSIPATH="/sys/class/scsi_device/${host}:${channel}:${id}:${lun}"
[144] Fix | Delete
if [ -d "$SCSIPATH" ] ; then
[145] Fix | Delete
SCSISTR="Host: scsi${host} Channel: $CHANNEL Id: $ID Lun: $LUN"
[146] Fix | Delete
if [ "$LN" -gt 0 ] ; then
[147] Fix | Delete
IVEND=$(cat ${SCSIPATH}/device/vendor)
[148] Fix | Delete
IPROD=$(cat ${SCSIPATH}/device/model)
[149] Fix | Delete
IPREV=$(cat ${SCSIPATH}/device/rev)
[150] Fix | Delete
SCSIDEV=$(printf ' Vendor: %-08s Model: %-16s Rev: %-4s' "$IVEND" "$IPROD" "$IPREV")
[151] Fix | Delete
SCSISTR="$SCSISTR
[152] Fix | Delete
$SCSIDEV"
[153] Fix | Delete
fi
[154] Fix | Delete
if [ "$LN" -gt 1 ] ; then
[155] Fix | Delete
ILVL=$(cat ${SCSIPATH}/device/scsi_level)
[156] Fix | Delete
type=$(cat ${SCSIPATH}/device/type)
[157] Fix | Delete
ITYPE=$(printtype $type)
[158] Fix | Delete
SCSITMP=$(printf ' Type: %-17s ANSI SCSI revision: %02d' "$ITYPE" "$((ILVL - 1))")
[159] Fix | Delete
SCSISTR="$SCSISTR
[160] Fix | Delete
$SCSITMP"
[161] Fix | Delete
fi
[162] Fix | Delete
else
[163] Fix | Delete
return 1
[164] Fix | Delete
fi
[165] Fix | Delete
else
[166] Fix | Delete
grepstr="scsi$host Channel: $CHANNEL Id: $ID Lun: $LUN"
[167] Fix | Delete
SCSISTR=$(grep -A "$LN" -e "$grepstr" /proc/scsi/scsi)
[168] Fix | Delete
fi
[169] Fix | Delete
if test -z "$SCSISTR"; then return 1; else return 0; fi
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
# Find sg device with 2.6 sysfs support
[173] Fix | Delete
sgdevice26 ()
[174] Fix | Delete
{
[175] Fix | Delete
local gendev
[176] Fix | Delete
[177] Fix | Delete
gendev=/sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device/generic
[178] Fix | Delete
if test -e "$gendev"; then
[179] Fix | Delete
SGDEV=$(basename "$(readlink "$gendev")")
[180] Fix | Delete
else
[181] Fix | Delete
for SGDEV in /sys/class/scsi_generic/sg*; do
[182] Fix | Delete
DEV=`readlink $SGDEV/device`
[183] Fix | Delete
if test "${DEV##*/}" = "$host:$channel:$id:$lun"; then
[184] Fix | Delete
SGDEV=`basename $SGDEV`; return
[185] Fix | Delete
fi
[186] Fix | Delete
done
[187] Fix | Delete
SGDEV=""
[188] Fix | Delete
fi
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
# Find sg device with 2.4 report-devs extensions
[192] Fix | Delete
sgdevice24 ()
[193] Fix | Delete
{
[194] Fix | Delete
if procscsiscsi 3; then
[195] Fix | Delete
SGDEV=`echo "$SCSISTR" | grep 'Attached drivers:' | sed 's/^ *Attached drivers: \(sg[0-9]*\).*/\1/'`
[196] Fix | Delete
fi
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
# Find sg device that belongs to SCSI device $host $channel $id $lun
[200] Fix | Delete
# and return in SGDEV
[201] Fix | Delete
sgdevice ()
[202] Fix | Delete
{
[203] Fix | Delete
SGDEV=
[204] Fix | Delete
if test -d /sys/class/scsi_device; then
[205] Fix | Delete
sgdevice26
[206] Fix | Delete
else
[207] Fix | Delete
DRV=`grep 'Attached drivers:' /proc/scsi/scsi 2>/dev/null`
[208] Fix | Delete
repdevstat=$((1-$?))
[209] Fix | Delete
if [ $repdevstat = 0 ]; then
[210] Fix | Delete
echo "scsi report-devs 1" >/proc/scsi/scsi
[211] Fix | Delete
DRV=`grep 'Attached drivers:' /proc/scsi/scsi 2>/dev/null`
[212] Fix | Delete
if [ $? = 1 ]; then return; fi
[213] Fix | Delete
fi
[214] Fix | Delete
if ! echo "$DRV" | grep -q 'drivers: sg'; then
[215] Fix | Delete
modprobe sg
[216] Fix | Delete
fi
[217] Fix | Delete
sgdevice24
[218] Fix | Delete
if [ $repdevstat = 0 ]; then
[219] Fix | Delete
echo "scsi report-devs 0" >/proc/scsi/scsi
[220] Fix | Delete
fi
[221] Fix | Delete
fi
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
# Whether or not the RMB (removable) bit has been set in the INQUIRY response.
[225] Fix | Delete
# Uses ${host}, ${channel}, ${id} and ${lun}. Assumes that sg_device() has
[226] Fix | Delete
# already been called. How to test this function: copy/paste this function
[227] Fix | Delete
# in a shell and run
[228] Fix | Delete
# (cd /sys/class/scsi_device && for d in *; do set ${d//:/ }; echo -n "$d $(</sys/class/scsi_device/${d}/device/block/*/removable) <> "; SGDEV=bsg/$d host=$1 channel=$2 id=$3 lun=$4 is_removable; done)
[229] Fix | Delete
is_removable ()
[230] Fix | Delete
{
[231] Fix | Delete
local b p
[232] Fix | Delete
[233] Fix | Delete
p=/sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device/inquiry
[234] Fix | Delete
# Extract the second byte of the INQUIRY response and check bit 7 (mask 0x80).
[235] Fix | Delete
b=$(od -tx1 -j1 -N1 "$p" 2>/dev/null |
[236] Fix | Delete
{ read -r _ byte rest; echo -n "$byte"; })
[237] Fix | Delete
if [ -n "$b" ]; then
[238] Fix | Delete
echo $(((0x$b & 0x80) != 0))
[239] Fix | Delete
else
[240] Fix | Delete
sg_inq /dev/$SGDEV 2>/dev/null | sed -n 's/^.*RMB=\([0-9]*\).*$/\1/p'
[241] Fix | Delete
fi
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
# Test if SCSI device is still responding to commands
[245] Fix | Delete
# Return values:
[246] Fix | Delete
# 0 device is present
[247] Fix | Delete
# 1 device has changed
[248] Fix | Delete
# 2 device has been removed
[249] Fix | Delete
testonline ()
[250] Fix | Delete
{
[251] Fix | Delete
local ctr RC RMB
[252] Fix | Delete
[253] Fix | Delete
: testonline
[254] Fix | Delete
ctr=0
[255] Fix | Delete
RC=0
[256] Fix | Delete
# Set default values
[257] Fix | Delete
IPTYPE=31
[258] Fix | Delete
IPQUAL=3
[259] Fix | Delete
if test ! -x /usr/bin/sg_turs; then return 0; fi
[260] Fix | Delete
sgdevice
[261] Fix | Delete
if test -z "$SGDEV"; then return 0; fi
[262] Fix | Delete
sg_turs /dev/$SGDEV >/dev/null 2>&1
[263] Fix | Delete
RC=$?
[264] Fix | Delete
[265] Fix | Delete
# Handle in progress of becoming ready and unit attention
[266] Fix | Delete
while test $RC = 2 -o $RC = 6 && test $ctr -le 30; do
[267] Fix | Delete
if test $RC = 2 -a "$RMB" != "1"; then echo -n "."; let LN+=1; sleep 1
[268] Fix | Delete
else sleep 0.02; fi
[269] Fix | Delete
let ctr+=1
[270] Fix | Delete
sg_turs /dev/$SGDEV >/dev/null 2>&1
[271] Fix | Delete
RC=$?
[272] Fix | Delete
# Check for removable device; TEST UNIT READY obviously will
[273] Fix | Delete
# fail for a removable device with no medium
[274] Fix | Delete
RMB=$(is_removable)
[275] Fix | Delete
print_and_scroll_back "$host:$channel:$id:$lun $SGDEV ($RMB) "
[276] Fix | Delete
test $RC = 2 -a "$RMB" = "1" && break
[277] Fix | Delete
done
[278] Fix | Delete
if test $ctr != 0; then white_out; fi
[279] Fix | Delete
# echo -e "\e[A\e[A\e[A${yellow}Test existence of $SGDEV = $RC ${norm} \n\n\n"
[280] Fix | Delete
if test $RC = 1; then return $RC; fi
[281] Fix | Delete
# Reset RC (might be !=0 for passive paths)
[282] Fix | Delete
RC=0
[283] Fix | Delete
# OK, device online, compare INQUIRY string
[284] Fix | Delete
INQ=`sg_inq $sg_len_arg /dev/$SGDEV 2>/dev/null`
[285] Fix | Delete
if [ -z "$INQ" ] ; then
[286] Fix | Delete
echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}INQUIRY failed${norm} \n\n\n"
[287] Fix | Delete
return 2
[288] Fix | Delete
fi
[289] Fix | Delete
IVEND=`echo "$INQ" | grep 'Vendor identification:' | sed 's/^[^:]*: \(.*\)$/\1/'`
[290] Fix | Delete
IPROD=`echo "$INQ" | grep 'Product identification:' | sed 's/^[^:]*: \(.*\)$/\1/'`
[291] Fix | Delete
IPREV=`echo "$INQ" | grep 'Product revision level:' | sed 's/^[^:]*: \(.*\)$/\1/'`
[292] Fix | Delete
STR=`printf " Vendor: %-08s Model: %-16s Rev: %-4s" "$IVEND" "$IPROD" "$IPREV"`
[293] Fix | Delete
IPTYPE=`echo "$INQ" | sed -n 's/.* Device_type=\([0-9]*\) .*/\1/p'`
[294] Fix | Delete
IPQUAL=`echo "$INQ" | sed -n 's/ *PQual=\([0-9]*\) Device.*/\1/p'`
[295] Fix | Delete
if [ "$IPQUAL" != 0 ] ; then
[296] Fix | Delete
[ -z "$IPQUAL" ] && IPQUAL=3
[297] Fix | Delete
[ -z "$IPTYPE" ] && IPTYPE=31
[298] Fix | Delete
echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}LU not available (PQual $IPQUAL)${norm} \n\n\n"
[299] Fix | Delete
return 2
[300] Fix | Delete
fi
[301] Fix | Delete
[302] Fix | Delete
TYPE=$(printtype $IPTYPE)
[303] Fix | Delete
if ! procscsiscsi ; then
[304] Fix | Delete
echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV removed.\n\n\n"
[305] Fix | Delete
return 2
[306] Fix | Delete
fi
[307] Fix | Delete
TMPSTR=`echo "$SCSISTR" | grep 'Vendor:'`
[308] Fix | Delete
if test $ignore_rev -eq 0 ; then
[309] Fix | Delete
if [ "$TMPSTR" != "$STR" ]; then
[310] Fix | Delete
echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nfrom:${SCSISTR#* } \nto: $STR ${norm} \n\n\n"
[311] Fix | Delete
return 1
[312] Fix | Delete
fi
[313] Fix | Delete
else
[314] Fix | Delete
# Ignore disk revision change
[315] Fix | Delete
local old_str_no_rev
[316] Fix | Delete
old_str_no_rev=`echo "$TMPSTR" | sed -e 's/.\{4\}$//'`
[317] Fix | Delete
local new_str_no_rev
[318] Fix | Delete
new_str_no_rev=`echo "$STR" | sed -e 's/.\{4\}$//'`
[319] Fix | Delete
if [ "$old_str_no_rev" != "$new_str_no_rev" ]; then
[320] Fix | Delete
echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nfrom:${SCSISTR#* } \nto: $STR ${norm} \n\n\n"
[321] Fix | Delete
return 1
[322] Fix | Delete
fi
[323] Fix | Delete
fi
[324] Fix | Delete
TMPSTR=`echo "$SCSISTR" | sed -n 's/.*Type: *\(.*\) *ANSI.*/\1/p' | sed 's/ *$//g'`
[325] Fix | Delete
if [ "$TMPSTR" != "$TYPE" ] ; then
[326] Fix | Delete
echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nfrom:${TMPSTR} \nto: $TYPE ${norm} \n\n\n"
[327] Fix | Delete
return 1
[328] Fix | Delete
fi
[329] Fix | Delete
return $RC
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
# Test if SCSI device $host $channel $id $lun exists
[333] Fix | Delete
# Outputs description from /proc/scsi/scsi (unless arg passed)
[334] Fix | Delete
# Returns SCSISTR (empty if no dev)
[335] Fix | Delete
testexist ()
[336] Fix | Delete
{
[337] Fix | Delete
: testexist
[338] Fix | Delete
SCSISTR=
[339] Fix | Delete
if procscsiscsi && test -z "$1"; then
[340] Fix | Delete
echo "$SCSISTR" | head -n1
[341] Fix | Delete
echo "$SCSISTR" | tail -n2 | pr -o4 -l1
[342] Fix | Delete
fi
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
# Returns the list of existing channels per host
[346] Fix | Delete
chanlist ()
[347] Fix | Delete
{
[348] Fix | Delete
local hcil
[349] Fix | Delete
local cil
[350] Fix | Delete
local chan
[351] Fix | Delete
local tmpchan
[352] Fix | Delete
[353] Fix | Delete
for dev in /sys/class/scsi_device/${host}:* ; do
[354] Fix | Delete
[ -d $dev ] || continue;
[355] Fix | Delete
hcil=${dev##*/}
[356] Fix | Delete
cil=${hcil#*:}
[357] Fix | Delete
chan=${cil%%:*}
[358] Fix | Delete
for tmpchan in $channelsearch ; do
[359] Fix | Delete
if test "$chan" -eq $tmpchan ; then
[360] Fix | Delete
chan=
[361] Fix | Delete
fi
[362] Fix | Delete
done
[363] Fix | Delete
if test -n "$chan" ; then
[364] Fix | Delete
channelsearch="$channelsearch $chan"
[365] Fix | Delete
fi
[366] Fix | Delete
done
[367] Fix | Delete
if test -z "$channelsearch"; then channelsearch="0"; fi
[368] Fix | Delete
}
[369] Fix | Delete
[370] Fix | Delete
# Returns the list of existing targets per host
[371] Fix | Delete
idlist ()
[372] Fix | Delete
{
[373] Fix | Delete
local tmpid
[374] Fix | Delete
local newid
[375] Fix | Delete
local oldid
[376] Fix | Delete
[377] Fix | Delete
oldlist=$(ls /sys/class/scsi_device/ | sed -n "s/${host}:${channel}:\([0-9]*:[0-9]*\)/\1/p" | uniq)
[378] Fix | Delete
# Rescan LUN 0 to check if we found new targets
[379] Fix | Delete
echo "${channel} - 0" > /sys/class/scsi_host/host${host}/scan
[380] Fix | Delete
newlist=$(ls /sys/class/scsi_device/ | sed -n "s/${host}:${channel}:\([0-9]*:[0-9]*\)/\1/p" | uniq)
[381] Fix | Delete
for newid in $newlist ; do
[382] Fix | Delete
oldid=$newid
[383] Fix | Delete
for tmpid in $oldlist ; do
[384] Fix | Delete
if test $newid = $tmpid ; then
[385] Fix | Delete
oldid=
[386] Fix | Delete
break
[387] Fix | Delete
fi
[388] Fix | Delete
done
[389] Fix | Delete
if test -n "$oldid" ; then
[390] Fix | Delete
id=${oldid%%:*}
[391] Fix | Delete
lun=${oldid##*:}
[392] Fix | Delete
dev=/sys/class/scsi_device/${host}:${channel}:${id}:${lun}
[393] Fix | Delete
if [ -d $dev ] ; then
[394] Fix | Delete
hcil=${dev##*/}
[395] Fix | Delete
printf "\r${green}NEW: $norm"
[396] Fix | Delete
testexist
[397] Fix | Delete
if test "$SCSISTR" ; then
[398] Fix | Delete
incrfound "$hcil"
[399] Fix | Delete
fi
[400] Fix | Delete
fi
[401] Fix | Delete
fi
[402] Fix | Delete
done
[403] Fix | Delete
idsearch=$(ls /sys/class/scsi_device/ | sed -n "s/${host}:${channel}:\([0-9]*\):[0-9]*/\1/p" | uniq)
[404] Fix | Delete
}
[405] Fix | Delete
[406] Fix | Delete
# Returns the list of existing LUNs from device $host $channel $id $lun
[407] Fix | Delete
# and returns list to stdout
[408] Fix | Delete
getluns()
[409] Fix | Delete
{
[410] Fix | Delete
sgdevice
[411] Fix | Delete
if test -z "$SGDEV"; then return 1; fi
[412] Fix | Delete
if test ! -x /usr/bin/sg_luns; then echo 0; return 1; fi
[413] Fix | Delete
LLUN=`sg_luns /dev/$SGDEV 2>/dev/null | sed -n 's/ \(.*\)/\1/p'`
[414] Fix | Delete
# Added -z $LLUN condition because $? gets the RC from sed, not sg_luns
[415] Fix | Delete
if test $? != 0 -o -z "$LLUN"; then echo 0; return 1; fi
[416] Fix | Delete
for lun in $LLUN ; do
[417] Fix | Delete
# Swap LUN number
[418] Fix | Delete
l0=0x$lun
[419] Fix | Delete
l1=$(( ($l0 >> 48) & 0xffff ))
[420] Fix | Delete
l2=$(( ($l0 >> 32) & 0xffff ))
[421] Fix | Delete
l3=$(( ($l0 >> 16) & 0xffff ))
[422] Fix | Delete
l4=$(( $l0 & 0xffff ))
[423] Fix | Delete
l0=$(( ( ( ($l4 * 0xffff) + $l3 ) * 0xffff + $l2 ) * 0xffff + $l1 ))
[424] Fix | Delete
printf "%u\n" $l0
[425] Fix | Delete
done
[426] Fix | Delete
return 0
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
# Wait for udev to settle (create device nodes etc.)
[430] Fix | Delete
udevadm_settle()
[431] Fix | Delete
{
[432] Fix | Delete
local tmo=60
[433] Fix | Delete
if test -x /sbin/udevadm; then
[434] Fix | Delete
print_and_scroll_back " Calling udevadm settle (can take a while) "
[435] Fix | Delete
# Loop for up to 60 seconds if sd devices still are settling..
[436] Fix | Delete
# This allows us to continue if udev events are stuck on multipaths in recovery mode
[437] Fix | Delete
while [ $tmo -gt 0 ] ; do
[438] Fix | Delete
if ! /sbin/udevadm settle --timeout=1 | egrep -q sd[a-z]+ ; then
[439] Fix | Delete
break;
[440] Fix | Delete
fi
[441] Fix | Delete
let tmo=$tmo-1
[442] Fix | Delete
done
[443] Fix | Delete
white_out
[444] Fix | Delete
elif test -x /sbin/udevsettle; then
[445] Fix | Delete
print_and_scroll_back " Calling udevsettle (can take a while) "
[446] Fix | Delete
/sbin/udevsettle
[447] Fix | Delete
white_out
[448] Fix | Delete
else
[449] Fix | Delete
sleep 0.02
[450] Fix | Delete
fi
[451] Fix | Delete
}
[452] Fix | Delete
[453] Fix | Delete
# Perform scan on a single lun $host $channel $id $lun
[454] Fix | Delete
dolunscan()
[455] Fix | Delete
{
[456] Fix | Delete
local remappedlun0=
[457] Fix | Delete
SCSISTR=
[458] Fix | Delete
devnr="$host $channel $id $lun"
[459] Fix | Delete
echo -e " Scanning for device $devnr ... "
[460] Fix | Delete
printf "${yellow}OLD: $norm"
[461] Fix | Delete
testexist
[462] Fix | Delete
# Device exists: Test whether it's still online
[463] Fix | Delete
# (testonline returns 2 if it's gone and 1 if it has changed)
[464] Fix | Delete
if test "$SCSISTR" ; then
[465] Fix | Delete
testonline
[466] Fix | Delete
RC=$?
[467] Fix | Delete
# Well known lun transition case. Only for Direct-Access devs (type 0)
[468] Fix | Delete
# If block directory exists && and PQUAL != 0, we unmapped lun0 and just have a well-known lun
[469] Fix | Delete
# If block directory doesn't exist && PQUAL == 0, we mapped a real lun0
[470] Fix | Delete
if test $lun -eq 0 -a $IPTYPE -eq 0 ; then
[471] Fix | Delete
if test $RC = 2 ; then
[472] Fix | Delete
if test -e /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device; then
[473] Fix | Delete
if test -d /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device/block ; then
[474] Fix | Delete
remappedlun0=2 # Transition from real lun 0 to well-known
[475] Fix | Delete
else
[476] Fix | Delete
RC=0 # Set this so the system leaves the existing well known lun alone. This is a lun 0 with no block directory
[477] Fix | Delete
fi
[478] Fix | Delete
fi
[479] Fix | Delete
elif test $RC = 0 -a $IPTYPE -eq 0; then
[480] Fix | Delete
if test -e /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device; then
[481] Fix | Delete
if test ! -d /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device/block ; then
[482] Fix | Delete
remappedlun0=1 # Transition from well-known to real lun 0
[483] Fix | Delete
fi
[484] Fix | Delete
fi
[485] Fix | Delete
fi
[486] Fix | Delete
fi
[487] Fix | Delete
fi
[488] Fix | Delete
[489] Fix | Delete
# Special case: lun 0 just got added (for reportlunscan),
[490] Fix | Delete
# so make sure we correctly treat it as new
[491] Fix | Delete
if test "$lun" = "0" -a "$1" = "1" -a -z "$remappedlun0"; then
[492] Fix | Delete
SCSISTR=""
[493] Fix | Delete
printf "\r\e[A\e[A\e[A"
[494] Fix | Delete
fi
[495] Fix | Delete
[496] Fix | Delete
: f $remove s $SCSISTR
[497] Fix | Delete
if test "$remove" -a "$SCSISTR" -o "$remappedlun0" = "1"; then
[498] Fix | Delete
if test $RC != 0 -o ! -z "$forceremove" -o -n "$remappedlun0"; then
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function