Advertisement
Guest User

block-iscsi

a guest
Jan 7th, 2011
143
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash -x
  2. # block-iscsi  -  2009 Keith Herron <keith@backdrift.org>
  3. #
  4. # multipath enabled block-iscsi xen block script.
  5. #
  6. # Note: This script depends on a block-iscsi.conf file
  7. #       located in the same directory.  This file contains
  8. #       an array of available iSCSI target IPs
  9. #
  10.  
  11. dir=$(dirname "$0")
  12. . "$dir/block-common.sh"
  13. . "$dir/block-iscsi.conf"
  14.  
  15. # Log which mode we are in
  16. logger -t block-iscsi "*** Beginning device $command ***"
  17.  
  18. # Fetch the iqn we specify in the domu config file
  19. #
  20. IQN=$(xenstore_read "$XENBUS_PATH/params")
  21.  
  22. logger -t block-iscsi "cmd:xenstore_read "$XENBUS_PATH/params""
  23.  
  24. logger -t block-iscsi "IQN: ${IQN}"
  25.  
  26. # We define portal ip in order to support new luns which don't yet have
  27. # /var/lib/iscsi/node entrys yet, not dynamic but avoids manual discovery
  28. #
  29.  
  30.  
  31. for PORTAL in ${PORTALS[@]}; do
  32.   logger -t block-iscsi `iscsiadm -m discovery -t st -p $PORTAL`
  33. done
  34.  
  35. logger -t block-iscsi "iscsiadm -m discovery -t st -p $PORTAL"
  36.  
  37. # Using the iscsi node directory we can determine the ip and port of
  38. # our iscsi target on a lun by lun basis
  39.  
  40. #  Codigo original, en debian la ruta de los nodos se crea en /etc/iscsi/nodes
  41. #  IP=`ls /var/lib/iscsi/nodes/${IQN} | cut -d , -f 1`
  42. #  PORT=`ls /var/lib/iscsi/nodes/${IQN} | cut -d , -f 2`
  43.  
  44. IP=`ls /etc/iscsi/nodes/${IQN} | cut -d , -f 1`
  45. PORT=`ls /etc/iscsi/nodes/${IQN} | cut -d , -f 2`
  46.  
  47. logger -t block-iscsi "TARGET: ${IP}:${PORT}"
  48.  
  49. # This is called by each command to determine which multipath map to use
  50. #
  51. function get_mpath_map {
  52.  
  53.    logger -t block-iscsi "Funcion multipath. Obtenemos el scsi device..."
  54.  
  55.    # Re-run multipath to ensure that maps are up to date
  56.    #
  57.    #multipath
  58.    #sleep 2
  59.  
  60.    # Now we determine which /dev/sd* device belongs to the iqn
  61.    #
  62.    logger -t block-iscsi "/bin/readlink /dev/disk/by-path/ip-${IP}:${PORT}-iscsi-${IQN}-lun-0"
  63.    logger -t block-iscsi "/dev/`/usr/bin/basename \`/bin/readlink /dev/disk/by-path/ip-${IP}:${PORT}-iscsi-${IQN}-lun-0\``"
  64.    SCSI_DEV="/dev/`basename \`/bin/readlink /dev/disk/by-path/ip-${IP}:${PORT}-iscsi-${IQN}-lun-0\``"
  65.    logger -t block-iscsi "scsi device: ${SCSI_DEV}"
  66.  
  67.    # And using the /dev/sd* device we can determine its corresponding multipath entry
  68.  
  69.    #MPATH_MAP="/dev/mapper/`multipath -ll ${SCSI_DEV} | head -1 | awk '{ print $1}'`"
  70.    #logger -t block-iscsi "mpath device: ${MPATH_MAP}"
  71.    MPATH_MAP=${SCSI_DEV}
  72. }
  73.  
  74. case $command in
  75.    add)
  76.       # Login to the target
  77.       logger -t block-iscsi "logging in to ${IQN} on ${IP}:${PORT}"
  78.       sleep 5
  79.       #FIXME needs more advanced race condition logic
  80.       iscsiadm -m node -T ${IQN} -p ${IP}:${PORT} --login | logger -t block-iscsi
  81.       sleep 5
  82.       #FIXME needs more advanced race condition logic
  83.       get_mpath_map
  84.  
  85.       if [ -a ${MPATH_MAP} ]; then
  86.          logger -t block-iscsi "${command}ing device: ${MPATH_MAP}"
  87.          write_dev ${MPATH_MAP}
  88.       fi
  89.    ;;
  90.  
  91.    remove)
  92.       get_mpath_map
  93.       logger -t block-iscsi "MPATH_MAP: ${MPATH_MAP}"
  94.  
  95.       if [ -a ${MPATH_MAP} ]; then
  96.          logger -t block-iscsi "flushing buffers on ${MPATH_MAP}"
  97.          blockdev --flushbufs ${MPATH_MAP}
  98.          logger -t block-iscsi "attempting logout of ${IQN} on ${IP}:${PORT}"
  99.          iscsiadm -m node -T ${IQN} -p ${IP}:${PORT} --logout | logger -t block-iscsi
  100.          sleep  10
  101.          #FIXME needs more advanced race condition logic
  102.       fi
  103.       sleep 5
  104.       #FIXME needs more advanced race condition logic
  105.    ;;
  106. esac
Advertisement
RAW Paste Data Copied
Advertisement