ShutDown() unconditionally performs a clean shutdown while ShutDownIfOffSnapshot() only does so if the VM is currently running a snapshot that requests them (contains '-off' in its name).
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/bin/LibvirtTool.pl | 50 ++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 13 deletions(-)
diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl index 6364b306d9..759d8ec762 100755 --- a/testbot/bin/LibvirtTool.pl +++ b/testbot/bin/LibvirtTool.pl @@ -311,6 +311,35 @@ sub Halt($$) =pod =over 12
+=item C<ShutDown()> + +Attempt a clean shutdown of the VM (regardless of its current snapshot). + +Returns 0 if the shutdown failed, 1 otherwise. +=back +=cut + +sub ShutDown($$) +{ + my ($Domain, $TA) = @_; + + if (Halt($TA, 0)) + { + Debug(Elapsed($Start), " Waiting for the VM to shut down\n"); + my $Deadline = time() + $WaitForShutdown; + while (time() <= $Deadline) + { + return 1 if (!$Domain->IsPoweredOn()); + sleep(1); + } + Error "Timed out waiting for $VMKey to perform a clean shutdown\n"; + } + return 0; +} + +=pod +=over 12 + =item C<ShutDownIfOffSnapshot()>
Attempt a clean shutdown of the VM if it is running a snapshot that requests @@ -320,6 +349,8 @@ 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 +=back +=cut
sub ShutDownIfOffSnapshot() { @@ -333,22 +364,15 @@ sub ShutDownIfOffSnapshot()
Debug(Elapsed($Start), " Performing a clean shutdown of $VMKey/$CurrentSnapshot\n"); LogMsg "Performing a clean shutdown of $VMKey/$CurrentSnapshot\n"; - return 0 if (!Halt($VM->GetAgent(), 0)); - - Debug(Elapsed($Start), " Waiting for the VM to shut down\n"); - my $Deadline = time() + $WaitForShutdown; - while (time() <= $Deadline) + if (ShutDown($Domain, $VM->GetAgent())) { - if (!$Domain->IsPoweredOn()) - { - Debug(Elapsed($Start), " Successfully shut down $VMKey\n"); - LogMsg "Successfully shut down $VMKey\n"; - return 2; - } - sleep(1); + Debug(Elapsed($Start), " Successfully shut down $VMKey\n"); + LogMsg "Successfully shut down $VMKey\n"; + return 2; } - Error "Timed out waiting for $VMKey to perform a clean shutdown. Forcefully shutting down now...\n";
+ # In fact the caller will do so + Error "Forcefully shutting down $VMKey/$CurrentSnapshot now...\n"; return 0; }