public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu v2 1/5] async snapshot: improve disk consistency by only calling vm_start() in savevm-end handler
Date: Thu, 12 Nov 2026 14:45:35 +0100	[thread overview]
Message-ID: <20261112134607.197439-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20261112134607.197439-1-f.ebner@proxmox.com>

A snapshot with VM state is created as follows in Proxmox VE:
1. qemu-server calls savevm-start and waits for query-savevm to return
   status 'completed'.
2. process_savevm_co() runs until state saving can converge.
3. blockdevs in IO threads are flushed async as an optimization.
4. The process_savevm_finalize() bottom half is scheduled and runs.
5. The VM is stopped, which drains and flushes all IO.
6. The state is set to 'completed'.
7a. The VM is started if it was running before.
7b. qemu-server sees status 'completed'.
8. qemu-server creates all the disk snapshots.
9. qemu-server calls savevm-end.

Since vm_start() is the very next command after setting the state to
'completed', in practice, step 7a will always happen before step 8,
which is problematic for consistency. The VM should only be started
again after the disk snapshots are taken. The functionality for
restoring the run state is already in place in qmp_savevm_end(), so
rely on that.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 ...async-for-background-state-snapshots.patch | 26 +++++++++++++------
 ...add-optional-buffer-size-to-QEMUFile.patch |  6 ++---
 ...se-migration-blocker-check-for-snaps.patch |  4 +--
 3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/debian/patches/pve/0015-PVE-add-savevm-async-for-background-state-snapshots.patch b/debian/patches/pve/0015-PVE-add-savevm-async-for-background-state-snapshots.patch
index 4bc6855b2e..abd64a812a 100644
--- a/debian/patches/pve/0015-PVE-add-savevm-async-for-background-state-snapshots.patch
+++ b/debian/patches/pve/0015-PVE-add-savevm-async-for-background-state-snapshots.patch
@@ -39,19 +39,21 @@ Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
 Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
 [EF: drop QIOChannel reference]
 Signed-off-by: Erik Fastermann <e.fastermann@proxmox.com>
+[FE: defer vm_start() to qmp_savevm_end() in case of success]
+Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
 ---
  hmp-commands-info.hx         |  13 +
  hmp-commands.hx              |  27 ++
  include/migration/snapshot.h |   2 +
  include/monitor/hmp.h        |   3 +
  migration/meson.build        |   1 +
- migration/savevm-async.c     | 615 +++++++++++++++++++++++++++++++++++
+ migration/savevm-async.c     | 623 +++++++++++++++++++++++++++++++++++
  monitor/hmp-cmds.c           |  38 +++
  qapi/migration.json          |  34 ++
  qapi/misc.json               |  25 ++
  qemu-options.hx              |  12 +
  system/vl.c                  |  10 +
- 11 files changed, 780 insertions(+)
+ 11 files changed, 788 insertions(+)
  create mode 100644 migration/savevm-async.c
 
 diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
@@ -162,10 +164,10 @@ index a9d0c9cc36..1ae3779e39 100644
  ), gnutls, zlib)
 diff --git a/migration/savevm-async.c b/migration/savevm-async.c
 new file mode 100644
-index 0000000000..de69350763
+index 0000000000..12e2a5dad2
 --- /dev/null
 +++ b/migration/savevm-async.c
-@@ -0,0 +1,615 @@
+@@ -0,0 +1,623 @@
 +#include "qemu/osdep.h"
 +#include "migration/channel-savevm-async.h"
 +#include "migration/migration.h"
@@ -415,11 +417,19 @@ index 0000000000..de69350763
 +        save_snapshot_error("process_savevm_cleanup: invalid state: %d",
 +                            snap_state.state);
 +    }
