Hi,
We have close to 50 LUNs presented to 40 hosts at a client site. We also need to perform maintenance which will cause downtime on our core FC switch. This means there will be a massive failover and potential path thrashing due to lack of path balance on all VM hosts at once.
Here’s what we have:
ESX Server with 2 HBAs -> 4 Paths -> Fixed path policy -> Active/Active Storage Array
Each HBA has 2 paths to the Active/Active array. This means that I should be able to migrate all paths to either of these two paths on one of the HBAs.
So here’s how we do it:
#!/bin/bash
COUNTER=1
for LUN in $(esxcfg-mpath -l | grep "has 4 paths" | awk '{print $2}')
do
esxcfg-mpath --lun=${LUN} --path=$(esxcfg-mpath -q --lun=${LUN} | grep FC | awk '{print $4}' | awk '{print NR "S\t " $0}' | grep ${COUNTER}S | awk '{print $2}') --preferred
COUNT=`expr ${COUNTER} + 1`
COUNTER=${COUNT}
if [[ ${COUNTER} -gt 2 ]]
then
COUNTER="1"
fi
done
for HBA in `esxcfg-info -w | grep vmhba | awk '{print $3}' | grep -e 'vmhba\+[1-9]' -o`
do
esxcfg-rescan $HBA
done
/usr/bin/vmware-vim-cmd hostsvc/storage/refresh
In the above case what you’re seeing is a loadbalance across paths 1 and 2 of the lowest HBA number seen for each path by esxcfg-mpath (esxcfg-mpath sorts HBA-path configs from lowest HBA number to highest HBA number)
Then there is an esxcfg-rescan operation on all HBAs of the host and a storage refresh. At this point, all your paths are on the two paths of the first HBA.
If you want to take down the first HBA and move all paths to the second HBA, it’s simply a slight script modification to increment the COUNTER variable:
#!/bin/bash
COUNTER=3
for LUN in $(esxcfg-mpath -l | grep "has 4 paths" | awk '{print $2}')
do
esxcfg-mpath --lun=${LUN} --path=$(esxcfg-mpath -q --lun=${LUN} | grep FC | awk '{print $4}' | awk '{print NR "S\t " $0}' | grep ${COUNTER}S | awk '{print $2}') --preferred
COUNT=`expr ${COUNTER} + 1`
COUNTER=${COUNT}
if [[ ${COUNTER} -gt 4 ]]
then
COUNTER="3"
fi
done
for HBA in `esxcfg-info -w | grep vmhba | awk '{print $3}' | grep -e 'vmhba\+[1-9]' -o`
do
esxcfg-rescan $HBA
done
/usr/bin/vmware-vim-cmd hostsvc/storage/refresh
In this case, the paths will vary between paths 3 and 4 which represent the two paths of the second HBA listed by esxcfg-mpath.
Thanks to Duncan Epping of yellow-bricks.com for some of the code
Cheers,
Leo