Skip to content

Commit 774ed10

Browse files
committed
move rescan-scsi-bus.sh to scripts folder; sg_inq --export corrections
git-svn-id: svn://localhost/trunk@474 6180dd3e-e324-4e3e-922d-17de1ae2f315
1 parent 2444b1a commit 774ed10

File tree

10 files changed

+181
-98
lines changed

10 files changed

+181
-98
lines changed

CREDITS

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Hannes Reinecke <hare at suse dot de>
3838
contributed sg_rdac, (and some corresponding VPD entries to
3939
sg_vpd_vendor), sg_stpg and sg_safte [20071013]
4040
sg_referrals [20100906]
41-
sg_inq --export option [20120220]
41+
sg_inq --export option [20120220+20130109]
4242
sg_xcopy+sg_copy_results [20120322]
4343

4444
Hayashi Naoyuki <titan at culzean dot org>
@@ -110,4 +110,4 @@ Trent Piepho <xyzzy at speakeasy dot org> print out some "sense key specific"
110110

111111

112112
Douglas Gilbert
113-
10th December 2012
113+
9th January 2013

ChangeLog

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ Each utility has its own version number, date of last change and
22
some description at the top of its ".c" file. All utilities in the main
33
directory have their own "man" pages. There is also a sg3_utils man page.
44

5-
Changelog for sg3_utils-1.35 [20130107] [svn: r473]
5+
Changelog for sg3_utils-1.35 [20130109] [svn: r474]
66
- sg_compare_and_write: new utility
77
- sg_inq+sg_vpd: block device characteristics VPD page:
88
add product_type, WABEREQ, WACEREQ and VBULS fields
9+
- sg_inq: more --export option changes for udev
910
- sg_verify: add --ebytchk option for sbc3r34 changes
1011
- sg_stpg: --offline option: fix 'Invalid state 0xe'
1112
- sg_ses: Door Lock element changed to Door element and
1213
abbreviation changed from 'dl' to 'do' (ses3r05)
13-
- archive/rescan-scsi-bus.sh: upgrade to version 1.56+
14+
- archive/rescan-scsi-bus.sh: upgrade to version 1.53hr
15+
- move rescan-scsi-bus.sh to scripts directory
1416
- sync to sbc3r34
15-
- sg_lib: sg_ll_verify10+16 expand BYTCHK two 2 bit field
17+
- sg_lib: sg_ll_verify10+16 expand BYTCHK to 2 bit field
1618
- sg_pt_win32, sg_scan(win32): changes for cygwin 1.7.17
1719
- clean up man page summary lines
1820

README

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,4 @@ See http://sg.danny.cz/sg/tools.html
373373

374374

375375
Douglas Gilbert
376-
21st December 2012
376+
9th January 2013

archive/README

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
In order to save source code space, the files is this directory have
2-
been removed (apart from the rescan-scsi-bus.sh script). See the
3-
sg3_utils-1.22 source tarball for the most recent version that
4-
included this source.
1+
The code and scripts in this directory may be removed at some later
2+
date. The last cleanup (i.e. purge of unused files) of this
3+
directory occurred between sg3_utils version 1.22 and 1.23 .
4+
No other code or script in this package currently uses the contents
5+
of this directory. The contents of this directory are not
6+
maintained by the author.
57

6-
The primary site for rescan-scsi-bus.sh is http://www.garloff.de/kurt/linux
7-
under the "Rescan SCSI bus" heading. Updated to rescan-scsi-bus.sh
8-
version 1.56 (2012-01-15) in sg3_utils version 1.35 .
8+
The rescan-scsi-bus.sh script was copied long ago from
9+
http://www.garloff.de/kurt/linux (under the "Rescan SCSI bus"
10+
heading) and was later placed in this directory. Since others
11+
do use the version of this script found in this package then
12+
rescan-scsi-bus.sh was updated in sg3_utils version 1.35 and
13+
was moved to the scripts directory.
914

1015
Douglas Gilbert
11-
20th December 2012
16+
9th January 2013

debian/changelog

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sg3-utils (1.35-0.1) unstable; urgency=low
22

33
* New upstream version
44

5-
-- Douglas Gilbert <[email protected]> Mon, 07 Jan 2013 13:00:00 -0500
5+
-- Douglas Gilbert <[email protected]> Wed, 09 Jan 2013 09:00:00 -0500
66

77
sg3-utils (1.34-0.1) unstable; urgency=low
88

doc/sg_inq.8

