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 <s.reiter@proxmox.com>
This commit is contained in:
Stefan Reiter 2021-03-16 17:30:23 +01:00 committed by Thomas Lamprecht
parent c89642784d
commit 27a5be5376
3 changed files with 9 additions and 2 deletions

View File

@ -281,6 +281,7 @@ sub __snapshot_create_vol_snapshots_hook {
PVE::Storage::activate_volumes($storecfg, [$snap->{vmstate}]); PVE::Storage::activate_volumes($storecfg, [$snap->{vmstate}]);
my $state_storage_id = PVE::Storage::parse_volume_id($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); mon_cmd($vmid, "savevm-start", statefile => $path);
print "saving VM state and RAM using storage '$state_storage_id'\n"; print "saving VM state and RAM using storage '$state_storage_id'\n";
my $render_state = sub { my $render_state = sub {

View File

@ -4330,10 +4330,13 @@ sub qemu_volume_snapshot_delete {
} }
sub set_migration_caps { sub set_migration_caps {
my ($vmid) = @_; my ($vmid, $savevm) = @_;
my $qemu_support = eval { mon_cmd($vmid, "query-proxmox-support") }; 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 $cap_ref = [];
my $enabled_cap = { my $enabled_cap = {
@ -4342,7 +4345,7 @@ sub set_migration_caps {
"x-rdma-pin-all" => 0, "x-rdma-pin-all" => 0,
"zero-blocks" => 0, "zero-blocks" => 0,
"compress" => 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"); my $supported_capabilities = mon_cmd($vmid, "query-migrate-capabilities");
@ -5600,6 +5603,7 @@ sub vm_suspend {
PVE::Storage::activate_volumes($storecfg, [$vmstate]); PVE::Storage::activate_volumes($storecfg, [$vmstate]);
eval { eval {
set_migration_caps($vmid, 1);
mon_cmd($vmid, "savevm-start", statefile => $path); mon_cmd($vmid, "savevm-start", statefile => $path);
for(;;) { for(;;) {
my $state = mon_cmd($vmid, "query-savevm"); my $state = mon_cmd($vmid, "query-savevm");

View File

@ -380,6 +380,8 @@ sub vm_stop {
return; return;
} }
sub set_migration_caps {} # ignored
# END redefine PVE::QemuServer methods # END redefine PVE::QemuServer methods
PVE::Tools::run_command("rm -rf snapshot-working"); PVE::Tools::run_command("rm -rf snapshot-working");