Monday, February 6, 2012

VIO - resolve client lpar disk to san luns

This had my head wrecked for 2 days.....

90+ dLPARs in 2 x p560 + 6 by JS23 blades and a PS701 blade all hanging off a DS3400 boot disk san and Hitachi USP-V data disk san.

Thanks to Felician Moldovan for much of the below script.

basically to resolve the mapping you have to
1. get the disk data in the client lpar
2. work out the hmc and vios servers
3. get the client lpar vscsi to vio vsci device mapping ( from the hmc )
4. get the disk data from the VIO servers
5. parse the whole damn lot into something presentable.

Still have not resolved all the issues for the IVM. Need to work out how to convert the HMC commands as hscroot into something that the IVM/VIO server in the blade can eat.

script below for your viewing pleasure. Apologies for lack of commentary within the script.

$ cat get_luns.info.ksh
#!/usr/bin/ksh
#
#
timestamp=`date +"%s"`
lpar=$1
#
get_vio_data() {
vio=$1
CTRLR1=$2
CTRLR2=$3
/usr/bin/ssh -qn uxadmin@${vio} -i key "lsdev -Cc disk -F 'name;status;description'" > ${vio}.${timestamp}.disks
/usr/bin/ssh -qn uxadmin@${vio} -i key "lspv" > ${vio}.${timestamp}.pvs
/usr/bin/ssh -qn uxadmin@${vio} -i key "/usr/ios/cli/ioscli lsmap -allgrep vhost" >${vio}.${timestamp}.maps
/usr/bin/ssh -qn uxadmin@${vio} -i key "/usr/ios/cli/ioscli lspath grep hdisk" > ${vio}.${timestamp}.paths
/usr/bin/ssh -qn uxadmin@${vio} -i key "sudo /usr/bin/mpio_get_config -Av" > ${vio}.${timestamp}.mpio
/usr/bin/ssh -qn uxadmin@${vio} -i key "sudo /usr/DynamicLinkManager/bin/dlnkmgr view -path -srt lu" > ${vio}.${timestamp}.hit
#
# determine which vhosts are interesting to this lpar and get map info for these vhosts
#
VHOST1=$(grep "C$CTRLR1" ${vio}.${timestamp}.maps awk '{print $1}' )
#echo $CTRLR1 $VHOST1
/usr/bin/ssh -qn uxadmin@${vio} -i key "/usr/ios/cli/ioscli lsmap -vadapter $VHOST1" >${vio}.${VHOST1}.${timestamp}.maps
if [ -n "$CTRLR2" ]
then
VHOST2=$(grep "C$CTRLR2" ${vio}.${timestamp}.maps awk '{print $1}')
#echo $CTRLR2 $VHOST2
/usr/bin/ssh -qn uxadmin@${vio} -i key "/usr/ios/cli/ioscli lsmap -vadapter $VHOST2" >${vio}.${VHOST2}.${timestamp}.maps
fi
}
#
get_hmc_data() # $1=HMC $2=Part of serial Number $3=LPAR_NO
{
# hmcs provide the mapping from vio host scsi controller to client lpar vscsi controller i.e. linking vscsi in client lpar to vhost in VIO server
# once we know the controller and lun on both sides and the vio-client controller mapping we can definitively state the mapping even if there is no pvid on the disk
#echo "Logging into hmc as hscroot. you will be prompted TWICE for hscroot password"
SEARCH_STRING=$2
LPAR_NO=$3
FRAME_NAME=$( /usr/bin/ssh -q hscroot@$1 -i key2 "lssyscfg -r sys -F name" grep $2)
/usr/bin/ssh -q hscroot@$1 -i key2 "lshwres -r virtualio --rsubtype scsi -m $FRAME_NAME --filter lpar_ids=" $3 " -F slot_num,remote_lpar_name,remote_slot_num" > ${HMC}.${timestamp}.ctrlr
}
#
get_lpar_data()
{
PART_SERIAL=$(uname -m cut -c4-8)
HMC=$(host $(echo $(lsrsrc IBM.ManagementServer grep Hostname head -1 awk '{print $NF}' sed -e 's/\"//g')) awk '{print $1 }')
PARTITION=$(uname -L awk '{print $1}')
HOST=$(uname -L awk '{print $2}')
#
for DISK in $(lspv awk '{print $1}')
do
echo $DISK $(lspv grep "$DISK " awk '{print $2}') $(lscfg -l $DISK awk '{print $2}' cut -d"-" -f5 cut -d"L" -f2) \
$(for VPATH in $(lspath -l $DISK awk '{print $3}')
do
echo $VPATH $(lscfg -l $VPATHawk '{print $2}' sed -e 's/-C/ /g'sed -e 's/-T/ /g' awk '{print $2" "$4}') $(lspath -l $DISK grep $VPATH awk '{print $1}')
done)>>${HOST}.${timestamp}.disks
done
#cat ${HOST}.${timestamp}.disks
}
#
merge_vio_ctrlr_info()
{
# $1 is lpar diskfile $2 is output of get_hmc_data function
while read LINE
do
VIO=$(echo $LINE cut -d"," -f2)
REM_CTRLR=$(echo $LINE cut -d"," -f3)
VHOST=$(grep "C$REM_CTRLR" ${vio}.${timestamp}.maps awk '{print $1}' )
CTRLR=$(echo $LINE cut -d"," -f1)
sed -e "s/ $CTRLR / $CTRLR $VIO $REM_CTRLR $VHOST /g" $1 >$1.tmp
mv $1.tmp $1
done<$2 #cat $1 } # get_SAN_info() { # $1 is the hdisk on the vio server to gather SAN info for # get LUN info for each disk if grep "$1 " $VIO.${timestamp}.mpio >/dev/null 2>&1
then
line=$(grep -w $1 $VIO.${timestamp}.mpio)
san=`grep "Subsystem Name" $VIO.${timestamp}.mpio cut -d\' -f2`
lun=`echo ${line} awk '{print $2}'`
else
line=$(grep -w $1 $VIO.${timestamp}.hit)
san=`echo ${line} awk '{print $5}' cut -d. -f2`
lun=`echo ${line} awk '{print $6}'`
fi
echo "$san $lun"
}
merge_fc_disk_info()
{
for VIO in $(cat ${HMC}.${timestamp}.ctrlr cut -d"," -f2 sort uniq)
do
#echo $VIO
>$1.tmp
while read LINE
do
HDISK=$(echo $LINE awk '{print $1}')
LPAR=$(hostname)
LUN=$(echo $LINE awk '{print $3}')
VHOST=$(echo $LINE awk '{print $8}')
#echo $VHOST
VHDS=$(grep -p $LUN $VIO.$VHOST.${timestamp}.maps grep -E 'VTD' awk '{print $NF}')
VHOST_FC_DISK=$(grep -p $LUN $VIO.$VHOST.${timestamp}.maps grep -E 'Backing' awk '{print $NF}')
# echo $VHOST_FC_DISK
SAN_INFO=$(get_SAN_info $VHOST_FC_DISK)
FIBRE_PATHS=$(grep "$VHOST_FC_DISK " $VIO.${timestamp}.paths awk '{print $3" "$1" "}' xargs echo)
echo $LINE $VIO $VHDS $VHOST_FC_DISK $SAN_INFO $FIBRE_PATHS >> $1.tmp
done<$1 mv $1.tmp $1 done } # get_lpar_data get_hmc_data $HMC $PART_SERIAL $PARTITION for VIO in $(cat ${HMC}.${timestamp}.ctrlr cut -d"," -f2 sort uniq) do # echo getting vio data from $VIO get_vio_data $VIO $(echo $(cat ${HMC}.${timestamp}.ctrlr grep $VIO cut -d"," -f3 sort uniq)) done merge_vio_ctrlr_info ${HOST}.${timestamp}.disks ${HMC}.${timestamp}.ctrlr merge_fc_disk_info ${HOST}.${timestamp}.disks mv ${HOST}.${timestamp}.disks diskmap.${HOST} rm *${timestamp}* while read LINE do echo $(hostname) $LINE done<diskmap.${HOST}.$(date +%Y%m%d_%H%M%S)
cat diskmap.${HOST}.$(date +%Y%m%d_%H%M%S)
rm diskmap.${HOST}.$(date +%Y%m%d_%H%M%S)
rm diskmap.${HOST}
exit 0
$

really useful site for sysadmins

http://www.tablespace.net/quicksheet/