+11-6
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,17 @@ if any.
8080
see entry below for \fI\-\-vpd\fR.
8181
.TP
8282
\fB\-u\fR, \fB\-\-export\fR
83-
print out information obtained from the device identification VPD page in
84-
the form: "SCSI_IDENT_<assoc>_<type>=<ident>" to stdout. This may be useful
85-
to tools like udev in Linux. If \fIPG\fR (from \fI\-\-page=PG\fR) is given
86-
then then it overrides the default choice of the device identification VPD
87-
page. Only other value of \fIPG\fR supported is 0x80 which is the unit
88-
serial number VPD page (used by older disks).
83+
prints out information obtained from the device. The output can be
84+
modified by selecting a VPD page with \fIPG\fR (from
85+
\fI\-\-page=PG\fR). If the device identification VPD page 0x83 is
86+
given it prints out information in the form:
87+
"SCSI_IDENT_<assoc>_<type>=<ident>" to stdout. If the device serial
88+
number VPD page 0x80 is given it prints out information in the form:
89+
"SCSI_SERIAL=<ident>". Other VPD pages are not supported. If no VPD
90+
page is given it prints out information in the form:
91+
"SCSI_VENDOR=<vendor>", "SCSI_MODEL=<model>", and
92+
"SCSI_REVISION=<rev>", taken from the standard inquiry. This may be
93+
useful for tools like udev in Linux.
8994
.TP
9095
\fB\-E\fR, \fB\-x\fR, \fB\-\-extended\fR
9196
prints the extended INQUIRY VPD page [0x86].

scripts/README

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This directory contains bash shell scripts. Most of them call one or
66
more utilities from the sg3_utils package. They assume the sg3_utils
77
package utilities are on the PATH of the user.
88

9+
rescan-scsi-bus.sh is written by Kurt Garloff (see
10+
http://www.garloff.de/kurt/linux/ under the "Rescan SCSI bus" heading)
11+
with patches from Hannes Reinecke.
12+
913
scsi_logging_level is written by Andreas Herrmann <aherrman at de dot ibm
1014
dot com>. It sets the logging level of the SCSI subsystem in the Linux
1115
2.6 series kernels. See that file for more information.
@@ -18,6 +22,8 @@ Details
1822
Each script supplies more information, typically by supplying a '-h'
1923
or '--help' option. The script source often contains explanatory
2024
information. Following is a usage summary with a one line description:
25+
rescan-scsi-bus.sh [OPTIONS]
26+
- see the output of 'rescan-scsi-bus.sh --help'
2127
scsi_logging_level [OPTIONS]
2228
- set Linux SCSI subsystem logging level
2329
scsi_mandat [-h] [-L] [-q] <device>
@@ -43,4 +49,4 @@ script. Since it depends on the sdparm utility it has been moved to
4349
the sdparm package in its scripts directory.
4450

4551
Douglas Gilbert
46-
25th August 2009
52+
9th January 2013

archive/rescan-scsi-bus.sh scripts/rescan-scsi-bus.sh

+61-30
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# scsi add-single-device mechanism
44
# (c) 1998--2010 Kurt Garloff <[email protected]>, GNU GPL v2 or v3
55
# (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 $
77

88
SCAN_WILD_CARD=4294967295
99

@@ -216,6 +216,10 @@ sgdevice ()
216216
}
217217