-+    if (snap_state.vm_needs_start) {
-+        if (!should_skip_vm_start()) {
-+            vm_start();
++
++    /*
++     * In case of success, qemu-server still needs to create the disk snapshots
++     * while the VM is stopped. qmp_savevm_end() will restore the run state
++     * later.
++     */
++    if (snap_state.state != SAVE_STATE_COMPLETED) {
++        if (snap_state.vm_needs_start) {
++            if (!should_skip_vm_start()) {
++                vm_start();
++            }
++            snap_state.vm_needs_start = false;
 +        }
-+        snap_state.vm_needs_start = false;
 +    }
 +
 +    DPRINTF("timing: process_savevm_finalize (full) took %ld ms\n",
diff --git a/debian/patches/pve/0016-PVE-add-optional-buffer-size-to-QEMUFile.patch b/debian/patches/pve/0016-PVE-add-optional-buffer-size-to-QEMUFile.patch
index fe00188373..b3b5899a78 100644
--- a/debian/patches/pve/0016-PVE-add-optional-buffer-size-to-QEMUFile.patch
+++ b/debian/patches/pve/0016-PVE-add-optional-buffer-size-to-QEMUFile.patch
@@ -186,10 +186,10 @@ index 8f824c124d..0ffcb13921 100644
  
  G_DEFINE_AUTOPTR_CLEANUP_FUNC(QEMUFile, qemu_fclose)
 diff --git a/migration/savevm-async.c b/migration/savevm-async.c
-index de69350763..67b69bf3ac 100644
+index 12e2a5dad2..c439bc9235 100644
 --- a/migration/savevm-async.c
 +++ b/migration/savevm-async.c
-@@ -433,7 +433,7 @@ void qmp_savevm_start(const char *statefile, bool has_skip_vm_start,
+@@ -441,7 +441,7 @@ void qmp_savevm_start(const char *statefile, bool has_skip_vm_start,
  
      QIOChannel *ioc = QIO_CHANNEL(qio_channel_savevm_async_new(snap_state.target,
                                                                 &snap_state.bs_pos));
@@ -198,7 +198,7 @@ index de69350763..67b69bf3ac 100644
      object_unref(ioc);
  
      if (!snap_state.file) {
-@@ -572,7 +572,7 @@ int load_snapshot_from_blockdev(const char *filename, Error **errp)
+@@ -580,7 +580,7 @@ int load_snapshot_from_blockdev(const char *filename, Error **errp)
  
      /* restore the VM state */
      QIOChannel *ioc = QIO_CHANNEL(qio_channel_savevm_async_new(be, &bs_pos));
diff --git a/debian/patches/pve/0044-savevm-async-reuse-migration-blocker-check-for-snaps.patch b/debian/patches/pve/0044-savevm-async-reuse-migration-blocker-check-for-snaps.patch
index 76b4c23e6b..f59e52d296 100644
--- a/debian/patches/pve/0044-savevm-async-reuse-migration-blocker-check-for-snaps.patch
+++ b/debian/patches/pve/0044-savevm-async-reuse-migration-blocker-check-for-snaps.patch
@@ -136,10 +136,10 @@ index 631421c784..1d07f71a24 100644
  bool migration_in_postcopy(void);
  bool migration_postcopy_is_alive(MigrationStatus state);
 diff --git a/migration/savevm-async.c b/migration/savevm-async.c
-index 67b69bf3ac..3ab0bd4539 100644
+index c439bc9235..25d0b253e5 100644
 --- a/migration/savevm-async.c
 +++ b/migration/savevm-async.c
-@@ -399,7 +399,7 @@ void qmp_savevm_start(const char *statefile, bool has_skip_vm_start,
+@@ -407,7 +407,7 @@ void qmp_savevm_start(const char *statefile, bool has_skip_vm_start,
          return;
      }
  
-- 
2.47.3





  reply	other threads:[~2026-11-12 13:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 13:45 [PATCH-SERIES qemu/qemu-server/docs/manager v2 0/5] vm: snapshot: improve consistency and documentation Fiona Ebner
2026-11-12 13:45 ` Fiona Ebner [this message]
2026-11-12 13:45 ` [PATCH qemu-server v2 2/5] snapshot: document how consistency between multiple disks is achieved Fiona Ebner
2026-11-12 13:45 ` [PATCH docs v2 3/5] pvesm: add anchor for storage types Fiona Ebner
2026-11-12 13:45 ` [PATCH docs v2 4/5] qm: document snapshot operations Fiona Ebner
2026-11-12 13:45 ` [PATCH manager v2 5/5] ui: qemu: online help: link to new section for snapshots Fiona Ebner

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=20261112134607.197439-2-f.ebner@proxmox.com \
    --to=f.ebner@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