From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 4E1821FF0B6 for ; Thu, 12 Nov 2026 14:46:59 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 0DF4921736; Thu, 12 Nov 2026 14:46:17 +0100 (CET) From: Fiona Ebner 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 Message-ID: <20261112134607.197439-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261112134607.197439-1-f.ebner@proxmox.com> References: <20261112134607.197439-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794491170979 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.257 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: JRRRNIOMTRDRPKL6PT6G6CGGRPKEAZER X-Message-ID-Hash: JRRRNIOMTRDRPKL6PT6G6CGGRPKEAZER X-MailFrom: f.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- ...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 Signed-off-by: Fiona Ebner [EF: drop QIOChannel reference] Signed-off-by: Erik Fastermann +[FE: defer vm_start() to qmp_savevm_end() in case of success] +Signed-off-by: Fiona Ebner --- 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