public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Reiter <s.reiter@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server 2/2] snapshot: set migration caps before savevm-start
Date: Tue, 16 Mar 2021 17:30:23 +0100	[thread overview]
Message-ID: <20210316163023.24534-2-s.reiter@proxmox.com> (raw)
In-Reply-To: <20210316163023.24534-1-s.reiter@proxmox.com>

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>
---
 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 c58ff19..7ee8876 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 15100ed..1c0b5c2 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 f65a902..cc04f01 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");
-- 
2.20.1





  reply	other threads:[~2021-03-16 16:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-16 16:30 [pve-devel] [PATCH pve-qemu 1/2] fix saving and loading dirty bitmaps in snapshots Stefan Reiter
2021-03-16 16:30 ` Stefan Reiter [this message]
2021-03-16 19:51   ` [pve-devel] applied: [PATCH qemu-server 2/2] snapshot: set migration caps before savevm-start Thomas Lamprecht
2021-03-16 19:48 ` [pve-devel] applied: [PATCH pve-qemu 1/2] fix saving and loading dirty bitmaps in snapshots Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210316163023.24534-2-s.reiter@proxmox.com \
    --to=s.reiter@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal