Francois Gouget : testbot/LibvirtTool: Separate ShutDown() from ShutDownIfOffSnapshot().

Alexandre Julliard julliard at winehq.org
Wed Feb 23 15:58:45 CST 2022


Module: tools
Branch: master
Commit: d342cd997cb100a124baa776d046a3f1653d9ff0
URL:    https://source.winehq.org/git/tools.git/?a=commit;h=d342cd997cb100a124baa776d046a3f1653d9ff0

Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Wed Feb 23 15:55:37 2022 +0100

testbot/LibvirtTool: Separate ShutDown() from ShutDownIfOffSnapshot().

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 at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 6364b30..759d8ec 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;
 }
 




More information about the wine-cvs mailing list