From 27a5be53760e74514dbd10e642112ba90362b468 Mon Sep 17 00:00:00 2001 From: Stefan Reiter Date: Tue, 16 Mar 2021 17:30:23 +0100 Subject: [PATCH] snapshot: set migration caps before savevm-start A "savevm" call (both our async variant and the upstream sync one) use migration code internally. As such, they both expect migration capabilities to be set. This is usually not a problem, as the default set of capabilities is ok, however, it leads to differing snapshot settings if one does a snapshot after a machine has been live-migrated (as the capabilities will persist from that), which could potentially lead to discrepencies in snapshots (currently it seems to be fine, but it still makes sense to set them to safeguard against future changes). Note that we do set the "dirty-bitmaps" capability now (if query-proxmox-support reports true), which has three effects: 1) PBS dirty-bitmaps are preserved in snapshots, enabling fast-incremental backups to work after rollback (as long as no newer backups exist), including for hibernate/resume 2) snapshots taken from now on, with a QEMU version supporting bitmap migration, *might* lead to incompatibility of these snapshots with QEMU versions that don't know about bitmaps at all (i.e. < 5.0 IIRC?) - forward compatibility is still given, and all other capabilities we set go back to very old versions 3) since we now explicitly disable bitmap saving if the version doesn't report support, we avoid crashes even with not-updated QEMU versions Signed-off-by: Stefan Reiter --- PVE/QemuConfig.pm | 1 + PVE/QemuServer.pm | 8 ++++++-- test/snapshot-test.pm | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm index c58ff19f..7ee88761 100644 --- a/PVE/QemuConfig.pm +++ b/PVE/QemuConfig.pm @@ -281,6 +281,7 @@ sub __snapshot_create_vol_snapshots_hook { PVE::Storage::activate_volumes($storecfg, [$snap->{vmstate}]); my $state_storage_id = PVE::Storage::parse_volume_id($snap->{vmstate}); + PVE::QemuServer::set_migration_caps($vmid, 1); mon_cmd($vmid, "savevm-start", statefile => $path); print "saving VM state and RAM using storage '$state_storage_id'\n"; my $render_state = sub { diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 15100ed4..1c0b5c2d 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -4330,10 +4330,13 @@ sub qemu_volume_snapshot_delete { } sub set_migration_caps { - my ($vmid) = @_; + my ($vmid, $savevm) = @_; my $qemu_support = eval { mon_cmd($vmid, "query-proxmox-support") }; + my $bitmap_prop = $savevm ? 'pbs-dirty-bitmap-savevm' : 'pbs-dirty-bitmap-migration'; + my $dirty_bitmaps = $qemu_support->{$bitmap_prop} ? 1 : 0; + my $cap_ref = []; my $enabled_cap = { @@ -4342,7 +4345,7 @@ sub set_migration_caps { "x-rdma-pin-all" => 0, "zero-blocks" => 0, "compress" => 0, - "dirty-bitmaps" => $qemu_support->{'pbs-dirty-bitmap-migration'} ? 1 : 0, + "dirty-bitmaps" => $dirty_bitmaps, }; my $supported_capabilities = mon_cmd($vmid, "query-migrate-capabilities"); @@ -5600,6 +5603,7 @@ sub vm_suspend { PVE::Storage::activate_volumes($storecfg, [$vmstate]); eval { + set_migration_caps($vmid, 1); mon_cmd($vmid, "savevm-start", statefile => $path); for(;;) { my $state = mon_cmd($vmid, "query-savevm"); diff --git a/test/snapshot-test.pm b/test/snapshot-test.pm index f65a902c..cc04f01c 100644 --- a/test/snapshot-test.pm +++ b/test/snapshot-test.pm @@ -380,6 +380,8 @@ sub vm_stop { return; } +sub set_migration_caps {} # ignored + # END redefine PVE::QemuServer methods PVE::Tools::run_command("rm -rf snapshot-working");