#!/usr/bin/ksh93
################################################################
####
#### Program: mapluns.sh
####
#### Description: The purpose of this script is to map the
#### disks from a VIO server to their respective virtual SCSI
#### slot numbers, virtual adapters, and LDEV numbers.
####
#### This script is intended to be run on a VIO server in the
#### "oem_setup_env" environment. The output from this script
#### is a table of information containing the name of the VIO
#### server, hdisk name, virtual adapter name, virtual slot
#### number, and the SAN LDEV ID.
####
#### Author: Dana French
####         (Copyright 2005)
####
#### Date: 08/10/2005
####  
################################################################

IFS=$'\n'
LSMAP=( $( /usr/ios/cli/ioscli lsmap -all ) )
HOSTID=$( hostname )
HDISK=""  VHOST=""  VSLOT=""  LDEV=""  

print -u 2 "# hostname:hdisk:vadapter:vslot:ldev:"

for MAPLN in "${LSMAP[@]//Backing device/BackingDevice}"
do

  [[ "_${MAPLN}" != _@(vhost|BackingDevice)* ]] && continue

  if [[ "_${MAPLN}" = _vhost* ]]
  then
    VHOST=${MAPLN%%[$' \t']*}
    VHOST=${VHOST#*[$' \t']}
    VSLOT=${MAPLN##*-}
    VSLOT=${VSLOT%%[$' \t']*}
    continue
  fi

  HDISK=${MAPLN##*[$' \t']}
  TMPDISK="${HDISK}"

  if [[ "_${TMPDISK}" = _dlmfdrv* ]]
  then
    TMPDISK=$( /usr/DynamicLinkManager/bin/dlnkmgr view -drv |
       grep "${TMPDISK}" |
       awk '{ print $3 }' |
       head -1 )
  fi 

  LSCFG=( $( lscfg -vl ${TMPDISK} ) )

  for LINE in "${LSCFG[@]}"
  do
    if [[ "_${LINE}" = *\(Z1\)* ]]
    then
      LDEV=${LINE#*\(Z1\)}
      LDEV=${LDEV//./}
      LDEV=${LDEV%%[$' \t']*}
    fi   
  done

  print -u 2 "# ${HOSTID}:${HDISK}:${VHOST}:${VSLOT}:${LDEV}:"
  print "/usr/ios/cli/ioscli mkvdev -vdev ${HDISK} -vadapter ${VHOST} -dev v${HDISK}"

#   HDISK=""  VHOST=""  VSLOT=""  LDEV=""
  HDISK=""  LDEV=""

done


This file last modified 11/02/10