Francois Gouget : testbot/LibvirtTool: Allow taking powered off snapshots.

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


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

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

testbot/LibvirtTool: Allow taking powered off snapshots.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 testbot/bin/LibvirtTool.pl | 67 +++++++++++++++++++++++++++++++---------------
 1 file changed, 46 insertions(+), 21 deletions(-)

diff --git a/testbot/bin/LibvirtTool.pl b/testbot/bin/LibvirtTool.pl
index 759d8ec..5e3e7af 100755
--- a/testbot/bin/LibvirtTool.pl
+++ b/testbot/bin/LibvirtTool.pl
@@ -610,7 +610,7 @@ sub GetSnapshotConfig($)
     {
       $Config->{locale} ||= $1; # take only the last match
     }
-    elsif ($Config->{base} =~ s/-(live|tsign|u8)$//)
+    elsif ($Config->{base} =~ s/-(live|off|tsign|u8)$//)
     {
       $Config->{$1} = 1;
     }
@@ -722,33 +722,58 @@ sub CreateSnapshot($$$$)
     }
   }
 
-  if ($Reboot)
+  if ($Config->{live})
   {
-    # A reboot is still required for some changes to take effect
-    ResetBootCount($TA);
-    Halt($TA, "reboot");
-    WaitForBoot($TA);
-    $Booting = 1;
-  }
-  if ($Booting)
-  {
-    WaitForSession($TA);
-    if ($SleepAfterBoot)
+    if ($Reboot)
+    {
+      # A reboot is still required for some changes to take effect
+      ResetBootCount($TA);
+      Halt($TA, "reboot");
+      WaitForBoot($TA);
+      $Booting = 1;
+    }
+    if ($Booting)
     {
-      Debug(Elapsed($Start), " Sleeping ${SleepAfterBoot}s for the $Config->{snapshot} snapshot\n");
-      LogMsg "Letting $VMKey settle down for the $Config->{snapshot} snapshot\n";
-      sleep($SleepAfterBoot);
+      WaitForSession($TA);
+      if ($SleepAfterBoot)
+      {
+        Debug(Elapsed($Start), " Sleeping ${SleepAfterBoot}s for the $Config->{snapshot} snapshot\n");
+        LogMsg "Letting $VMKey settle down for the $Config->{snapshot} snapshot\n";
+        sleep($SleepAfterBoot);
+      }
     }
+    CheckBootCount($TA);
+    $TA->Disconnect(); # disconnect before taking the snapshot
+  }
+  else
+  {
+    # Power off the VM for the snapshot
+    Debug(Elapsed($Start), " Shutting down $VMKey to take the $Config->{snapshot} snapshot\n");
+    ResetBootCount($TA);
+    ShutDown($Domain, $TA);
   }
-  CheckBootCount($TA);
 
-  $TA->Disconnect(); # disconnect before taking the snapshot
   Debug(Elapsed($Start), " Creating the $Config->{snapshot} snapshot\n");
   my $ErrMessage = $Domain->CreateSnapshot($Config->{snapshot});
   if (defined $ErrMessage)
   {
     FatalError("Could not create the $Config->{snapshot} snapshot on $VMKey: $ErrMessage\n");
   }
+  return 0 if ($Config->{live});
+
+  # Without this small pause Libvirt/QEmu sometimes forgets to power on the VM!
+  sleep(1);
+
+  # The VM was powered off for the snapshot but we need it to be running for
+  # Revert(). So (revert &) power it on again.
+  Debug(Elapsed($Start), " Starting $VMKey from the new $Config->{snapshot} snapshot\n");
+  ($ErrMessage, $Booting) = $Domain->RevertToSnapshot($Config->{snapshot});
+  if (defined $ErrMessage)
+  {
+    FatalError("Could not revert $VMKey to $Config->{snapshot}: $ErrMessage\n");
+  }
+  WaitForBoot($TA);
+  return 1;
 }
 
 sub Revert()
@@ -774,9 +799,10 @@ sub Revert()
     {
       FatalError("Creating locale snapshots ($Config->{locale}) is not supported for ". $VM->Type ." VMs ($VMKey)\n");
     }
-    if (!$Config->{live})
+    if ($Config->{locale} and !$Config->{live})
     {
-      FatalError("Only live snapshots can be created ($VMKey)\n");
+      # The --locale and --country changes don't persist across reboots :-(
+      FatalError("Creating non-live locale snapshots is not supported ($VMKey)\n");
     }
     if (!$Domain->HasSnapshot($Config->{base}))
     {
@@ -836,8 +862,7 @@ sub Revert()
 
   if ($Config->{create})
   {
-    CreateSnapshot($Domain, $TA, $Config, $Booting);
-    $Booting = 0;
+    $Booting = CreateSnapshot($Domain, $TA, $Config, $Booting);
 
     if ($VM->Type eq "build" or $VM->Type eq "wine")
     {




More information about the wine-cvs mailing list