From a019f0f57192fea0278da100e1c68c0223de42e5 Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Tue, 6 Oct 2015 10:06:02 -0700 Subject: [PATCH] Reattach the PCI device to host driver This patch adds the ability to do a virsh nodedev-reattach of the PCI device. This detaches the PCI device from the pci-stub to it's original host driver (lpfc) in the hope that it does a reset of the device upon reattach. Change-Id: Ib44a35820015b98e13beb628d1625a33eeafc96b --- .../fibre_channel/fc_commands.sh | 1 + .../fibre_channel/invoke_fc_passthrough.sh | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/provisioning_scripts/fibre_channel/fc_commands.sh b/provisioning_scripts/fibre_channel/fc_commands.sh index dbf5bef..534507d 100755 --- a/provisioning_scripts/fibre_channel/fc_commands.sh +++ b/provisioning_scripts/fibre_channel/fc_commands.sh @@ -33,6 +33,7 @@ ALLOWED_CMDS=" ^source keystonerc_jenkins \&\& nova list$ ^source keystonerc_jenkins \&\& nova show [a-f0-9]+-[a-f0-9]+-[a-f0-9]+-[a-f0-9]+-[a-f0-9]+$ ^virsh nodedev-dettach pci_0000_[02][51]_00_[23]$ +^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$" diff --git a/provisioning_scripts/fibre_channel/invoke_fc_passthrough.sh b/provisioning_scripts/fibre_channel/invoke_fc_passthrough.sh index 20ca57e..fae4256 100644 --- a/provisioning_scripts/fibre_channel/invoke_fc_passthrough.sh +++ b/provisioning_scripts/fibre_channel/invoke_fc_passthrough.sh @@ -143,6 +143,8 @@ for pci in $fc_pci_device; do fcoe=`mktemp --suffix=_fcoe.xml` echo $XML > $fcoe + fc_virsh_device="pci_0000_${BUS}_${SLOT}_${FUNCTION}" + scp -i $PROVIDER_KEY $fcoe $PROVIDER_USER@$HYPERVISOR:/tmp/ # Run passthrough and clean up. @@ -150,12 +152,23 @@ for pci in $fc_pci_device; do # will need to do this cleanup at the end of the job and not *before* attaching # since we won't know which ones are still in use echo $(sudo lspci | grep -i fib) - ssh -i $PROVIDER_KEY $PROVIDER_USER@$HYPERVISOR "virsh nodedev-dettach pci_0000_${BUS}_${SLOT}_${FUNCTION}" + ssh -i $PROVIDER_KEY $PROVIDER_USER@$HYPERVISOR "virsh nodedev-dettach $fc_virsh_device" detach_result=$? echo "Detach result: $detach_result" if [[ $detach_result -ne 0 ]]; then - echo "Detach failed. Trying next device..." + echo "Detach failed ($detach_result). Trying next device..." + continue + fi + + # Reattach the device to the host. + # This will hopefully reset the device + echo $(sudo lspci | grep -i fib) + ssh -i $PROVIDER_KEY $PROVIDER_USER@$HYPERVISOR "virsh nodedev-reattach $fc_virsh_device" + reattach_result=$? + echo "reattach result: $reattach_result" + if [[ $reattach_result -ne 0 ]]; then + echo "Reattach failed ($reattach_result). Trying next device..." continue fi