From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 35A111FF0C0 for ; Wed, 18 Nov 2026 13:24:09 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 184BD216F2; Wed, 18 Nov 2026 13:24:07 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Subject: [PATCH qemu 3/3] async snapshot: keep track of savevm-end status Date: Wed, 18 Nov 2026 13:21:49 +0100 Message-ID: <20261118122359.123647-4-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118122359.123647-1-f.ebner@proxmox.com> References: <20261118122359.123647-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: 1795004642606 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.250 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: TMMQUQP5KZEYX2LQSZMPUFNXEO5LEMYJ X-Message-ID-Hash: TMMQUQP5KZEYX2LQSZMPUFNXEO5LEMYJ 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: If a snapshot ends with an error, qemu-server had no way to detect when it's safe to consider 'savevm-end' done. The result of 'query-savevm' only changes when the status is set to SAVE_STATE_DONE, not reporting the 'bytes' value anymore, and qemu-server looked at that. Keep track of the 'savevm-end' state and report it to allow distinguishing between 'savevm-end' being done or still waiting for the target file close in case of an error. Checking for an already active 'savevm-end' invocation at the beginning of qmp_savevm_end() fixes a crash: when a second 'savevm-end' QMP call came in, while a previous one was still sleeping in target_close_wait, the following assertion would trigger: > kvm: ../util/qemu-coroutine-sleep.c:77: qemu_co_sleep: \ > Assertion `prev == NULL' failed. Signed-off-by: Fiona Ebner --- migration/savevm-async.c | 13 +++++++++++++ qapi/migration.json | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/migration/savevm-async.c b/migration/savevm-async.c index 3ab0bd4539..e9037173af 100644 --- a/migration/savevm-async.c +++ b/migration/savevm-async.c @@ -60,6 +60,7 @@ static struct SnapshotState { Coroutine *co; QemuCoSleep target_close_wait; IOThread *iothread; + bool savevm_end_active; } snap_state; static bool savevm_aborted(void) @@ -77,6 +78,8 @@ SaveVMInfo *qmp_query_savevm(Error **errp) SaveVMInfo *info = g_malloc0(sizeof(*info)); struct SnapshotState *s = &snap_state; + info->savevm_end_active = s->savevm_end_active; + if (s->state != SAVE_STATE_DONE) { info->has_bytes = true; info->bytes = s->bs_pos; @@ -498,6 +501,7 @@ static void coroutine_fn wait_for_close_co(void *opaque) "qmp_savevm_end"); /* we cannot assume the snapshot finished in this case, so leave the * state alone - caller has to figure something out */ + snap_state.savevm_end_active = false; return; } } else { @@ -511,6 +515,8 @@ static void coroutine_fn wait_for_close_co(void *opaque) snap_state.state = SAVE_STATE_DONE; } + snap_state.savevm_end_active = false; + DPRINTF("savevm-end: cleanup done\n"); } @@ -521,6 +527,13 @@ void qmp_savevm_end(Error **errp) return; } + if (snap_state.savevm_end_active) { + error_setg(errp, "savevm-end handler already running"); + return; + } + + snap_state.savevm_end_active = true; + Coroutine *wait_for_close = qemu_coroutine_create(wait_for_close_co, NULL); if (snap_state.state == SAVE_STATE_ACTIVE) { diff --git a/qapi/migration.json b/qapi/migration.json index 0794a3a7a3..d7504a0d4d 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -354,11 +354,15 @@ # # @bytes: total amount of data transfered # +# @savevm-end-active: Whether a @savevm-end handler is currently +# active. +# # Since: 1.3 ## { 'struct': 'SaveVMInfo', 'data': {'*status': 'str', '*error': 'str', - '*total-time': 'int', '*bytes': 'int'} } + '*total-time': 'int', '*bytes': 'int', + 'savevm-end-active': 'bool'} } ## # @query-savevm: -- 2.47.3