218218
# 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
219223
testonline ()
220224
{
221225
: testonline
@@ -232,7 +236,7 @@ testonline ()
232236
print_and_scroll_back "$host:$channel:$id:$lun $SGDEV ($RMB) "
233237
fi
234238
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
236240
else usleep 20000; fi
237241
let ctr+=1
238242
sg_turs /dev/$SGDEV >/dev/null 2>&1
@@ -257,7 +261,10 @@ testonline ()
257261
fi
258262

259263
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
261268
TMPSTR=`echo "$SCSISTR" | grep 'Vendor:'`
262269
if [ "$TMPSTR" != "$STR" ]; then
263270
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 ()
313320
idlist ()
314321
{
315322
local hcil
316-
local cil
317-
local il
318323
local target
319324
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
327333
for tmpid in $idsearch ; do
328-
if test "$target" -eq $tmpid ; then
329-
target=
334+
if test $id -eq $tmpid ; then
335+
newid=
330336
break
331337
fi
332338
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
335351
fi
336352
done
337353
}
@@ -392,7 +408,7 @@ dolunscan()
392408
: f $remove s $SCSISTR
393409
if test "$remove" -a "$SCSISTR"; then
394410
# 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)
396412
testonline
397413
RC=$?
398414
if test $RC != 0 -o ! -z "$forceremove"; then
@@ -420,7 +436,7 @@ dolunscan()
420436
fi
421437
printf "\r\e[A\e[A\e[A${yellow}OLD: $norm"
422438
testexist
423-
if test -z "$SCSISTR"; then
439+
if test -z "$SCSISTR" -a $RC != 1; then
424440
printf "\r${red}DEL: $norm\r\n\n"
425441
let rmvd+=1;
426442
return 1
@@ -590,9 +606,12 @@ if test @$1 = @--help -o @$1 = @-h -o @$1 = @-?; then
590606
echo " -w scan for target device IDs 0--15 [default: 0--7]"
591607
echo " -c enables scanning of channels 0 1 [default: 0 / all detected ones]"
592608
echo " -r enables removing of devices [default: disabled]"
609+
echo " -f flush failed multipath devices [default: disabled]"
593610
echo " -i issue a FibreChannel LIP reset [default: disabled]"
594611
echo "--remove: same as -r"
612+
echo "--flush: same as -f"
595613
echo "--issue-lip: same as -i"
614+
echo "--wide: same as -w"
596615
echo "--forcerescan: Rescan existing devices"
597616
echo "--forceremove: Remove and readd every device (DANGEROUS)"
598617
echo "--nooptscan: don't stop looking for LUNs is 0 is not found"
@@ -623,16 +642,13 @@ modprobe sg >/dev/null 2>&1
623642

624643
if test -x /usr/bin/sg_inq; then
625644
sg_version=$(sg_inq -V 2>&1 | cut -d " " -f 3)
626-
sg_version=${sg_version/./}
645+
sg_version=${sg_version##0.}
627646
#echo "\"$sg_version\""
628647
if [ -z "$sg_version" -o "$sg_version" -lt 70 ] ; then
629648
sg_len_arg="-36"
630649
else
631650
sg_len_arg="--len=36"
632651
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."
636652
fi
637653

638654
# defaults
@@ -656,12 +672,14 @@ opt="$1"
656672
while test ! -z "$opt" -a -z "${opt##-*}"; do
657673
opt=${opt#-}
658674
case "$opt" in
675+
f) flush=1 ;;
659676
l) lunsearch=`seq 0 7` ;;
660677
L) lunsearch=`seq 0 $2`; shift ;;
661678
w) opt_idsearch=`seq 0 15` ;;
662679
c) opt_channelsearch="0 1" ;;
663680
r) remove=1 ;;
664681
i) lipreset=1 ;;
682+
-flush) flush=1 ;;
665683
-remove) remove=1 ;;
666684
-forcerescan) remove=1; forcerescan=1 ;;
667685
-forceremove) remove=1; forceremove=1 ;;
@@ -678,6 +696,7 @@ while test ! -z "$opt" -a -z "${opt##-*}"; do
678696
-reportlun2) scan_flags=$(($scan_flags|0x20000)) ;;
679697
-largelun) scan_flags=$(($scan_flags|0x200)) ;;
680698
-sparselun) scan_flags=$((scan_flags|0x40)) ;;
699+
-wide) opt_idsearch=`seq 0 15` ;;
681700
*) echo "Unknown option -$opt !" ;;
682701
esac
683702
shift
@@ -706,10 +725,27 @@ if test -w /sys/module/scsi_mod/parameters/default_dev_flags -a $scan_flags != 0
706725
unset OLD_SCANFLAGS
707726
fi
708727
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
711737
declare -i found=0
712738
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
713749
for host in $hosts; do
714750
echo -n "Scanning host $host "
715751
if test -e /sys/class/fc_host/host$host ; then
@@ -718,11 +754,6 @@ for host in $hosts; do
718754
echo 1 > /sys/class/fc_host/host$host/issue_lip 2> /dev/null;
719755
udevadm_settle
720756
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
726757
channelsearch=
727758
idsearch=
728759
else
@@ -746,7 +777,7 @@ done
746777
if test -n "$OLD_SCANFLAGS"; then
747778
echo $OLD_SCANFLAGS > /sys/module/scsi_mod/parameters/default_dev_flags
748779
fi
749-
echo "$found new device(s) found. "
780+
echo "$found new or changed device(s) found. "
750781
echo "$rmvd device(s) removed. "
751782

752783
# Local Variables:

sg3_utils.spec

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fi
7979
%{_libdir}/*.la
8080

8181
%changelog
82-
* Mon Jan 07 2012 - dgilbert at interlog dot com
82+
* Wed Jan 09 2012 - dgilbert at interlog dot com
8383
- track t10 changes, fix for cygwin 1.7.17
8484
* sg3_utils-1.35
8585

0 commit comments

Comments
 (0)