From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Avihai Horon" <avihaih@nvidia.com>, "Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 20/27] migration: Refactor migration_completion_precopy() to return bool
Date: Tue, 7 Jul 2026 08:29:13 +0200 [thread overview]
Message-ID: <20260707062920.317302-21-clg@redhat.com> (raw)
In-Reply-To: <20260707062920.317302-1-clg@redhat.com>
From: Avihai Horon <avihaih@nvidia.com>
migration_completion_precopy() reports its error through the Error
**errp argument, so its int return value carries no information beyond
success/failure. Convert it to return a bool, matching the common
convention.
Convert its underlying helper qemu_savevm_state_complete_precopy()
likewise, and in turn qemu_savevm_state_non_iterable(), which it calls.
Adjust all callers accordingly.
Refactor and clean migration_completion() code too, which no longer
needs to track int return values.
Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20260706085211.13905-16-avihaih@nvidia.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
migration/savevm.h | 4 ++--
migration/migration.c | 35 ++++++++++++++---------------------
migration/savevm.c | 32 +++++++++++++++-----------------
3 files changed, 31 insertions(+), 40 deletions(-)
diff --git a/migration/savevm.h b/migration/savevm.h
index 415198423f578049c209a1e40b796cfe63b410f0..f7dcdd7d1b6b7b5397eb1b6aab5cb5816a92f1a8 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, Error **errp);
+bool qemu_savevm_state_complete_precopy(MigrationState *s, Error **errp);
void qemu_savevm_query_pending_iter(MigrationState *s, MigPendingData *pending,
bool exact);
bool qemu_savevm_query_pending_final(MigrationState *s,
@@ -74,7 +74,7 @@ int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis,
Error **errp);
int qemu_load_device_state(QEMUFile *f, Error **errp);
int qemu_loadvm_approve_switchover(const char *approver);
-int qemu_savevm_state_non_iterable(QEMUFile *f, Error **errp);
+bool qemu_savevm_state_non_iterable(QEMUFile *f, Error **errp);
int qemu_savevm_state_non_iterable_early(QEMUFile *f,
JSONWriter *vmdesc,
Error **errp);
diff --git a/migration/migration.c b/migration/migration.c
index 98603ee19c34531d069400d1ab0ed36b65bb228e..7d5acd93c32393c9611731ab153b23f4bbc826a3 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2659,8 +2659,7 @@ static int postcopy_start(MigrationState *ms, Error **errp)
*/
qemu_savevm_send_postcopy_listen(fb);
- ret = qemu_savevm_state_non_iterable(fb, errp);
- if (ret) {
+ if (!qemu_savevm_state_non_iterable(fb, errp)) {
error_prepend(errp, "Postcopy save non-iterable states failed: ");
goto fail_closefb;
}
@@ -2858,22 +2857,22 @@ static bool migration_switchover_start(MigrationState *s, Error **errp)
return true;
}
-static int migration_completion_precopy(MigrationState *s, Error **errp)
+static bool migration_completion_precopy(MigrationState *s, Error **errp)
{
- int ret;
+ bool ret = false;
bql_lock();
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");
+ int r = migration_stop_vm(s, RUN_STATE_FINISH_MIGRATE);
+
+ if (r < 0) {
+ error_setg_errno(errp, -r, "Failed to stop the VM");
goto out_unlock;
}
}
if (!migration_switchover_start(s, errp)) {
- ret = -EFAULT;
goto out_unlock;
}
@@ -2910,18 +2909,17 @@ static void migration_completion_postcopy(MigrationState *s)
*/
static void migration_completion(MigrationState *s)
{
- int ret = 0;
Error *local_err = NULL;
if (s->state == MIGRATION_STATUS_ACTIVE) {
- ret = migration_completion_precopy(s, &local_err);
+ if (!migration_completion_precopy(s, &local_err)) {
+ goto fail;
+ }
} else if (s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE) {
migration_completion_postcopy(s);
} else {
- ret = -1;
- }
-
- if (ret < 0) {
+ error_setg(&local_err, "Unexpected migration completion status %s",
+ MigrationStatus_str(s->state));
goto fail;
}
@@ -2945,12 +2943,7 @@ static void migration_completion(MigrationState *s)
return;
fail:
- 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");
+ if (local_err || qemu_file_get_error_obj(s->to_dst_file, &local_err)) {
migrate_error_propagate(s, local_err);
}
@@ -3863,7 +3856,7 @@ static void *bg_migration_thread(void *opaque)
goto fail_with_bql;
}
- if (qemu_savevm_state_non_iterable(fb, &local_err)) {
+ if (!qemu_savevm_state_non_iterable(fb, &local_err)) {
error_prepend(&local_err, "Failed to save non-iterable devices ");
goto fail_with_bql;
}
diff --git a/migration/savevm.c b/migration/savevm.c
index f654a1c563df40d546e42018a3706e92fb11cfa7..bbb8d2b47c6452b228c67cbbdaacc7c333985be7 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1737,13 +1737,12 @@ void qemu_savevm_state_end_precopy(MigrationState *s, QEMUFile *f)
qemu_savevm_state_vm_desc(s, f);
}
-int qemu_savevm_state_non_iterable(QEMUFile *f, Error **errp)
+bool qemu_savevm_state_non_iterable(QEMUFile *f, Error **errp)
{
MigrationState *ms = migrate_get_current();
int64_t start_ts_each, end_ts_each;
JSONWriter *vmdesc = ms->vmdesc;
SaveStateEntry *se;
- int ret;
/* Making sure cpu states are synchronized before saving non-iterable */
cpu_synchronize_all_states();
@@ -1756,9 +1755,8 @@ int qemu_savevm_state_non_iterable(QEMUFile *f, Error **errp)
start_ts_each = qemu_clock_get_us(QEMU_CLOCK_REALTIME);
- ret = vmstate_save(f, se, vmdesc, errp);
- if (ret) {
- return ret;
+ if (vmstate_save(f, se, vmdesc, errp) < 0) {
+ return false;
}
end_ts_each = qemu_clock_get_us(QEMU_CLOCK_REALTIME);
@@ -1768,10 +1766,10 @@ int qemu_savevm_state_non_iterable(QEMUFile *f, Error **errp)
trace_vmstate_downtime_checkpoint("src-non-iterable-saved");
- return 0;
+ return true;
}
-int qemu_savevm_state_complete_precopy(MigrationState *s, Error **errp)
+bool qemu_savevm_state_complete_precopy(MigrationState *s, Error **errp)
{
ERRP_GUARD();
QEMUFile *f = s->to_dst_file;
@@ -1781,12 +1779,11 @@ int qemu_savevm_state_complete_precopy(MigrationState *s, Error **errp)
if (ret) {
qemu_file_get_error_obj(f, errp);
error_prepend(errp, "Failed to save iterable device state: ");
- return ret;
+ return false;
}
- ret = qemu_savevm_state_non_iterable(f, errp);
- if (ret) {
- return ret;
+ if (!qemu_savevm_state_non_iterable(f, errp)) {
+ return false;
}
qemu_savevm_state_end_precopy(s, f);
@@ -1795,10 +1792,10 @@ int qemu_savevm_state_complete_precopy(MigrationState *s, Error **errp)
if (ret) {
qemu_file_get_error_obj(f, errp);
error_prepend(errp, "Failed to flush QEMUFile: ");
- return ret;
+ return false;
}
- return 0;
+ return true;
}
static void qemu_savevm_query_pending(MigrationState *s,
@@ -1928,7 +1925,9 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
goto cleanup;
}
- ret = qemu_savevm_state_complete_precopy(ms, errp);
+ if (!qemu_savevm_state_complete_precopy(ms, errp)) {
+ ret = -1;
+ }
cleanup:
qemu_savevm_state_cleanup();
@@ -1962,9 +1961,8 @@ int qemu_save_device_state(QEMUFile *f, Error **errp)
return ret;
}
- ret = qemu_savevm_state_non_iterable(f, errp);
- if (ret) {
- return ret;
+ if (!qemu_savevm_state_non_iterable(f, errp)) {
+ return -1;
}
qemu_savevm_state_end(f);
--
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 ` [PULL 06/27] migration: Propagate errors in migration_completion_precopy() Cédric Le Goater
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 ` Cédric Le Goater [this message]
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-21-clg@redhat.com \
--to=clg@redhat.com \
--cc=avihaih@nvidia.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.