Module: tools Branch: master Commit: d5be151028e0dab3e1d323e4e6a0fc9be2061118 URL: https://source.winehq.org/git/tools.git/?a=commit;h=d5be151028e0dab3e1d323e4...
Author: Francois Gouget fgouget@codeweavers.com Date: Tue Feb 15 05:03:17 2022 +0100
testbot/LibvirtTool: Wait a bit between shutting down and reverting a VM.
Also rename ShutDown() to the more descriptive ShutDownIfOffSnapshot() and document it.
Signed-off-by: Francois Gouget fgouget@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
testbot/bin/LibvirtTool.pl | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl index a4ae7df..fad0727 100755 --- a/testbot/bin/LibvirtTool.pl +++ b/testbot/bin/LibvirtTool.pl @@ -279,7 +279,20 @@ sub GetPrivilegedTA($) return $TA->SetTime() ? $TA : $VM->GetAgent(1); }
-sub ShutDown() +=pod +=over 12 + +=item C<ShutDownIfOffSnapshot()> + +Attempt a clean shutdown of the VM if it is running a snapshot that requests +them (snapshot name containing '-off'). + +Returns 0 if the shutdown failed, 2 if it was successful and 1 if the VM was +already powered off or a shutdown was not needed. +=back +=cut + +sub ShutDownIfOffSnapshot() { my $Domain = $VM->GetDomain(); my $CurrentSnapshot = $Domain->GetSnapshotName(); @@ -310,7 +323,7 @@ sub ShutDown() { Debug(Elapsed($Start), " Successfully shut down $VMKey\n"); LogMsg "Successfully shut down $VMKey\n"; - return 1; + return 2; } sleep(1); } @@ -364,7 +377,7 @@ sub Monitor() if ($IsReady and $VM->GetDomain()->IsPoweredOn()) { # Try to perform a clean shutdown if requested - ShutDown(); + ShutDownIfOffSnapshot();
my $ErrMessage = $VM->GetDomain()->PowerOff(); if (defined $ErrMessage) @@ -390,7 +403,7 @@ sub Monitor() sub PowerOff() { # Try to perform a clean shutdown if requested - ShutDown(); + ShutDownIfOffSnapshot();
# Power off the VM no matter what its initial status is $CurrentStatus = $VM->Status; @@ -430,7 +443,7 @@ sub CheckOff() if ($SnapshotName eq $VM->IdleSnapshot) { # Try to perform a clean shutdown if requested - ShutDown(); + ShutDownIfOffSnapshot();
my $ErrMessage = $VM->GetDomain()->PowerOff(); FatalError("$ErrMessage\n") if (defined $ErrMessage); @@ -611,8 +624,10 @@ sub Revert() $VM->Save(); }
- # Before reverting, try to perform a clean shutdown if requested - ShutDown(); + # Before reverting, try to perform a clean shutdown if requested. + # After a shutdown a small wait is also sometimes required, at least when + # switching from a PCI-passthrough configuration to a regular one. + sleep(1) if (ShutDownIfOffSnapshot() == 2);
# Revert the VM (and power it on if necessary) Debug(Elapsed($Start), " Reverting $VMKey to $DomainSnapshot\n");