3
3
# scsi add-single-device mechanism
4
4
# (c) 1998--2010 Kurt Garloff <[email protected] >, GNU GPL v2 or v3
5
5
# (c) 2006--2008 Hannes Reinecke, GNU GPL v2 or later
6
- # $Id: rescan-scsi-bus.sh,v 1.56 2012/01/14 22:23:53 garloff Exp $
6
+ # $Id: rescan-scsi-bus.sh,v 1.53 2011/10/18 16:44:27 garloff Exp $
7
7
8
8
SCAN_WILD_CARD=4294967295
9
9
@@ -216,6 +216,10 @@ sgdevice ()
216
216
}
217
217
218
218
# Test if SCSI device is still responding to commands
219
+ # Return values:
220
+ # 0 device is present
221
+ # 1 device has changed
222
+ # 2 device has been removed
219
223
testonline ()
220
224
{
221
225
: testonline
@@ -232,7 +236,7 @@ testonline ()
232
236
print_and_scroll_back " $host :$channel :$id :$lun $SGDEV ($RMB ) "
233
237
fi
234
238
while test $RC = 2 -o $RC = 6 && test $ctr -le 8; do
235
- if test $RC = 2 -a " $RMB " ! = " 1" ; then echo -n " ." ; let $ LN +=1; sleep 1
239
+ if test $RC = 2 -a " $RMB " ! = " 1" ; then echo -n " ." ; let LN+=1; sleep 1
236
240
else usleep 20000; fi
237
241
let ctr+=1
238
242
sg_turs /dev/$SGDEV > /dev/null 2>&1
@@ -257,7 +261,10 @@ testonline ()
257
261
fi
258
262
259
263
TYPE=$( printtype $IPTYPE )
260
- procscsiscsi
264
+ if ! procscsiscsi ; then
265
+ echo -e " \e[A\e[A\e[A\e[A${red} $SGDEV removed.\n\n\n"
266
+ return 2
267
+ fi
261
268
TMPSTR=` echo " $SCSISTR " | grep ' Vendor:' `
262
269
if [ " $TMPSTR " != " $STR " ]; then
263
270
echo -e " \e[A\e[A\e[A\e[A${red} $SGDEV changed: ${bold} \nfrom:${SCSISTR#* } \nto: $STR ${norm} \n\n\n"
@@ -313,25 +320,34 @@ chanlist ()
313
320
idlist ()
314
321
{
315
322
local hcil
316
- local cil
317
- local il
318
323
local target
319
324
local tmpid
320
-
321
- for dev in /sys/class/scsi_device/${host} :${channel} :* ; do
322
- [ -d $dev ] || continue ;
323
- hcil=${dev##*/ }
324
- cil=${hcil#*: }
325
- il=${cil#*: }
326
- target=${il%%:* }
325
+ local newid
326
+
327
+ idsearch=$( ls /sys/class/scsi_device/ | sed -n " s/${host} :${channel} :\([0-9]*\):[0-9]*/\1/p" | uniq)
328
+ echo " ${channel} - -" > /sys/class/scsi_host/host${host} /scan
329
+ # Rescan to check if we found new targets
330
+ newsearch=$( ls /sys/class/scsi_device/ | sed -n " s/${host} :${channel} :\([0-9]*\):[0-9]*/\1/p" | uniq)
331
+ for id in $newsearch ; do
332
+ newid=$id
327
333
for tmpid in $idsearch ; do
328
- if test " $target " -eq $tmpid ; then
329
- target =
334
+ if test $id -eq $tmpid ; then
335
+ newid =
330
336
break
331
337
fi
332
338
done
333
- if test -n " $target " ; then
334
- idsearch=" $idsearch $target "
339
+ if test -n " $newid " ; then
340
+ id=$newid
341
+ for dev in /sys/class/scsi_device/${host} :${channel} :${newid} :* ; do
342
+ [ -d $dev ] || continue ;
343
+ hcil=${dev##*/ }
344
+ lun=${hcil##*: }
345
+ printf " \r${green} NEW: $norm "
346
+ testexist
347
+ if test " $SCSISTR " ; then
348
+ let found+=1
349
+ fi
350
+ done
335
351
fi
336
352
done
337
353
}
@@ -392,7 +408,7 @@ dolunscan()
392
408
: f $remove s $SCSISTR
393
409
if test " $remove " -a " $SCSISTR " ; then
394
410
# Device exists: Test whether it's still online
395
- # (testonline returns 1 if it's gone or has changed)
411
+ # (testonline returns 2 if it's gone and 1 if it has changed)
396
412
testonline
397
413
RC=$?
398
414
if test $RC ! = 0 -o ! -z " $forceremove " ; then
@@ -420,7 +436,7 @@ dolunscan()
420
436
fi
421
437
printf " \r\e[A\e[A\e[A${yellow} OLD: $norm "
422
438
testexist
423
- if test -z " $SCSISTR " ; then
439
+ if test -z " $SCSISTR " -a $RC ! = 1 ; then
424
440
printf " \r${red} DEL: $norm \r\n\n"
425
441
let rmvd+=1;
426
442
return 1
@@ -590,9 +606,12 @@ if test @$1 = @--help -o @$1 = @-h -o @$1 = @-?; then
590
606
echo " -w scan for target device IDs 0--15 [default: 0--7]"
591
607
echo " -c enables scanning of channels 0 1 [default: 0 / all detected ones]"
592
608
echo " -r enables removing of devices [default: disabled]"
609
+ echo " -f flush failed multipath devices [default: disabled]"
593
610
echo " -i issue a FibreChannel LIP reset [default: disabled]"
594
611
echo " --remove: same as -r"
612
+ echo " --flush: same as -f"
595
613
echo " --issue-lip: same as -i"
614
+ echo " --wide: same as -w"
596
615
echo " --forcerescan: Rescan existing devices"
597
616
echo " --forceremove: Remove and readd every device (DANGEROUS)"
598
617
echo " --nooptscan: don't stop looking for LUNs is 0 is not found"
@@ -623,16 +642,13 @@ modprobe sg >/dev/null 2>&1
623
642
624
643
if test -x /usr/bin/sg_inq; then
625
644
sg_version=$( sg_inq -V 2>&1 | cut -d " " -f 3)
626
- sg_version=${sg_version/ . / }
645
+ sg_version=${sg_version## 0. }
627
646
# echo "\"$sg_version\""
628
647
if [ -z " $sg_version " -o " $sg_version " -lt 70 ] ; then
629
648
sg_len_arg=" -36"
630
649
else
631
650
sg_len_arg=" --len=36"
632
651
fi
633
- else
634
- echo " WARN: /usr/bin/sg_inq not present -- please install sg3_utils"
635
- echo " or rescan-scsi-bus.sh might not fully work."
636
652
fi
637
653
638
654
# defaults
@@ -656,12 +672,14 @@ opt="$1"
656
672
while test ! -z " $opt " -a -z " ${opt## -* } " ; do
657
673
opt=${opt# -}
658
674
case " $opt " in
675
+ f) flush=1 ;;
659
676
l) lunsearch=` seq 0 7` ;;
660
677
L) lunsearch=` seq 0 $2 ` ; shift ;;
661
678
w) opt_idsearch=` seq 0 15` ;;
662
679
c) opt_channelsearch=" 0 1" ;;
663
680
r) remove=1 ;;
664
681
i) lipreset=1 ;;
682
+ -flush) flush=1 ;;
665
683
-remove) remove=1 ;;
666
684
-forcerescan) remove=1; forcerescan=1 ;;
667
685
-forceremove) remove=1; forceremove=1 ;;
@@ -678,6 +696,7 @@ while test ! -z "$opt" -a -z "${opt##-*}"; do
678
696
-reportlun2) scan_flags=$(( $scan_flags | 0x20000 )) ;;
679
697
-largelun) scan_flags=$(( $scan_flags | 0x200 )) ;;
680
698
-sparselun) scan_flags=$(( scan_flags| 0x40 )) ;;
699
+ -wide) opt_idsearch=` seq 0 15` ;;
681
700
* ) echo " Unknown option -$opt !" ;;
682
701
esac
683
702
shift
@@ -706,10 +725,27 @@ if test -w /sys/module/scsi_mod/parameters/default_dev_flags -a $scan_flags != 0
706
725
unset OLD_SCANFLAGS
707
726
fi
708
727
fi
709
- echo " Scanning SCSI subsystem for new devices"
710
- test -z " $remove " || echo " and remove devices that have disappeared"
728
+ DMSETUP=$( which dmsetup)
729
+ [ -z " $DMSETUP " ] && flush=
730
+ MULTIPATH=$( which multipath)
731
+ [ -z " $MULTIPATH " ] && flush=
732
+
733
+ echo -n " Scanning SCSI subsystem for new devices"
734
+ test -z " $flush " || echo -n " , flush failed multipath devices,"
735
+ test -z " $remove " || echo -n " and remove devices that have disappeared"
736
+ echo
711
737
declare -i found=0
712
738
declare -i rmvd=0
739
+
740
+ if [ -n " $flush " -a -x $MULTIPATH ] ; then
741
+ for mpath in $( $DMSETUP ls --target=multipath | cut -f 1) ; do
742
+ num=$( $DMSETUP status $mpath | awk ' BEGIN{RS=" ";active=0}/[0-9]+:[0-9]+/{dev=1}/A/{if (dev == 1) active++; dev=0} END{ print active }' )
743
+ if [ $num -eq 0 ] ; then
744
+ $DMSETUP message $mpath 0 fail_if_no_path
745
+ $MULTIPATH -f $mpath
746
+ fi
747
+ done
748
+ fi
713
749
for host in $hosts ; do
714
750
echo -n " Scanning host $host "
715
751
if test -e /sys/class/fc_host/host$host ; then
@@ -718,11 +754,6 @@ for host in $hosts; do
718
754
echo 1 > /sys/class/fc_host/host$host /issue_lip 2> /dev/null;
719
755
udevadm_settle
720
756
fi
721
- # We used to always trigger a rescan for FC to update channels and targets
722
- # Commented out -- as discussed with Hannes we should rely
723
- # on the main loop doing the scan, no need to do it here.
724
- # echo "- - -" > /sys/class/scsi_host/host$host/scan 2> /dev/null;
725
- # udevadm_settle
726
757
channelsearch=
727
758
idsearch=
728
759
else
746
777
if test -n " $OLD_SCANFLAGS " ; then
747
778
echo $OLD_SCANFLAGS > /sys/module/scsi_mod/parameters/default_dev_flags
748
779
fi
749
- echo " $found new device(s) found. "
780
+ echo " $found new or changed device(s) found. "
750
781
echo " $rmvd device(s) removed. "
751
782
752
783
# Local Variables:
0 commit comments