From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Avihai Horon" <avihaih@nvidia.com>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Peter Xu" <peterx@redhat.com>,
"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 06/27] migration: Propagate errors in migration_completion_precopy()
Date: Tue, 7 Jul 2026 08:28:59 +0200 [thread overview]
Message-ID: <20260707062920.317302-7-clg@redhat.com> (raw)
In-Reply-To: <20260707062920.317302-1-clg@redhat.com>
From: Avihai Horon <avihaih@nvidia.com>
migration_completion_precopy() doesn't propagate errors to migration
core which leads to error information loss. Fix that.
This prepares for a follow-up where migration_switchover_start() can
fail on switchover-ack and still report a useful error.
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Link: https://lore.kernel.org/qemu-devel/20260706085211.13905-2-avihaih@nvidia.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
migration/savevm.h | 2 +-
migration/migration.c | 13 ++++++++-----
migration/savevm.c | 29 +++++++++++++++++------------
3 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/migration/savevm.h b/migration/savevm.h
index 96fdf96d4ef6f7fd174f50e8c1402f0b6d6b9e1f..b6bb4fa977fae84ed121b0668cdefdf49e3d9c67 100644
--- a/migration/savevm.h
+++ b/migration/savevm.h
@@ -44,7 +44,7 @@ void qemu_savevm_state_header(QEMUFile *f);
int qemu_savevm_state_iterate(QEMUFile *f, bool postcopy);
void qemu_savevm_state_cleanup(void);
void qemu_savevm_state_complete_postcopy(QEMUFile *f);
-int qemu_savevm_state_complete_precopy(MigrationState *s);
+int qemu_savevm_state_complete_precopy(MigrationState *s, Error **errp);
void qemu_savevm_query_pending(MigPendingData *pending, bool exact);
int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy);
bool qemu_savevm_state_postcopy_prepare(QEMUFile *f, Error **errp);
diff --git a/migration/migration.c b/migration/migration.c
index 0f56432d903054883679a66ac5bd853577b5df66..7e0a0bea7ae823ee5ef6e7ba8876c9222f9ac834 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2820,7 +2820,7 @@ static bool migration_switchover_start(MigrationState *s, Error **errp)
return true;
}
-static int migration_completion_precopy(MigrationState *s)
+static int migration_completion_precopy(MigrationState *s, Error **errp)
{
int ret;
@@ -2829,16 +2829,17 @@ static int migration_completion_precopy(MigrationState *s)
if (!migrate_mode_is_cpr()) {
ret = migration_stop_vm(s, RUN_STATE_FINISH_MIGRATE);
if (ret < 0) {
+ error_setg_errno(errp, -ret, "Failed to stop the VM");
goto out_unlock;
}
}
- if (!migration_switchover_start(s, NULL)) {
+ if (!migration_switchover_start(s, errp)) {
ret = -EFAULT;
goto out_unlock;
}
- ret = qemu_savevm_state_complete_precopy(s);
+ ret = qemu_savevm_state_complete_precopy(s, errp);
out_unlock:
bql_unlock();
return ret;
@@ -2875,7 +2876,7 @@ static void migration_completion(MigrationState *s)
Error *local_err = NULL;
if (s->state == MIGRATION_STATUS_ACTIVE) {
- ret = migration_completion_precopy(s);
+ ret = migration_completion_precopy(s, &local_err);
} else if (s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE) {
migration_completion_postcopy(s);
} else {
@@ -2906,7 +2907,9 @@ static void migration_completion(MigrationState *s)
return;
fail:
- if (qemu_file_get_error_obj(s->to_dst_file, &local_err)) {
+ if (local_err) {
+ migrate_error_propagate(s, local_err);
+ } else if (qemu_file_get_error_obj(s->to_dst_file, &local_err)) {
migrate_error_propagate(s, local_err);
} else if (ret) {
error_setg_errno(&local_err, -ret, "Error in migration completion");
diff --git a/migration/savevm.c b/migration/savevm.c
index 23adaf9dd9263b8dafe808f0637724fe4a5482b2..7e2a0c2b4a7470d9c2159eac1d18ae891740fe3e 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1771,28 +1771,34 @@ int qemu_savevm_state_non_iterable(QEMUFile *f, Error **errp)
return 0;
}
-int qemu_savevm_state_complete_precopy(MigrationState *s)
+int qemu_savevm_state_complete_precopy(MigrationState *s, Error **errp)
{
+ ERRP_GUARD();
QEMUFile *f = s->to_dst_file;
- Error *local_err = NULL;
int ret;
ret = qemu_savevm_state_complete_precopy_iterable(f, false);
if (ret) {
+ qemu_file_get_error_obj(f, errp);
+ error_prepend(errp, "Failed to save iterable device state: ");
return ret;
}
- /* TODO: pass error upper */
- ret = qemu_savevm_state_non_iterable(f, &local_err);
+ ret = qemu_savevm_state_non_iterable(f, errp);
if (ret) {
- migrate_error_propagate(s, error_copy(local_err));
- error_report_err(local_err);
return ret;
}
qemu_savevm_state_end_precopy(s, f);
- return qemu_fflush(f);
+ ret = qemu_fflush(f);
+ if (ret) {
+ qemu_file_get_error_obj(f, errp);
+ error_prepend(errp, "Failed to flush QEMUFile: ");
+ return ret;
+ }
+
+ return 0;
}
void qemu_savevm_query_pending(MigPendingData *pending, bool exact)
@@ -1874,13 +1880,12 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
}
ret = qemu_file_get_error(f);
- if (ret == 0) {
- qemu_savevm_state_complete_precopy(ms);
- ret = qemu_file_get_error(f);
- }
- if (ret != 0) {
+ if (ret) {
error_setg_errno(errp, -ret, "Error while writing VM state");
+ goto cleanup;
}
+
+ ret = qemu_savevm_state_complete_precopy(ms, errp);
cleanup:
qemu_savevm_state_cleanup();
--
2.54.0
next prev parent reply other threads:[~2026-07-07 6:31 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 6:28 [PULL 00/27] vfio queue Cédric Le Goater
2026-07-07 6:28 ` [PULL 01/27] vfio/pci: Initialize rom_read_failed in vfio_pci_load_rom() Cédric Le Goater
2026-07-07 6:28 ` [PULL 02/27] vfio/pci: Fix information leak in vfio_rom_read() Cédric Le Goater
2026-07-07 6:28 ` [PULL 03/27] docs: Update vfio-user spec to describe DMA access mode bits Cédric Le Goater
2026-07-07 6:28 ` [PULL 04/27] vfio-user: validate VERSION replies Cédric Le Goater
2026-07-07 6:28 ` [PULL 05/27] vfio/iommufd: Merge .dma_map_file() into .dma_map() Cédric Le Goater
2026-07-07 6:28 ` Cédric Le Goater [this message]
2026-07-07 6:29 ` [PULL 07/27] migration/ram: Use migration_bitmap_sync_precopy() for postcopy discard Cédric Le Goater
2026-07-07 6:29 ` [PULL 08/27] migration: Run final save_query_pending at switchover Cédric Le Goater
2026-07-07 6:29 ` [PULL 09/27] migration: Log the approver in qemu_loadvm_approve_switchover() Cédric Le Goater
2026-07-07 6:29 ` [PULL 10/27] migration: Replace switchover_ack_needed SaveVMHandler Cédric Le Goater
2026-07-07 6:29 ` [PULL 11/27] migration: Rename switchover-ack code to legacy Cédric Le Goater
2026-07-07 6:29 ` [PULL 12/27] migration: Make switchover-ack re-usable Cédric Le Goater
2026-07-07 6:29 ` [PULL 13/27] migration: Fail migration if switchover-ack is requested after switchover decision Cédric Le Goater
2026-07-07 6:29 ` [PULL 14/27] vfio/migration: Extract VFIO_MIG_FLAG_DEV_INIT_DATA_SENT sending to helper Cédric Le Goater
2026-07-07 6:29 ` [PULL 15/27] vfio/migration: Add Error ** parameter to vfio_migration_init() Cédric Le Goater
2026-07-07 6:29 ` [PULL 16/27] vfio/migration: Add new switchover-ack mechanism Cédric Le Goater
2026-07-07 6:29 ` [PULL 17/27] vfio/migration: Implement VFIO_PRECOPY_INFO_REINIT feature Cédric Le Goater
2026-07-07 6:29 ` [PULL 18/27] vfio/migration: Check VFIO_PRECOPY_INFO_REINIT during switchover Cédric Le Goater
2026-07-07 6:29 ` [PULL 19/27] migration: Enable new switchover-ack Cédric Le Goater
2026-07-07 6:29 ` [PULL 20/27] migration: Refactor migration_completion_precopy() to return bool Cédric Le Goater
2026-07-07 6:29 ` [PULL 21/27] migration: Fix "switchover" used as a verb in comments and docs Cédric Le Goater
2026-07-07 6:29 ` [PULL 22/27] iommufd: Introduce handler for device ATS support Cédric Le Goater
2026-07-07 6:29 ` [PULL 23/27] vfio/pci: Add ats property Cédric Le Goater
2026-07-07 6:29 ` [PULL 24/27] vfio/pci: Propagate errors in vfio_pci_load_rom() using Error API Cédric Le Goater
2026-07-07 6:29 ` [PULL 25/27] vfio/listener: Fix translated_addr for non-identity-mapped RAM sections Cédric Le Goater
2026-07-07 6:29 ` [PULL 26/27] backends/iommufd: Fix dev_id and type order in viommu trace Cédric Le Goater
2026-07-07 6:29 ` [PULL 27/27] vfio/pci: Reject invalid MSI-X Table and PBA BIR values Cédric Le Goater
2026-07-08 5:53 ` [PULL 00/27] vfio queue Stefan Hajnoczi
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=20260707062920.317302-7-clg@redhat.com \
--to=clg@redhat.com \
--cc=avihaih@nvidia.com \
--cc=peterx@redhat.com \
--cc=philmd@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.