bf143f
From 34eae2d7ef928a7e0e10cc30fe76839c005998eb Mon Sep 17 00:00:00 2001
bf143f
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
bf143f
Date: Wed, 13 Apr 2022 12:33:29 +0100
bf143f
Subject: [PATCH 07/11] migration: Read state once
bf143f
bf143f
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
bf143f
RH-MergeRequest: 249: migration: Read state once
bf143f
RH-Bugzilla: 2074205
bf143f
RH-Acked-by: Peter Xu <peterx@redhat.com>
bf143f
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
bf143f
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
bf143f
RH-Acked-by: quintela1 <quintela@redhat.com>
bf143f
RH-Commit: [1/1] 9aa47b492a646fce4e66ebd9b7d7a85286d16051
bf143f
bf143f
The 'status' field for the migration is updated normally using
bf143f
an atomic operation from the migration thread.
bf143f
Most readers of it aren't that careful, and in most cases it doesn't
bf143f
matter.
bf143f
bf143f
In query_migrate->fill_source_migration_info the 'state'
bf143f
is read twice; the first time to decide which state fields to fill in,
bf143f
and then secondly to copy the state to the status field; that can end up
bf143f
with a status that's inconsistent; e.g. setting up the fields
bf143f
for 'setup' and then having an 'active' status.  In that case
bf143f
libvirt gets upset by the lack of ram info.
bf143f
The symptom is:
bf143f
   libvirt.libvirtError: internal error: migration was active, but no RAM info was set
bf143f
bf143f
Read the state exactly once in fill_source_migration_info.
bf143f
bf143f
This is a possible fix for:
bf143f
https://bugzilla.redhat.com/show_bug.cgi?id=2074205
bf143f
bf143f
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
bf143f
Message-Id: <20220413113329.103696-1-dgilbert@redhat.com>
bf143f
Reviewed-by: Juan Quintela <quintela@redhat.com>
bf143f
Reviewed-by: Peter Xu <peterx@redhat.com>
bf143f
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
bf143f
(cherry picked from commit 552de79bfdd5e9e53847eb3c6d6e4cd898a4370e)
bf143f
---
bf143f
 migration/migration.c | 5 +++--
bf143f
 1 file changed, 3 insertions(+), 2 deletions(-)
bf143f
bf143f
diff --git a/migration/migration.c b/migration/migration.c
bf143f
index 51e6726dac..d8b24a2c91 100644
bf143f
--- a/migration/migration.c
bf143f
+++ b/migration/migration.c
bf143f
@@ -1071,6 +1071,7 @@ static void populate_disk_info(MigrationInfo *info)
bf143f
 static void fill_source_migration_info(MigrationInfo *info)
bf143f
 {
bf143f
     MigrationState *s = migrate_get_current();
bf143f
+    int state = qatomic_read(&s->state);
bf143f
     GSList *cur_blocker = migration_blockers;
bf143f
 
bf143f
     info->blocked_reasons = NULL;
bf143f
@@ -1090,7 +1091,7 @@ static void fill_source_migration_info(MigrationInfo *info)
bf143f
     }
bf143f
     info->has_blocked_reasons = info->blocked_reasons != NULL;
bf143f
 
bf143f
-    switch (s->state) {
bf143f
+    switch (state) {
bf143f
     case MIGRATION_STATUS_NONE:
bf143f
         /* no migration has happened ever */
bf143f
         /* do not overwrite destination migration status */
bf143f
@@ -1135,7 +1136,7 @@ static void fill_source_migration_info(MigrationInfo *info)
bf143f
         info->has_status = true;
bf143f
         break;
bf143f
     }
bf143f
-    info->status = s->state;
bf143f
+    info->status = state;
bf143f
 }
bf143f
 
bf143f
 typedef enum WriteTrackingSupport {
bf143f
-- 
bf143f
2.37.3
bf143f