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)