Module: tools
Branch: master
Commit: 00a592969c037ef88c6a7865d3f86dc629a8a4aa
URL: https://source.winehq.org/git/tools.git/?a=commit;h=00a592969c037ef88c6a786…
Author: Francois Gouget <fgouget(a)codeweavers.com>
Date: Wed Feb 23 15:55:40 2022 +0100
testbot/LibvirtTool: Allow taking powered off snapshots.
Signed-off-by: Francois Gouget <fgouget(a)codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard(a)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")
{
Module: tools
Branch: master
Commit: d342cd997cb100a124baa776d046a3f1653d9ff0
URL: https://source.winehq.org/git/tools.git/?a=commit;h=d342cd997cb100a124baa77…
Author: Francois Gouget <fgouget(a)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(a)codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard(a)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;
}