{"id":559,"date":"2011-09-05T02:59:37","date_gmt":"2011-09-05T00:59:37","guid":{"rendered":"http:\/\/www.superkikim.com\/?p=559"},"modified":"2015-09-02T16:16:12","modified_gmt":"2015-09-02T14:16:12","slug":"detecter-un-nouveau-disque-ou-lun-sur-un-systeme-linux-rescan-bus","status":"publish","type":"post","link":"https:\/\/akim.sissaoui.com\/en\/informatique\/detecter-un-nouveau-disque-ou-lun-sur-un-systeme-linux-rescan-bus\/","title":{"rendered":"D\u00e9tecter un nouveau disque ou LUN sur un syst\u00e8me Linux (rescan bus)"},"content":{"rendered":"<p>Pour d\u00e9tecter un nouveau disque, ou tout changement de taille d&#8217;un LUN ou d&#8217;un disque sur Linux, il faut envoyer le texte &#8220;- &#8211; -&#8221; dans un fichier texte ce qui initiera le scan. Le probl\u00e8me est que cette op\u00e9ration n&#8217;enl\u00e8ve pas les dsique supprim\u00e9s par exemple, et ne permet pas de scanner tous les contr\u00f4leurs en une fois, mais un \u00e0 un. Donc \u00e0 condition de savoir comment identifier le bus que l&#8217;on souhaite scanner, il faudra tous les faire.<br \/>\n<!--more--><br \/>\nL&#8217;alternative est cet excellent script de Kurt Garloff et Hannes Reinecke, distribuable sous license GNU GPL v2<\/p>\n<pre lang=\"bash\" file=\"rescan-scsi-bus.sh\">\r\n#!\/bin\/bash\r\n# Skript to rescan SCSI bus, using the\r\n# scsi add-single-device mechanism\r\n# (c) 1998--2008 Kurt Garloff <kurt@garloff.de>, GNU GPL v2 or later\r\n# (c) 2006--2008 Hannes Reinecke, GNU GPL v2 or later\r\n# $Id: rescan-scsi-bus.sh,v 1.48 2010\/08\/10 19:32:22 garloff Exp $\r\n\r\nsetcolor ()\r\n{\r\n  red=\"\\e[0;31m\"\r\n  green=\"\\e[0;32m\"\r\n  yellow=\"\\e[0;33m\"\r\n  bold=\"\\e[0;1m\"\r\n  norm=\"\\e[0;0m\"\r\n}\r\n\r\nunsetcolor ()\r\n{\r\n  red=\"\"; green=\"\"\r\n  yellow=\"\"; norm=\"\"\r\n}\r\n\r\n# Output some text and return cursor to previous position\r\n# (only works for simple strings)\r\n# Stores length of string in LN and returns it\r\nprint_and_scroll_back ()\r\n{\r\n  STRG=\"$1\"\r\n  LN=${#STRG}\r\n  BK=\"\"\r\n  declare -i cntr=0\r\n  while test $cntr -lt $LN; do BK=\"$BK\\e[D\"; let cntr+=1; done\r\n  echo -en \"$STRG$BK\"\r\n  return $LN\r\n}\r\n\r\n# Overwrite a text of length $1 (fallback to $LN) with whitespace\r\nwhite_out ()\r\n{\r\n  BK=\"\"; WH=\"\"\r\n  if test -n \"$1\"; then LN=$1; fi\r\n  declare -i cntr=0\r\n  while test $cntr -lt $LN; do BK=\"$BK\\e[D\"; WH=\"$WH \"; let cntr+=1; done\r\n  echo -en \"$WH$BK\"\r\n}\r\n\r\n# Return hosts. sysfs must be mounted\r\nfindhosts_26 ()\r\n{\r\n  hosts=\r\n  for hostdir in \/sys\/class\/scsi_host\/host*; do\r\n    hostno=${hostdir#\/sys\/class\/scsi_host\/host}\r\n    if [ -f $hostdir\/isp_name ] ; then\r\n      hostname=\"qla2xxx\"\r\n    elif [ -f $hostdir\/lpfc_drvr_version ] ; then\r\n      hostname=\"lpfc\"\r\n    else\r\n      hostname=`cat $hostdir\/proc_name`\r\n    fi\r\n    hosts=\"$hosts $hostno\"\r\n    echo \"Host adapter $hostno ($hostname) found.\"\r\n  done\r\n  if [ -z \"$hosts\" ] ; then\r\n    echo \"No SCSI host adapters found in sysfs\"\r\n    exit 1;\r\n  fi\r\n  hosts=`echo $hosts | sed 's\/ \/\\n\/g' | sort -n`\r\n}\r\n\r\n# Return hosts. \/proc\/scsi\/HOSTADAPTER\/? must exist\r\nfindhosts ()\r\n{\r\n  hosts=\r\n  for driverdir in \/proc\/scsi\/*; do\r\n    driver=${driverdir#\/proc\/scsi\/}\r\n    if test $driver = scsi -o $driver = sg -o $driver = dummy -o $driver = device_info; then continue; fi\r\n    for hostdir in $driverdir\/*; do\r\n      name=${hostdir#\/proc\/scsi\/*\/}\r\n      if test $name = add_map -o $name = map -o $name = mod_parm; then continue; fi\r\n      num=$name\r\n      driverinfo=$driver\r\n      if test -r $hostdir\/status; then\r\n        num=$(printf '%d\\n' `sed -n 's\/SCSI host number:\/\/p' $hostdir\/status`)\r\n        driverinfo=\"$driver:$name\"\r\n      fi\r\n      hosts=\"$hosts $num\"\r\n      echo \"Host adapter $num ($driverinfo) found.\"\r\n    done\r\n  done\r\n}\r\n\r\nprinttype ()\r\n{\r\n  local type=$1\r\n\r\n  case \"$type\" in\r\n    0) echo \"Direct-Access    \" ;;\r\n    1) echo \"Sequential-Access\" ;;\r\n    2) echo \"Printer          \" ;;\r\n    3) echo \"Processor        \" ;;\r\n    4) echo \"WORM             \" ;;\r\n    5) echo \"CD-ROM           \" ;;\r\n    6) echo \"Scanner          \" ;;\r\n    7) echo \"Optical Device   \" ;;\r\n    8) echo \"Medium Changer   \" ;;\r\n    9) echo \"Communications   \" ;;\r\n    10) echo \"Unknown          \" ;;\r\n    11) echo \"Unknown          \" ;;\r\n    12) echo \"RAID             \" ;;\r\n    13) echo \"Enclosure        \" ;;\r\n    14) echo \"Direct-Access-RBC\" ;;\r\n    *) echo \"Unknown          \" ;;\r\n  esac\r\n}\r\n\r\nprint02i()\r\n{\r\n    if [ \"$1\" = \"*\" ] ; then\r\n        echo \"00\"\r\n    else\r\n        printf \"%02i\" \"$1\"\r\n    fi\r\n}\r\n\r\n# Get \/proc\/scsi\/scsi info for device $host:$channel:$id:$lun\r\n# Optional parameter: Number of lines after first (default = 2),\r\n# result in SCSISTR, return code 1 means empty.\r\nprocscsiscsi ()\r\n{\r\n  if test -z \"$1\"; then LN=2; else LN=$1; fi\r\n  CHANNEL=`print02i \"$channel\"`\r\n  ID=`print02i \"$id\"`\r\n  LUN=`print02i \"$lun\"`\r\n  if [ -d \/sys\/class\/scsi_device ]; then\r\n    SCSIPATH=\"\/sys\/class\/scsi_device\/${host}:${channel}:${id}:${lun}\"\r\n    if [ -d  \"$SCSIPATH\" ] ; then\r\n      SCSISTR=\"Host: scsi${host} Channel: $CHANNEL Id: $ID Lun: $LUN\"\r\n      if [ \"$LN\" -gt 0 ] ; then\r\n        IVEND=$(cat ${SCSIPATH}\/device\/vendor)\r\n        IPROD=$(cat ${SCSIPATH}\/device\/model)\r\n        IPREV=$(cat ${SCSIPATH}\/device\/rev)\r\n        SCSIDEV=$(printf '  Vendor: %-08s Model: %-16s Rev: %-4s' \"$IVEND\" \"$IPROD\" \"$IPREV\")\r\n        SCSISTR=\"$SCSISTR\r\n$SCSIDEV\"\r\n      fi\r\n      if [ \"$LN\" -gt 1 ] ; then\r\n        ILVL=$(cat ${SCSIPATH}\/device\/scsi_level)\r\n        type=$(cat ${SCSIPATH}\/device\/type)\r\n        ITYPE=$(printtype $type)\r\n        SCSITMP=$(printf '  Type:   %-16s                ANSI SCSI revision: %02d' \"$ITYPE\" \"$((ILVL - 1))\")\r\n        SCSISTR=\"$SCSISTR\r\n$SCSITMP\"\r\n      fi\r\n    else\r\n      return 1\r\n    fi\r\n  else\r\n    grepstr=\"scsi$host Channel: $CHANNEL Id: $ID Lun: $LUN\"\r\n    SCSISTR=`cat \/proc\/scsi\/scsi | grep -A$LN -e\"$grepstr\"`\r\n  fi\r\n  if test -z \"$SCSISTR\"; then return 1; else return 0; fi\r\n}\r\n\r\n# Find sg device with 2.6 sysfs support\r\nsgdevice26 ()\r\n{\r\n  if test -e \/sys\/class\/scsi_device\/$host\\:$channel\\:$id\\:$lun\/device\/generic; then\r\n    SGDEV=`readlink \/sys\/class\/scsi_device\/$host\\:$channel\\:$id\\:$lun\/device\/generic`\r\n    SGDEV=`basename $SGDEV`\r\n  else\r\n    for SGDEV in \/sys\/class\/scsi_generic\/sg*; do\r\n      DEV=`readlink $SGDEV\/device`\r\n      if test \"${DEV##*\/}\" = \"$host:$channel:$id:$lun\"; then\r\n        SGDEV=`basename $SGDEV`; return\r\n      fi\r\n    done\r\n    SGDEV=\"\"\r\n  fi\r\n}\r\n\r\n# Find sg device with 2.4 report-devs extensions\r\nsgdevice24 ()\r\n{\r\n  if procscsiscsi 3; then\r\n    SGDEV=`echo \"$SCSISTR\" | grep 'Attached drivers:' | sed 's\/^ *Attached drivers: \\(sg[0-9]*\\).*\/\\1\/'`\r\n  fi\r\n}\r\n\r\n# Find sg device that belongs to SCSI device $host $channel $id $lun\r\n# and return in SGDEV\r\nsgdevice ()\r\n{\r\n  SGDEV=\r\n  if test -d \/sys\/class\/scsi_device; then\r\n    sgdevice26\r\n  else\r\n    DRV=`grep 'Attached drivers:' \/proc\/scsi\/scsi 2>\/dev\/null`\r\n    repdevstat=$((1-$?))\r\n    if [ $repdevstat = 0 ]; then\r\n      echo \"scsi report-devs 1\" >\/proc\/scsi\/scsi\r\n      DRV=`grep 'Attached drivers:' \/proc\/scsi\/scsi 2>\/dev\/null`\r\n      if [ $? = 1 ]; then return; fi\r\n    fi\r\n    if ! `echo $DRV | grep 'drivers: sg' >\/dev\/null`; then\r\n      modprobe sg\r\n    fi\r\n    sgdevice24\r\n    if [ $repdevstat = 0 ]; then\r\n      echo \"scsi report-devs 0\" >\/proc\/scsi\/scsi\r\n    fi\r\n  fi\r\n}\r\n\r\n# Test if SCSI device is still responding to commands\r\ntestonline ()\r\n{\r\n  : testonline\r\n  RC=0\r\n  if test ! -x \/usr\/bin\/sg_turs; then return 0; fi\r\n  sgdevice\r\n  if test -z \"$SGDEV\"; then return 0; fi\r\n  sg_turs \/dev\/$SGDEV >\/dev\/null 2>&1\r\n  RC=$?\r\n  # Handle in progress of becoming ready and unit attention -- wait at max 11s\r\n  declare -i ctr=0\r\n  if test $RC = 2 -o $RC = 6; then\r\n    RMB=`sg_inq \/dev\/$SGDEV | grep 'RMB=' | sed 's\/^.*RMB=\\(.\\).*$\/\\1\/'`\r\n    print_and_scroll_back \"$host:$channel:$id:$lun $SGDEV ($RMB) \"\r\n  fi\r\n  while test $RC = 2 -o $RC = 6 && test $ctr -le 8; do\r\n    if test $RC = 2 -a \"$RMB\" != \"1\"; then echo -n \".\"; let $LN+=1; sleep 1\r\n    else usleep 20000; fi\r\n    let ctr+=1\r\n    sg_turs \/dev\/$SGDEV >\/dev\/null 2>&1\r\n    RC=$?\r\n  done\r\n  if test $ctr != 0; then white_out; fi\r\n  # echo -e \"\\e[A\\e[A\\e[A${yellow}Test existence of $SGDEV = $RC ${norm} \\n\\n\\n\"\r\n  if test $RC = 1; then return $RC; fi\r\n  # Reset RC (might be !=0 for passive paths)\r\n  RC=0\r\n  # OK, device online, compare INQUIRY string\r\n  INQ=`sg_inq $sg_len_arg \/dev\/$SGDEV 2>\/dev\/null`\r\n  IVEND=`echo \"$INQ\" | grep 'Vendor identification:' | sed 's\/^[^:]*: \\(.*\\)$\/\\1\/'`\r\n  IPROD=`echo \"$INQ\" | grep 'Product identification:' | sed 's\/^[^:]*: \\(.*\\)$\/\\1\/'`\r\n  IPREV=`echo \"$INQ\" | grep 'Product revision level:' | sed 's\/^[^:]*: \\(.*\\)$\/\\1\/'`\r\n  STR=`printf \"  Vendor: %-08s Model: %-16s Rev: %-4s\" \"$IVEND\" \"$IPROD\" \"$IPREV\"`\r\n  IPTYPE=`echo \"$INQ\" | sed -n 's\/.* Device_type=\\([0-9]*\\) .*\/\\1\/p'`\r\n  IPQUAL=`echo \"$INQ\" | sed -n 's\/ *PQual=\\([0-9]*\\)  Device.*\/\\1\/p'`\r\n  if [ \"$IPQUAL\" != 0 ] ; then\r\n    echo -e \"\\e[A\\e[A\\e[A\\e[A${red}$SGDEV changed: ${bold}LU not available (PQual $IPQUAL)${norm}    \\n\\n\\n\"\r\n    return 2\r\n  fi\r\n\r\n  TYPE=$(printtype $IPTYPE)\r\n  procscsiscsi\r\n  TMPSTR=`echo \"$SCSISTR\" | grep 'Vendor:'`\r\n  if [ \"$TMPSTR\" != \"$STR\" ]; then\r\n    echo -e \"\\e[A\\e[A\\e[A\\e[A${red}$SGDEV changed: ${bold}\\nfrom:${SCSISTR#* } \\nto: $STR ${norm} \\n\\n\\n\"\r\n    return 1\r\n  fi\r\n  TMPSTR=`echo \"$SCSISTR\" | sed -n 's\/.*Type: *\\(.*\\) *ANSI.*\/\\1\/p'`\r\n  if [ $TMPSTR != $TYPE ] ; then\r\n    echo -e \"\\e[A\\e[A\\e[A\\e[A${red}$SGDEV changed: ${bold}\\nfrom:${TMPSTR} \\nto: $TYPE ${norm} \\n\\n\\n\"\r\n    return 1\r\n  fi\r\n  return $RC\r\n}\r\n\r\n# Test if SCSI device $host $channen $id $lun exists\r\n# Outputs description from \/proc\/scsi\/scsi (unless arg passed)\r\n# Returns SCSISTR (empty if no dev)\r\ntestexist ()\r\n{\r\n  : testexist\r\n  SCSISTR=\r\n  if procscsiscsi && test -z \"$1\"; then\r\n    echo \"$SCSISTR\" | head -n1\r\n    echo \"$SCSISTR\" | tail -n2 | pr -o4 -l1\r\n  fi\r\n}\r\n\r\n# Returns the list of existing channels per host\r\nchanlist ()\r\n{\r\n  local hcil\r\n  local cil\r\n  local chan\r\n  local tmpchan\r\n\r\n  for dev in \/sys\/class\/scsi_device\/${host}:* ; do\r\n    [ -d $dev ] || continue;\r\n    hcil=${dev##*\/}\r\n    cil=${hcil#*:}\r\n    chan=${cil%%:*}\r\n    for tmpchan in $channelsearch ; do\r\n      if test \"$chan\" -eq $tmpchan ; then\r\n        chan=\r\n      fi\r\n    done\r\n    if test -n \"$chan\" ; then\r\n      channelsearch=\"$channelsearch $chan\"\r\n    fi\r\n  done\r\n  if test -z \"$channelsearch\"; then channelsearch=\"0\"; fi\r\n}\r\n\r\n# Returns the list of existing targets per host\r\nidlist ()\r\n{\r\n  local hcil\r\n  local cil\r\n  local il\r\n  local target\r\n  local tmpid\r\n\r\n  for dev in \/sys\/class\/scsi_device\/${host}:${channel}:* ; do\r\n    [ -d $dev ] || continue;\r\n    hcil=${dev##*\/}\r\n    cil=${hcil#*:}\r\n    il=${cil#*:}\r\n    target=${il%%:*}\r\n    for tmpid in $idsearch ; do\r\n      if test \"$target\" -eq $tmpid ; then\r\n        target=\r\n        break\r\n      fi\r\n    done\r\n    if test -n \"$target\" ; then\r\n      idsearch=\"$idsearch $target\"\r\n    fi\r\n  done\r\n}\r\n\r\n# Returns the list of existing LUNs from device $host $channel $id $lun\r\n# and returns list to stdout\r\ngetluns()\r\n{\r\n  sgdevice\r\n  if test -z \"$SGDEV\"; then return; fi\r\n  if test ! -x \/usr\/bin\/sg_luns; then echo 0; return; fi\r\n  LLUN=`sg_luns -d \/dev\/$SGDEV 2>\/dev\/null`\r\n  if test $? != 0; then echo 0; return; fi\r\n  echo \"$LLUN\" | sed -n 's\/.*lun=\\(.*\\)\/\\1\/p'\r\n}\r\n\r\n# Wait for udev to settle (create device nodes etc.)\r\nudevadm_settle()\r\n{\r\n  if test -x \/sbin\/udevadm; then\r\n    print_and_scroll_back \" Calling udevadm settle (can take a while) \"\r\n    \/sbin\/udevadm settle\r\n    white_out\r\n  else\r\n    usleep 20000\r\n  fi\r\n}\r\n\r\n# Perform scan on a single lun $host $channel $id $lun\r\ndolunscan()\r\n{\r\n  SCSISTR=\r\n  devnr=\"$host $channel $id $lun\"\r\n  echo \"Scanning for device $devnr ... \"\r\n  printf \"${yellow}OLD: $norm\"\r\n  testexist\r\n  # Special case: lun 0 just got added (for reportlunscan),\r\n  # so make sure we correctly treat it as new\r\n  if test \"$lun\" = \"0\" -a \"$1\"; then\r\n    SCSISTR=\"\"\r\n    printf \"\\r\\e[A\\e[A\\e[A\"\r\n  fi\r\n  : f $remove s $SCSISTR\r\n  if test \"$remove\" -a \"$SCSISTR\"; then\r\n    # Device exists: Test whether it's still online\r\n    # (testonline returns 1 if it's gone or has changed)\r\n    testonline\r\n    RC=$?\r\n    if test $RC != 0 -o ! -z \"$forceremove\"; then\r\n      echo -en \"\\r\\e[A\\e[A\\e[A${red}REM: \"\r\n      echo \"$SCSISTR\" | head -n1\r\n      echo -e \"${norm}\\e[B\\e[B\"\r\n      if test -e \/sys\/class\/scsi_device\/${host}:${channel}:${id}:${lun}\/device; then\r\n        echo 1 > \/sys\/class\/scsi_device\/${host}:${channel}:${id}:${lun}\/device\/delete\r\n        if test $RC -eq 1 -o $lun -eq 0 ; then\r\n          # Try readding, should fail if device is gone\r\n          echo \"$channel $id $lun\" > \/sys\/class\/scsi_host\/host${host}\/scan\r\n        fi\r\n        # FIXME: Can we skip udevadm settle for removal?\r\n        #udevadm_settle\r\n        usleep 20000\r\n      else\r\n        echo \"scsi remove-single-device $devnr\" > \/proc\/scsi\/scsi\r\n        if test $RC -eq 1 -o $lun -eq 0 ; then\r\n          # Try readding, should fail if device is gone\r\n          echo \"scsi add-single-device $devnr\" > \/proc\/scsi\/scsi\r\n        fi\r\n      fi\r\n    fi\r\n    if test $RC = 0 -o \"$forcerescan\" ; then\r\n      if test -e \/sys\/class\/scsi_device\/${host}:${channel}:${id}:${lun}\/device; then\r\n        echo 1 > \/sys\/class\/scsi_device\/${host}:${channel}:${id}:${lun}\/device\/rescan\r\n        udevadm_settle\r\n      fi\r\n    fi\r\n    printf \"\\r\\e[A\\e[A\\e[A${yellow}OLD: $norm\"\r\n    testexist\r\n    if test -z \"$SCSISTR\"; then\r\n      printf \"\\r${red}DEL: $norm\\r\\n\\n\"\r\n      let rmvd+=1;\r\n      return 1\r\n    fi\r\n  fi\r\n  if test -z \"$SCSISTR\"; then\r\n    # Device does not exist, try to add\r\n    printf \"\\r${green}NEW: $norm\"\r\n    if test -e \/sys\/class\/scsi_host\/host${host}\/scan; then\r\n      echo \"$channel $id $lun\" > \/sys\/class\/scsi_host\/host${host}\/scan 2> \/dev\/null\r\n      udevadm_settle\r\n    else\r\n      echo \"scsi add-single-device $devnr\" > \/proc\/scsi\/scsi\r\n    fi\r\n    testexist\r\n    if test -z \"$SCSISTR\"; then\r\n      # Device not present\r\n      printf \"\\r\\e[A\";\r\n      # Optimization: if lun==0, stop here (only if in non-remove mode)\r\n      if test $lun = 0 -a -z \"$remove\" -a $optscan = 1; then\r\n        break;\r\n      fi\r\n    else\r\n      let found+=1;\r\n    fi\r\n  fi\r\n}\r\n\r\n# Perform report lun scan on $host $channel $id using REPORT_LUNS\r\ndoreportlun()\r\n{\r\n  lun=0\r\n  SCSISTR=\r\n  devnr=\"$host $channel $id $lun\"\r\n  echo -en \"Scanning for device $devnr ...\\r\"\r\n  lun0added=\r\n  #printf \"${yellow}OLD: $norm\"\r\n  # Phase one: If LUN0 does not exist, try to add\r\n  testexist -q\r\n  if test -z \"$SCSISTR\"; then\r\n    # Device does not exist, try to add\r\n    #printf \"\\r${green}NEW: $norm\"\r\n    if test -e \/sys\/class\/scsi_host\/host${host}\/scan; then\r\n      echo \"$channel $id $lun\" > \/sys\/class\/scsi_host\/host${host}\/scan 2> \/dev\/null\r\n      udevadm_settle\r\n    else\r\n      echo \"scsi add-single-device $devnr\" > \/proc\/scsi\/scsi\r\n    fi\r\n    testexist -q\r\n    if test -n \"$SCSISTR\"; then\r\n      lun0added=1\r\n      #testonline\r\n    else\r\n      # Device not present\r\n      # return\r\n      # Find alternative LUN to send getluns to\r\n      for dev in \/sys\/class\/scsi_device\/${host}:${channel}:${id}:*; do\r\n        [ -d \"$dev\" ] || continue\r\n        lun=${dev##*:}\r\n        break\r\n      done\r\n    fi\r\n  fi\r\n  targetluns=`getluns`\r\n  lunremove=\r\n  #echo \"getluns reports \" $targetluns\r\n  # Check existing luns\r\n  for dev in \/sys\/class\/scsi_device\/${host}:${channel}:${id}:*; do\r\n    [ -d \"$dev\" ] || continue\r\n    lun=${dev##*:}\r\n    newsearch=\r\n    inlist=\r\n    # OK, is existing $lun (still) in reported list\r\n    for tmplun in $targetluns; do\r\n      if test $tmplun -eq $lun ; then\r\n        inlist=1\r\n        dolunscan $lun0added\r\n      else\r\n        newsearch=\"$newsearch $tmplun\"\r\n      fi\r\n    done\r\n    # OK, we have now done a lunscan on $lun and\r\n    # $newsearch is the old $targetluns without $lun\r\n    if [ -z \"$inlist\" ]; then\r\n      # Stale lun\r\n      lunremove=\"$lunremove $lun\"\r\n    fi\r\n    # $lun removed from $lunsearch (echo for whitespace cleanup)\r\n    targetluns=`echo $newsearch`\r\n  done\r\n  # Add new ones and check stale ones\r\n  for lun in $targetluns $lunremove; do\r\n    dolunscan $lun0added\r\n  done\r\n}\r\n\r\n# Perform search (scan $host)\r\ndosearch ()\r\n{\r\n  if test -z \"$channelsearch\" ; then\r\n    chanlist\r\n  fi\r\n  for channel in $channelsearch; do\r\n    if test -z \"$idsearch\" ; then\r\n      idlist\r\n    fi\r\n    for id in $idsearch; do\r\n      if test -z \"$lunsearch\" ; then\r\n        doreportlun\r\n      else\r\n        for lun in $lunsearch; do\r\n          dolunscan\r\n        done\r\n      fi\r\n    done\r\n  done\r\n}\r\n\r\nexpandlist ()\r\n{\r\n  list=$1\r\n  result=\"\"\r\n  first=${list%%,*}\r\n  rest=${list#*,}\r\n  while test ! -z \"$first\"; do\r\n    beg=${first%%-*};\r\n    if test \"$beg\" = \"$first\"; then\r\n      result=\"$result $beg\";\r\n    else\r\n      end=${first#*-}\r\n      result=\"$result `seq $beg $end`\"\r\n    fi\r\n    test \"$rest\" = \"$first\" && rest=\"\"\r\n    first=${rest%%,*}\r\n    rest=${rest#*,}\r\n  done\r\n  echo $result\r\n}\r\n\r\n# main\r\nif test @$1 = @--help -o @$1 = @-h -o @$1 = @-?; then\r\n    echo \"Usage: rescan-scsi-bus.sh [options] [host [host ...]]\"\r\n    echo \"Options:\"\r\n    echo \" -l      activates scanning for LUNs 0--7   [default: 0]\"\r\n    echo \" -L NUM  activates scanning for LUNs 0--NUM [default: 0]\"\r\n    echo \" -w      scan for target device IDs 0--15   [default: 0--7]\"\r\n    echo \" -c      enables scanning of channels 0 1   [default: 0 \/ all detected ones]\"\r\n    echo \" -r      enables removing of devices        [default: disabled]\"\r\n    echo \" -i      issue a FibreChannel LIP reset     [default: disabled]\"\r\n    echo \"--remove:        same as -r\"\r\n    echo \"--issue-lip:     same as -i\"\r\n    echo \"--forcerescan:   Rescan existing devices\"\r\n    echo \"--forceremove:   Remove and readd every device (DANGEROUS)\"\r\n    echo \"--nooptscan:     don't stop looking for LUNs is 0 is not found\"\r\n    echo \"--color:         use coloured prefixes OLD\/NEW\/DEL\"\r\n    echo \"--hosts=LIST:    Scan only host(s) in LIST\"\r\n    echo \"--channels=LIST: Scan only channel(s) in LIST\"\r\n    echo \"--ids=LIST:      Scan only target ID(s) in LIST\"\r\n    echo \"--luns=LIST:     Scan only lun(s) in LIST\"\r\n    echo \"--sync\/nosync:   Issue a sync \/ no sync [default: sync if remove]\"\r\n    echo \"--attachpq3:     Tell kernel to attach sg to LUN 0 that reports PQ=3\"\r\n    echo \"--reportlun2:    Tell kernel to try REPORT_LUN even on SCSI2 devices\"\r\n    echo \"--largelun:      Tell kernel to support LUNs > 7 even on SCSI2 devs\"\r\n    echo \"--sparselun:     Tell kernel to support sparse LUN numbering\"\r\n    echo \" Host numbers may thus be specified either directly on cmd line (deprecated) or\"\r\n    echo \" or with the --hosts=LIST parameter (recommended).\"\r\n    echo \"LIST: A[-B][,C[-D]]... is a comma separated list of single values and ranges\"\r\n    echo \" (No spaces allowed.)\"\r\n    exit 0\r\nfi\r\n\r\nif test ! -d \/sys\/class\/scsi_host\/ -a ! -d \/proc\/scsi\/; then\r\n  echo \"Error: SCSI subsystem not active\"\r\n  exit 1\r\nfi\r\n\r\n# Make sure sg is there\r\nmodprobe sg >\/dev\/null 2>&1\r\n\r\nif test -x \/usr\/bin\/sg_inq; then\r\n    sg_version=$(sg_inq -V 2>&1 | cut -d \" \" -f 3)\r\n    sg_version=${sg_version##0.}\r\n    #echo \"\\\"$sg_version\\\"\"\r\n    if [ -z \"$sg_version\" -o \"$sg_version\" -lt 70 ] ; then\r\n        sg_len_arg=\"-36\"\r\n    else\r\n        sg_len_arg=\"--len=36\"\r\n    fi\r\nfi\r\n\r\n# defaults\r\nunsetcolor\r\nlunsearch=\r\nopt_idsearch=`seq 0 7`\r\nopt_channelsearch=\r\nremove=\r\nforceremove=\r\noptscan=1\r\nsync=1\r\ndeclare -i scan_flags=0\r\nif test -d \/sys\/class\/scsi_host; then\r\n  findhosts_26\r\nelse\r\n  findhosts\r\nfi\r\n\r\n# Scan options\r\nopt=\"$1\"\r\nwhile test ! -z \"$opt\" -a -z \"${opt##-*}\"; do\r\n  opt=${opt#-}\r\n  case \"$opt\" in\r\n    l) lunsearch=`seq 0 7` ;;\r\n    L) lunsearch=`seq 0 $2`; shift ;;\r\n    w) opt_idsearch=`seq 0 15` ;;\r\n    c) opt_channelsearch=\"0 1\" ;;\r\n    r) remove=1 ;;\r\n    i) lipreset=1 ;;\r\n    -remove)      remove=1 ;;\r\n    -forcerescan) remove=1; forcerescan=1 ;;\r\n    -forceremove) remove=1; forceremove=1 ;;\r\n    -hosts=*)     arg=${opt#-hosts=};   hosts=`expandlist $arg` ;;\r\n    -channels=*)  arg=${opt#-channels=};opt_channelsearch=`expandlist $arg` ;;\r\n    -ids=*)   arg=${opt#-ids=};         opt_idsearch=`expandlist $arg` ;;\r\n    -luns=*)  arg=${opt#-luns=};        lunsearch=`expandlist $arg` ;;\r\n    -color) setcolor ;;\r\n    -nooptscan) optscan=0 ;;\r\n    -issue-lip) lipreset=1 ;;\r\n    -sync) sync=2 ;;\r\n    -nosync) sync=0 ;;\r\n    -attachpq3) scan_flags=$(($scan_flags|0x1000000)) ;;\r\n    -reportlun2) scan_flags=$(($scan_flags|0x20000)) ;;\r\n    -largelun) scan_flags=$(($scan_flags|0x200)) ;;\r\n    -sparselun) scan_flags=$((scan_flags|0x40)) ;;\r\n    *) echo \"Unknown option -$opt !\" ;;\r\n  esac\r\n  shift\r\n  opt=\"$1\"\r\ndone\r\n\r\n# Hosts given ?\r\nif test \"@$1\" != \"@\"; then\r\n  hosts=$*\r\nfi\r\n\r\nif [ -d \/sys\/class\/scsi_host -a ! -w \/sys\/class\/scsi_host ]; then\r\n  echo \"You need to run scsi-rescan-bus.sh as root\"\r\n  exit 2\r\nfi\r\nif test \"$sync\" = 1 -a \"$remove\" = 1; then sync=2; fi\r\nif test \"$sync\" = 2; then echo \"Syncing file systems\"; sync; fi\r\nif test -w \/sys\/module\/scsi_mod\/parameters\/default_dev_flags -a $scan_flags != 0; then\r\n  OLD_SCANFLAGS=`cat \/sys\/module\/scsi_mod\/parameters\/default_dev_flags`\r\n  NEW_SCANFLAGS=$(($OLD_SCANFLAGS|$scan_flags))\r\n  if test \"$OLD_SCANFLAGS\" != \"$NEW_SCANFLAGS\"; then\r\n    echo -n \"Temporarily setting kernel scanning flags from \"\r\n    printf \"0x%08x to 0x%08x\\n\" $OLD_SCANFLAGS $NEW_SCANFLAGS\r\n    echo $NEW_SCANFLAGS > \/sys\/module\/scsi_mod\/parameters\/default_dev_flags\r\n  else\r\n    unset OLD_SCANFLAGS\r\n  fi\r\nfi\r\necho \"Scanning SCSI subsystem for new devices\"\r\ntest -z \"$remove\" || echo \" and remove devices that have disappeared\"\r\ndeclare -i found=0\r\ndeclare -i rmvd=0\r\nfor host in $hosts; do\r\n  echo -n \"Scanning host $host \"\r\n  if test -e \/sys\/class\/fc_host\/host$host ; then\r\n    # It's pointless to do a target scan on FC\r\n    if test -n \"$lipreset\" ; then\r\n      echo 1 > \/sys\/class\/fc_host\/host$host\/issue_lip 2> \/dev\/null;\r\n    fi\r\n    # Always trigger a rescan for FC to update channels and targets\r\n    echo \"- - -\" > \/sys\/class\/scsi_host\/host$host\/scan 2> \/dev\/null;\r\n    channelsearch=\r\n    idsearch=\r\n    udevadm_settle\r\n  else\r\n    channelsearch=$opt_channelsearch\r\n    idsearch=$opt_idsearch\r\n  fi\r\n  [ -n \"$channelsearch\" ] && echo -n \"channels $channelsearch \"\r\n  echo -n \"for \"\r\n  if [ -n \"$idsearch\" ] ; then\r\n    echo -n \" SCSI target IDs \" $idsearch\r\n  else\r\n    echo -n \" all SCSI target IDs\"\r\n  fi\r\n  if [ -n \"$lunsearch\" ] ; then\r\n    echo \", LUNs \" $lunsearch\r\n  else\r\n    echo \", all LUNs\"\r\n  fi\r\n  dosearch\r\ndone\r\nif test -n \"$OLD_SCANFLAGS\"; then\r\n  echo $OLD_SCANFLAGS > \/sys\/module\/scsi_mod\/parameters\/default_dev_flags\r\nfi\r\necho \"$found new device(s) found.               \"\r\necho \"$rmvd device(s) removed.                 \"\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Pour d\u00e9tecter un nouveau disque, ou tout changement de taille d&#8217;un LUN ou d&#8217;un disque sur Linux, il faut envoyer le texte &#8220;- &#8211; -&#8221; dans un fichier texte ce qui initiera le scan. Le probl\u00e8me est que cette op\u00e9ration n&#8217;enl\u00e8ve pas les dsique supprim\u00e9s par exemple, et ne permet pas de scanner tous les [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[220],"tags":[56,162],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/posts\/559"}],"collection":[{"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/comments?post=559"}],"version-history":[{"count":8,"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/posts\/559\/revisions"}],"predecessor-version":[{"id":1151,"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/posts\/559\/revisions\/1151"}],"wp:attachment":[{"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/media?parent=559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/categories?post=559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/akim.sissaoui.com\/en\/wp-json\/wp\/v2\/tags?post=559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}