Add an Online check for the FC HBA

Fibre Channel devices can go into Linkdown or Offline mode after
a many times being PCI pass through to virsh domains.  We need
to make sure that the HBA we are attempting to pass through to the
virsh domain is actually in port_state="Online".  If the HBA
isn't online, then every volume attachment via that HBA will fail
100% of the time.

This patch adds a test against the requested HBA(s) and makes sure
that they are Online.  If all the requested HBA(s) are not Online,
then the script will fail.

Change-Id: Icf05bc3ed6adb842006852f1804696fc416c0d26
This commit is contained in:
Walter A. Boring IV 2015-08-11 10:48:35 -07:00 committed by Walter A. Boring IV
parent 29160e71d3
commit 912809b0fa
2 changed files with 31 additions and 2 deletions

View File

@ -36,7 +36,9 @@ ALLOWED_CMDS="
^virsh nodedev-reattach pci_0000_[02][51]_00_[23]$ ^virsh nodedev-reattach pci_0000_[02][51]_00_[23]$
^scp -t /tmp/$ ^scp -t /tmp/$
^virsh attach-device instance-[0-9a-f]* /tmp/tmp.*_fcoe.xml$ ^virsh attach-device instance-[0-9a-f]* /tmp/tmp.*_fcoe.xml$
^echo \\\$fc_pci_device$" ^echo \\\$fc_pci_device$
^systool -c fc_host -v$
^systool -c fc_host -v | grep -B12 'Online' | grep 'Class Device path' | grep '.*'$"
#Don't allow any sudo commands #Don't allow any sudo commands
if [[ ! $SSH_ORIGINAL_COMMAND =~ sudo ]]; then if [[ ! $SSH_ORIGINAL_COMMAND =~ sudo ]]; then

View File

@ -128,13 +128,40 @@ fi
echo "Found pci devices: $fc_pci_device" echo "Found pci devices: $fc_pci_device"
function is_device_online() {
fc_device=$1
# If a device is not "Online" we'll get an empty
# string as a result of the following command.
cmd="systool -c fc_host -v"
OUTPUT=$(ssh -i $PROVIDER_KEY $PROVIDER_USER@$HYPERVISOR "systool -c fc_host -v")
test_fc_online="systool -c fc_host -v | grep -B12 'Online' | grep 'Class Device path' | grep '$fc_device'"
ONLINE=$(ssh -i $PROVIDER_KEY $PROVIDER_USER@$HYPERVISOR "$test_fc_online")
echo "online result='$ONLINE'"
if [ -z "$ONLINE" ]; then
return 0;
else
return 1;
fi
}
exit_code=1 exit_code=1
errexit=$(set +o | grep errexit) errexit=$(set +o | grep errexit)
#Ignore errors #Ignore errors
set +e set +e
let num_attached=0 let num_attached=0
for pci in $fc_pci_device; do for pci in $fc_pci_device; do
echo $pci echo "Trying passthrough for $pci"
is_device_online $pci
online=$?
if [ $online -eq 1 ]; then
echo "Device($pci) is Online"
else
echo "Device($pci) is NOT Online"
# It does no good to passthrough an HBA that isn't Online.
# When an HBA goes into 'Linkdown' or 'Offline' mode, the
# host typically needs to get rebooted.
continue
fi
BUS=$(echo $pci | cut -d : -f2) BUS=$(echo $pci | cut -d : -f2)
SLOT=$(echo $pci | cut -d : -f3 | cut -d . -f1) SLOT=$(echo $pci | cut -d : -f3 | cut -d . -f1)
FUNCTION=$(echo $pci | cut -d : -f3 | cut -d . -f2) FUNCTION=$(echo $pci | cut -d : -f3 | cut -d . -f2)