From 463fd7e3414eebfaeb541722bea244f4eec32a74 Mon Sep 17 00:00:00 2001 From: Douglas Gilbert Date: Fri, 30 Sep 2022 08:58:39 +0000 Subject: rescan-scsi-bus: speed large multipath scans Speed multipath scans with many LUNs by caching multipath LUN info in temporary file, see: https://github.com/doug-gilbert/sg3_utils/issues/22 Fix small bug in last commit, see: https://github.com/doug-gilbert/sg3_utils/issues/24 git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@973 6180dd3e-e324-4e3e-922d-17de1ae2f315 --- ChangeLog | 5 +++- doc/rescan-scsi-bus.sh.8 | 2 +- scripts/rescan-scsi-bus.sh | 60 ++++++++++++++++++++++++++++++++-------------- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a9d3b40..f4ba2b99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,7 +2,7 @@ Each utility has its own version number, date of last change and some description at the top of its ".c" file. All utilities in the main directory have their own "man" pages. There is also a sg3_utils man page. -Changelog for pre-release sg3_utils-1.48 [20220926] [svn: r972] +Changelog for pre-release sg3_utils-1.48 [20220930] [svn: r973] - some utilities: add experimental --json[=JO] option - sg_z_act_query: new utility for sending either a Zone activate or Zone query command @@ -29,6 +29,9 @@ Changelog for pre-release sg3_utils-1.48 [20220926] [svn: r972] - https://github.com/doug-gilbert/sg3_utils/pull/21 - speed testonline() when peripheral_qualifier != 0 see https://github.com/doug-gilbert/sg3_utils/issues/24 + - speed multipath scans with many LUNs, cache multipath + LUN info in temporary file, see + https://github.com/doug-gilbert/sg3_utils/issues/22 - sg_rep_zones: add Report zone starting LBA granularity field in REPORT ZONES response [zbc2r12] - add --brief option, show part of header and last diff --git a/doc/rescan-scsi-bus.sh.8 b/doc/rescan-scsi-bus.sh.8 index 96f86c33..51aa00aa 100644 --- a/doc/rescan-scsi-bus.sh.8 +++ b/doc/rescan-scsi-bus.sh.8 @@ -1,4 +1,4 @@ -.TH RESCAN\-SCSI\-BUS.SH "1" "August 2022" "rescan\-scsi\-bus.sh" "User Commands" +.TH RESCAN\-SCSI\-BUS.SH "1" "September 2022" "rescan\-scsi\-bus.sh" "User Commands" .SH NAME rescan-scsi-bus.sh \- script to add and remove SCSI devices without rebooting .SH SYNOPSIS diff --git a/scripts/rescan-scsi-bus.sh b/scripts/rescan-scsi-bus.sh index f0105cf8..1ebc0e91 100755 --- a/scripts/rescan-scsi-bus.sh +++ b/scripts/rescan-scsi-bus.sh @@ -4,9 +4,11 @@ # (c) 2006--2022 Hannes Reinecke, GNU GPL v2 or later # $Id: rescan-scsi-bus.sh,v 1.57 2012/03/31 14:08:48 garloff Exp $ -VERSION="20220926" +VERSION="20220930" SCAN_WILD_CARD=4294967295 +TMPLUNINFOFILE="/tmp/rescan-scsi-mpath-info.txt" + setcolor () { red="\e[0;31m" @@ -276,7 +278,7 @@ testonline () # Handle in progress of becoming ready and unit attention while [ $RC = 2 -o $RC = 6 ] && [ $ctr -lt $timeout ] ; do - if [ $RC = 2 ] && [ "$RMB" != "1" ] && [ sg_inq /dev/$SGDEV | grep -q -i "PQual=0" ] ; then + if [ $RC = 2 ] && [ "$RMB" != "1" ] && sg_inq /dev/$SGDEV | grep -q -i "PQual=0" ; then echo -n "." let LN+=1 sleep 1 @@ -777,6 +779,33 @@ searchexisting() done } +getallmultipathinfo() +{ + local mp= + local uuid= + local dmtmp= + local maj_min= + local tmpfile= + + truncate -s 0 $TMPLUNINFOFILE + for mp in $($DMSETUP ls --target=multipath | cut -f 1) ; do + [ "$mp" = "No" ] && break; + maj_min=$($DMSETUP status "$mp" | cut -d " " -f14) + if [ ! -L /dev/mapper/${mp} ]; then + echo "softlink /dev/mapper/${mp} not available." + continue + fi + local ret=$(readlink /dev/mapper/$mp 2>/dev/null) + if [[ $? -ne 0 || -z "$ret" ]]; then + echo "readlink /dev/mapper/$mp failed. check multipath status." + continue + fi + dmtmp=$(basename $ret) + uuid=$(cut -f2 -d- "/sys/block/$dmtmp/dm/uuid") + echo "$mp $maj_min $dmtmp $uuid" >> $TMPLUNINFOFILE + done +} + # Go through all of the existing devices and figure out any that have been remapped findremapped() { @@ -812,6 +841,8 @@ findremapped() udevadm_settle 2>&1 /dev/null echo "Done" + getallmultipathinfo + # See what changed and reload the respective multipath device if applicable while read -r hctl sddev id_serial_old ; do remapped=0 @@ -937,7 +968,6 @@ findmultipath() local dev="$1" local find_mismatch="$2" local mp= - local mp2= local found_dup=0 local maj_min= @@ -947,27 +977,21 @@ findmultipath() fi maj_min=$(cat "/sys/block/$dev/dev") - for mp in $($DMSETUP ls --target=multipath | cut -f 1) ; do - [ "$mp" = "No" ] && break; - if "$DMSETUP" status "$mp" | grep -q " $maj_min "; then - # With two arguments, look up current uuid from sysfs - # if it doesn't match what was passed, this multipath - # device is not updated, so this is a remapped LUN - if [ -n "$find_mismatch" ] ; then - mp2=$($MULTIPATH -l "$mp" | egrep -o "dm-[0-9]+") - mp2=$(cut -f2 -d- "/sys/block/$mp2/dm/uuid") - if [ "$find_mismatch" != "$mp2" ] ; then - addmpathtolist "$mp" - found_dup=1 - fi - continue + mp=$(cat $TMPLUNINFOFILE | grep -w "$maj_min" | cut -d " " -f1) + if [ -n "$mp" ]; then + if [ -n "$find_mismatch" ] ; then + uuid=$(cat $TMPLUNINFOFILE | grep -w "$maj_min" | cut -d " " -f4) + if [ "$find_mismatch" != "$uuid" ] ; then + addmpathtolist "$mp" + found_dup=1 fi + else # Normal mode: Find the first multipath with the sdev # and add it to the list addmpathtolist "$mp" return fi - done + fi # Return 1 to signal that a duplicate was found to the calling function if [ $found_dup -eq 1 ] ; then -- cgit v1.2.3