#!/bin/bash # Vikram Khatri (vikram.khatri@us.ibm.com) # Check SCSI-3 PR Registration and Reservation # # ./validatePR reserve /dev/sde 6 # # ./validatePR release /dev/sde 6 # Type Description # 0 Obsolete # 1 Write exclusive # 2 Obsolete # 3 Exclusive Access # 4 Obsolete # 5 Write Exclusive, registrants only # 6 Exclusive Access, registrants only # 7 Write Exclusive, all registrants # 8 Exclusive Access, all registrants # 9-15 Obsolete if [ "$#" != "2" ]; then echo "Usage: $0 diskdevice scsiprtype" 1>&2 echo "Usage: $0 /dev/sdg 7" 1>&2 exit 1 fi ddevice=$1 sprtype=$2 if [ ! -f /usr/bin/sg_persist ] ; then echo "Cannot locate sg_persist. Install sg3utils. Exiting..." 1>&2 exit 1 fi if [ -f /usr/sbin/rsct/bin/lsnodeid ] ; then key=`/usr/sbin/rsct/bin/lsnodeid` else key=$(gethostip -x $(uname -n)) fi echo "=============================================================" echo "disk device=${ddevice} key=${key} prtype=${sprtype}" echo "=============================================================" echo -n "Check the state of the disk ............. " sg_persist -d ${ddevice} --in --read-keys > /tmp/sgp.txt if [ $? -eq 0 ] ; then echo " Success" KEYS=$(sg_persist -i -k -d $ddevice | grep -E "^[\t ]*0x.*" | sed -e 's/^ *//') for ik in $KEYS do sg_persist -d ${ddevice} --out -C -K $ik > /dev/null done else echo " Failure RC=$?" echo "=============================================================" cat < /tmp/sgp.txt echo "=============================================================" exit 1 fi echo -n "Check if registration succeeds .......... " sg_persist -d ${ddevice} --out --register --param-sark=${key} > /tmp/sgp.txt if [ $? -eq 0 ] ; then echo " Success" echo -n "Check if reservation succeeds ........... " sg_persist -d ${ddevice} --out --reserve --param-rk=${key} --prout-type=${sprtype} > /tmp/sgp.txt if [ $? -eq 0 ] ; then echo " Success" echo -n "Check if release succeeds ............... " sg_persist -d ${ddevice} --out --release --param-rk=${key} --prout-type=${sprtype} > /tmp/sgp.txt if [ $? -eq 0 ] ; then echo " Success" echo -n "Check if registration can be removed .... " sg_persist -d ${ddevice} --out --register --param-rk=${key} --param-sark=0 > /tmp/sgp.txt if [ $? -eq 0 ] ; then echo " Success" else echo " Failure RC=$?" echo "=============================================================" cat < /tmp/sgp.txt echo "=============================================================" fi else echo " Failure RC=$?" echo "=============================================================" cat < /tmp/sgp.txt echo "=============================================================" fi else echo " Failure RC=$?" echo "=============================================================" cat < /tmp/sgp.txt echo "=============================================================" fi else echo " Failure RC=$?" echo "=============================================================" cat < /tmp/sgp.txt echo "=============================================================" fi echo -n "Check the state of the disk ............. " sg_persist -d ${ddevice} --in --read-keys > /tmp/sgp.txt if [ $? -eq 0 ] ; then echo " Success" else echo " Failure RC=$?" echo "=============================================================" cat < /tmp/sgp.txt fi echo "============================================================="