@samitouri / QOSamiQemu / commits / 663692f0a3

colo: Setup ram cache in normal migration path

Since 121ccedc2b migration: block incoming colo when capability is disabled x-colo capability needs to be always enabled on the incoming side. So migration_incoming_colo_enabled() and migrate_colo() are equivalent with migrate_colo() being easier to reason about since it is always true during the whole migration. Use migrate_colo() to initialize the ram cache in the normal migration path. Reviewed-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: Peter Xu <peterx@redhat.com> Signed-off-by: Lukas Straub <lukasstraub2@web.de> Link: https://lore.kernel.org/qemu-devel/20260302-colo_unit_test_multifd-v11-3-d653fb3b1d80@web.de Signed-off-by: Fabiano Rosas <farosas@suse.de>

Lukas Straub committed Mar 2, 2026 at 12:43 UTC 663692f0a30c3fb525f2d81883db231ea1a5d402
2 files changed +15 -17
migration/migration.c
+14 -4
@@ -630,10 +630,6 @@ int migration_incoming_enable_colo(Error **errp)
630 return -EINVAL;
631 }
632
633 - if (ram_block_discard_disable(true)) {
634 - error_setg(errp, "COLO: cannot disable RAM discard");
635 - return -EBUSY;
636 - }
633 migration_colo_enabled = true;
634 return 0;
635 }
@@ -770,6 +766,20 @@ process_incoming_migration_co(void *opaque)
766
767 assert(mis->from_src_file);
768
769 + if (migrate_colo()) {
770 + if (ram_block_discard_disable(true)) {
771 + error_setg(&local_err, "COLO: cannot disable RAM discard");
772 + goto fail;
773 + }
774 +
775 + ret = colo_init_ram_cache(&local_err);
776 + if (ret) {
777 + error_prepend(&local_err, "failed to init colo RAM cache: %d: ",
778 + ret);
779 + goto fail;
780 + }
781 + }
782 +
783 mis->largest_page_size = qemu_ram_pagesize_largest();
784 postcopy_state_set(POSTCOPY_INCOMING_NONE);
785 migrate_set_state(&mis->state, MIGRATION_STATUS_SETUP,
migration/savevm.c
+1 -13
@@ -2427,19 +2427,7 @@ static int loadvm_process_enable_colo(MigrationIncomingState *mis,
2427 Error **errp)
2428 {
2429 ERRP_GUARD();
2430 - int ret;
2431 -
2432 - ret = migration_incoming_enable_colo(errp);
2433 - if (ret < 0) {
2434 - return ret;
2435 - }
2436 -
2437 - ret = colo_init_ram_cache(errp);
2438 - if (ret) {
2439 - error_prepend(errp, "failed to init colo RAM cache: %d: ", ret);
2440 - migration_incoming_disable_colo();
2441 - }
2442 - return ret;
2430 + return migration_incoming_enable_colo(errp);
2431 }
2432
2433 static int loadvm_postcopy_handle_switchover_start(Error **errp)