Commit b2cbd3d0f9 for qemu.org

commit b2cbd3d0f92a3b1ff311129c85ad6188cdfbb671
Author: Lukas Straub <lukasstraub2@web.de>
Date:   Mon Mar 2 12:45:34 2026 +0100

    colo: Use file lock in primary_vm_do_failover()

    Take the file lock since s->to_dst_file and s->rp_state.from_dst_file
    may be changed in the migration thread.

    Signed-off-by: Lukas Straub <lukasstraub2@web.de>
    Reviewed-by: Peter Xu <peterx@redhat.com>
    Link: https://lore.kernel.org/qemu-devel/20260302-colo_unit_test_multifd-v11-19-d653fb3b1d80@web.de
    Signed-off-by: Fabiano Rosas <farosas@suse.de>

diff --git a/migration/colo.c b/migration/colo.c
index ce02c71d88..dc47d03874 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -173,11 +173,13 @@ static void primary_vm_do_failover(void)
      * The s->rp_state.from_dst_file and s->to_dst_file may use the
      * same fd, but we still shutdown the fd for twice, it is harmless.
      */
-    if (s->to_dst_file) {
-        qemu_file_shutdown(s->to_dst_file);
-    }
-    if (s->rp_state.from_dst_file) {
-        qemu_file_shutdown(s->rp_state.from_dst_file);
+    WITH_QEMU_LOCK_GUARD(&s->qemu_file_lock) {
+        if (s->to_dst_file) {
+            qemu_file_shutdown(s->to_dst_file);
+        }
+        if (s->rp_state.from_dst_file) {
+            qemu_file_shutdown(s->rp_state.from_dst_file);
+        }
     }

     old_state = failover_set_state(FAILOVER_STATUS_ACTIVE,