From 424d6468d62d09328c19cd54de1132be0940f049 Mon Sep 17 00:00:00 2001
From: sunshihao <sunshihao@huawei.com>
Date: Thu, 16 Apr 2020 11:05:20 +0800
Subject: [PATCH 4/4] sg3_utils-1.42-delete-lun-rescan-scsi-bus-report-error

---
 scripts/rescan-scsi-bus.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/scripts/rescan-scsi-bus.sh b/scripts/rescan-scsi-bus.sh
index 25a5f2a..dc3026a 100755
--- a/scripts/rescan-scsi-bus.sh
+++ b/scripts/rescan-scsi-bus.sh
@@ -502,7 +502,7 @@ dolunscan()
     # Well known lun transition case. Only for Direct-Access devs (type 0)
     # If block directory exists && and PQUAL != 0, we unmapped lun0 and just have a well-known lun
     # If block directory doesn't exist && PQUAL == 0, we mapped a real lun0
-    if [ "$lun" -eq 0 ] && [ $IPTYPE -eq 0 ] ; then
+    if [ x"$lun" = x0 ] && [ x$IPTYPE = x0 ] ; then
       if [ $RC = 2 ] ; then
         if [ -e "$devpath" ] ; then
           if [ -d "$devpath/block" ] ; then
@@ -511,7 +511,7 @@ dolunscan()
             RC=0   # Set this so the system leaves the existing well known lun alone. This is a lun 0 with no block directory
           fi
         fi
-      elif [ $RC = 0 ] && [ $IPTYPE -eq 0 ] ; then
+      elif [ $RC = 0 ] && [ x$IPTYPE = x0 ] ; then
         if [ -e "$devpath" ] ; then
           if [ ! -d "$devpath/block" ] ; then
             remappedlun0=1  # Transition from well-known to real lun 0
@@ -523,7 +523,7 @@ dolunscan()
 
   # Special case: lun 0 just got added (for reportlunscan),
   # so make sure we correctly treat it as new
-  if [ "$lun" = "0" ] && [ "$1" = "1" ] && [ -z "$remappedlun0" ] ; then
+  if [ x"$lun" = x"0" ] && [ x"$1" = x"1" ] && [ -z "$remappedlun0" ] ; then
     SCSISTR=""
     printf "\r\e[A\e[A\e[A"
   fi
@@ -546,7 +546,7 @@ dolunscan()
         sleep 0.02
       else
         echo "scsi remove-single-device $devnr" > /proc/scsi/scsi
-        if [ $RC -eq 1 ] || [ "$lun" -eq 0 ] ; then
+        if [ $RC -eq 1 ] || [ x"$lun" = x0 ] ; then
           # Try reading, should fail if device is gone
           echo "scsi add-single-device $devnr" > /proc/scsi/scsi
         fi
-- 
2.19.1

