]> git.proxmox.com Git - qemu-server.git/commitdiff
backup, migrate: fix races with suspended VMs that can wake up
authorFilip Schauer <f.schauer@proxmox.com>
Fri, 13 Oct 2023 13:50:06 +0000 (15:50 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 16 Oct 2023 14:48:47 +0000 (16:48 +0200)
Fix races with ACPI-suspended VMs which could wake up during migration
or during a suspend-mode backup.

Revert prevention, of ACPI-suspended VMs automatically resuming after
migration, introduced by 7ba974a6828d. The commit introduced a
potential problem that causes a suspended VM that wakes up during
migration to remain paused after the migration finishes.

This can be fixed once QEMU preserves the 'suspended' runstate during
migration (current patch on the qemu-devel list [0]) by checking for
the 'suspended' runstate on the target after migration.

Furthermore the commit increased the race window during the
preparation of a suspend-mode backup, when a suspended VM wakes up
between the vm_is_paused check in PVE::VZDump::QemuServer::prepare and
PVE::VZDump::QemuServer::qga_fs_freeze. This causes the code to skip
fs-freeze even if the VM has woken up, potentially leaving the file
system in an inconsistent state.

To prevent this, do not treat the suspended runstate as paused when
migrating or archiving a VM.

[0]: https://lists.nongnu.org/archive/html/qemu-devel/2023-08/msg05260.html

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
 [ TL: massage in Fiona's extra info into commit message ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Qemu.pm
PVE/QemuMigrate.pm
PVE/QemuServer.pm
PVE/VZDump/QemuServer.pm

index 9877ce24a9b7e2e581d894881787e29aa51657d2..38bdaabd26e9c3dadbf4279b255bcaf46f2ca93a 100644 (file)
@@ -3084,7 +3084,7 @@ __PACKAGE__->register_method({
 
        # sending a graceful shutdown command to paused VMs runs into timeouts, and even worse, when
        # the VM gets resumed later, it still gets the request delivered and powers off
-       if (PVE::QemuServer::vm_is_paused($vmid)) {
+       if (PVE::QemuServer::vm_is_paused($vmid, 1)) {
            if ($param->{forceStop}) {
                warn "VM is paused - stop instead of shutdown\n";
                $shutdown = 0;
@@ -3160,7 +3160,7 @@ __PACKAGE__->register_method({
        my $node = extract_param($param, 'node');
        my $vmid = extract_param($param, 'vmid');
 
-       die "VM is paused - cannot shutdown\n" if PVE::QemuServer::vm_is_paused($vmid);
+       die "VM is paused - cannot shutdown\n" if PVE::QemuServer::vm_is_paused($vmid, 1);
 
        die "VM $vmid not running\n" if !PVE::QemuServer::check_running($vmid);
 
index f41c61f71f3c997d874f653005890a432daa0436..111eeb07e8425b515665df15be9ea5969bb1dff9 100644 (file)
@@ -224,7 +224,9 @@ sub prepare {
            }
        }
 
-       $self->{vm_was_paused} = 1 if PVE::QemuServer::vm_is_paused($vmid);
+       # Do not treat a suspended VM as paused, as it might wake up
+       # during migration and remain paused after migration finishes.
+       $self->{vm_was_paused} = 1 if PVE::QemuServer::vm_is_paused($vmid, 0);
     }
 
     my ($loc_res, $mapped_res, $missing_mappings_by_node) = PVE::QemuServer::check_local_resources($conf, 1);
index 28956755b4d9a1b5f1de473faa400ee5a9a61cd5..2cd894859b5b7568ca4d4d3b026eea9bfdec7255 100644 (file)
@@ -8497,7 +8497,7 @@ sub complete_migration_storage {
 }
 
 sub vm_is_paused {
-    my ($vmid) = @_;
+    my ($vmid, $include_suspended) = @_;
     my $qmpstatus = eval {
        PVE::QemuConfig::assert_config_exists_on_node($vmid);
        mon_cmd($vmid, "query-status");
@@ -8505,8 +8505,8 @@ sub vm_is_paused {
     warn "$@\n" if $@;
     return $qmpstatus && (
        $qmpstatus->{status} eq "paused" ||
-       $qmpstatus->{status} eq "suspended" ||
-       $qmpstatus->{status} eq "prelaunch"
+       $qmpstatus->{status} eq "prelaunch" ||
+       ($include_suspended && $qmpstatus->{status} eq "suspended")
     );
 }
 
index b38d7e741d32b655dcc17f75deac704776859531..f811cbf22fd673134bc5f5c6e289d29d092ce3b6 100644 (file)
@@ -67,7 +67,9 @@ sub prepare {
     $self->{vm_was_paused} = 0;
     if (!PVE::QemuServer::check_running($vmid)) {
        $self->{vm_was_running} = 0;
-    } elsif (PVE::QemuServer::vm_is_paused($vmid)) {
+    } elsif (PVE::QemuServer::vm_is_paused($vmid, 0)) {
+       # Do not treat a suspended VM as paused, as it would cause us to skip
+       # fs-freeze even if the VM wakes up before we reach qga_fs_freeze.
        $self->{vm_was_paused} = 1;
     }