From 912809b0fac81d042397f67159c98b11924db30e Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Tue, 11 Aug 2015 10:48:35 -0700 Subject: [PATCH] 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 --- .../fibre_channel/fc_commands.sh | 4 ++- .../fibre_channel/invoke_fc_passthrough.sh | 29 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/provisioning_scripts/fibre_channel/fc_commands.sh b/provisioning_scripts/fibre_channel/fc_commands.sh index 534507d..818f346 100755 --- a/provisioning_scripts/fibre_channel/fc_commands.sh +++ b/provisioning_scripts/fibre_channel/fc_commands.sh @@ -36,7 +36,9 @@ ALLOWED_CMDS=" ^virsh nodedev-reattach pci_0000_[02][51]_00_[23]$ ^scp -t /tmp/$ ^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 if [[ ! $SSH_ORIGINAL_COMMAND =~ sudo ]]; then diff --git a/provisioning_scripts/fibre_channel/invoke_fc_passthrough.sh b/provisioning_scripts/fibre_channel/invoke_fc_passthrough.sh index fae4256..1f43e21 100644 --- a/provisioning_scripts/fibre_channel/invoke_fc_passthrough.sh +++ b/provisioning_scripts/fibre_channel/invoke_fc_passthrough.sh @@ -128,13 +128,40 @@ fi 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 errexit=$(set +o | grep errexit) #Ignore errors set +e let num_attached=0 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) SLOT=$(echo $pci | cut -d : -f3 | cut -d . -f1) FUNCTION=$(echo $pci | cut -d : -f3 | cut -d . -f2)