Friday 11 April 2014

Script for Setting Perennial Reservations on RDM luns

RDM's must have the perennial reservation flag set to true.

Unfortunately the four bits of info (perennial reservations setting, NAA ID, LUN_ID and Data Store Name, aren't all available from one command, so you need to do a little work.

NAAID and Perennial Reservation status:

ssh to host and run:
# esxcli storage core device list > /tmp/esxcli_reservations_naaID.txt
where you'll see the NAA id and Perennially Reserved status for all luns on that host:
naa.60060160b1b02d00559a83248cc0e311
   Display Name: DGC Fibre Channel Disk (naa.60060160b1b02d00559a83248cc0e311)
   Has Settable Display Name: false
   Size: 122880
   Device Type: Direct-Access
   Multipath Plugin: PowerPath
   Devfs Path: /vmfs/devices/disks/naa.60060160b1b02d00559a83248cc0e311
   Vendor: DGC
   Model: VRAID
   Revision: 0532
   SCSI Level: 4
   Is Pseudo: false
   Status: on
   Is RDM Capable: true
   Is Local: false
   Is Removable: false
   Is SSD: false
   Is Offline: false
   Is Perennially Reserved: false
   Queue Full Sample Size: 0
   Queue Full Threshold: 0
   Thin Provisioning Status: yes
   Attached Filters: VAAI_FILTER
   VAAI Status: supported
   Other UIDs: vml.020003000060060160b1b02d00559a83248cc0e311565241494420
   Is Local SAS Device: false
   Is Boot USB Device: false

LUN_ID and NAAID

# esxcli storage core device list | grep -C12 "Reserved: false" | grep "Path: /vmfs/devices" | cut -d. -f2 | tee /tmp/NAA_perennial_false.txt
to get the list of NAA ids of luns without perennial reservation set.

List all LUN numbers:
~ # esxcfg-mpath -l | grep "LUN:" | cut -d: -f4,5 | awk '{print $2,$3}' | sort -
u | sort -n -k2
LUN: 0
LUN: 1
LUN: 2
LUN: 3
LUN: 8
LUN: 9
LUN: 10
LUN: 11
LUN: 12
LUN: 13
LUN: 14
LUN: 15
LUN: 42
LUN: 132
LUN: 149
LUN: 151
LUN: 198
LUN: 200
LUN: 201
LUN: 202
LUN: 203
LUN: 204

NAAid and Data Store name

But most of these are VMFS datastores, which are set correctly when they have perennial reservation as false (default is correct, so don't change):

~ # esxcfg-scsidevs -m | awk '{print $1,$5}' > /tmp/esxcfg-scsidevs-m-naaID_DataStore.txt

naa.6000144000000010a0245b40d0472b3a:1 SAN_DS1
~ #

You can manually verify the RDMs and build the command below to change from False to True on RDMs:
esxcli storage core device setconfig -d naa.id --perennially-reserved=true
for example:
# esxcli storage core device setconfig -d naa.6000144000000010a0245b40d047369b --perennially-reserved=true
# esxcli storage core device setconfig -d naa.6000144000000010a0245b40d047369e --perennially-reserved=true

Or just run this script to build the commands for you:
_____________________________________________________________________________
esxcfg-scsidevs -m > /tmp/esxcfg-scsidevs-m-naaID_DataStore.txt
esxcli storage core device list | grep -C12 "Reserved: false" | \
grep "Path: /vmfs/devices" | cut -d. -f2 | while read naaID ; do
#echo "checking ${naaID} for datastore" ;
grep ${naaID} /tmp/esxcfg-scsidevs-m-naaID_DataStore.txt >/dev/null
RC=$?
if [ ${RC} != 0 ] ; then
echo -n "${naaID} does not have datastore, assuming RDM, "
echo "which needs perennial reservation set with command shown:"
echo
echo -n "esxcli storage core device setconfig -d "
echo "naa.${naaID} --perennially-reserved=true"
echo
echo
else
DataStore=`grep ${naaID} /tmp/esxcfg-scsidevs-m-naaID_DataStore.txt |\
awk '{print $1,$5}' | awk '{print $2}'`
echo -n "NAAID ${naaID} has datastore ${DataStore}, so does not need "
echo "perennial reservation changed"
fi
done
__________________________________________________________________________

Example run of script follows:

60060160b1b02d00559a83248cc0e311 does not have datastore, assuming RDM, which needs perennial reservation set with command shown:

esxcli storage core device setconfig -d  naa.60060160b1b02d00559a83248cc0e311 --perennially-reserved=true

NAAID 6000144000000010a0245b40d047339f has datastore SAN_DS1, so does not need perennial reservation changed

References:
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1016106