doug-gilbert / sg3_utils

Author's own git mirror of his sg3_utils subversion repository. Note: default branch is now _main_. It includes tags from the various releases.
https://sg.danny.cz/sg/sg3_utils.html
Other
25 stars 22 forks source link

rescan-scsi-bus.sh: when there is a logical lun-0, testonline will spend 30s to retry-check it #24

Closed LiuXing108 closed 2 years ago

LiuXing108 commented 2 years ago

In function testonline, this shell uses sg_turs to check sgdevice, but lun-0 is not always a real device, sometimes a logical one. it depends on Vendor's implementation. So could we ensure there is a real sd-device before we check it by sg_turs?

doug-gilbert commented 2 years ago

Would something like 'if sg_inq $DEVICE | grep -q -i "PQual=0" ' work in this situation?

LiuXing108 commented 2 years ago

it works:

testoneline() {
  ……
  sg_turs /dev/$SGDEV >/dev/null 2>&1
  RC=$?

  # Handle in progress of becoming ready and unit attention
  while [ $RC = 2 -o $RC = 6 ] && [ $ctr -le 30 ] ; do
    if [ $RC = 2 ] && [ "$RMB" != "1" ] && [ sg_inq /dev/$SGDEV | grep -q -i "PQual=0" ]; then
      echo -n "."
      let LN+=1
      sleep 1
    else
      sleep 0.02
    fi
    let ctr+=1
    sg_turs /dev/$SGDEV >/dev/null 2>&1
    RC=$?
……
}
doug-gilbert commented 2 years ago

sg3_utils revision 972 (subversion, as show in ChangeLog file) uploaded with the above change in it. Could you test it?

LiuXing108 commented 2 years ago

I'm so sorry and embarrassed for https://github.com/doug-gilbert/sg3_utils/issues/24#issuecomment-1256902739. it has a code error - we should not add "[ ]".

LiuXing108 commented 2 years ago

I'm so sorry and embarrassed for #24 (comment). it has a code error - we should not add "[ ]", I wrote it wrong. it should be like this: if [ $RC = 2 ] && [ "$RMB" != "1" ] && sg_inq /dev/$SGDEV | grep -q -i "PQual=0" ; then

and I tested this shell with "scsi-rescan -a -r ",there are two iscsi links on my server, as we expected, one link reduced 30 seconds。 after modificated: real 0m12.165s user 0m2.853s sys 0m2.450s before modificated: real 1m12.874s user 0m2.732s sys 0m2.353s

doug-gilbert commented 2 years ago

Subversion revision 973, now mirrored here, has the above fix. Perhaps you might recheck it has been done properly. Also that revision contains the patch discussed in the issue #22 .