Blame SOURCES/libvirt-qemu-migration-Refresh-device-information-after-transferring-state.patch

404507
From c043762bfe04d7b10030b76fae12473b031c3c0a Mon Sep 17 00:00:00 2001
404507
Message-Id: <c043762bfe04d7b10030b76fae12473b031c3c0a@dist-git>
404507
From: Peter Krempa <pkrempa@redhat.com>
404507
Date: Fri, 2 Feb 2018 11:05:00 +0100
404507
Subject: [PATCH] qemu: migration: Refresh device information after
404507
 transferring state
404507
404507
In my first approach in 4b480d10768c I overlooked the comment in
404507
qemuMigrationRunIncoming stating that during actual migration the
404507
qemuMigrationRunIncoming does not wait until the migration is complete
404507
but rather offloads that to the Finish phase of migration.
404507
404507
This means that during actual migration qemuProcessRefreshState was
404507
called prior to qemu actually transferring the full state and thus the
404507
queries did not get the correct information. The approach worked only
404507
for restore, where we wait for the migration to finish during qemu
404507
startup.
404507
404507
Fix the issue by calling qemuProcessRefreshState both from
404507
qemuProcessStart if there's no incomming migration and from
404507
qemuMigrationFinish so that the code actually works as expected.
404507
404507
(cherry picked from commit 93db7eea1b86408e02852a8c886d473f4f5007e3)
404507
404507
 https://bugzilla.redhat.com/show_bug.cgi?id=1463168
404507
---
404507
 src/qemu/qemu_migration.c |  9 +++++++++
404507
 src/qemu/qemu_process.c   | 17 ++++++++++-------
404507
 src/qemu/qemu_process.h   |  4 ++++
404507
 3 files changed, 23 insertions(+), 7 deletions(-)
404507
404507
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
404507
index a50bb7206c..0968dd62a4 100644
404507
--- a/src/qemu/qemu_migration.c
404507
+++ b/src/qemu/qemu_migration.c
404507
@@ -5351,6 +5351,15 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
404507
             goto endjob;
404507
     }
404507
 
404507
+    /* Now that the state data was transferred we can refresh the actual state
404507
+     * of the devices */
404507
+    if (qemuProcessRefreshState(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN) < 0) {
404507
+        /* Similarly to the case above v2 protocol will not be able to recover
404507
+         * from this. Let's ignore this and perhaps stuff will not break. */
404507
+        if (v3proto)
404507
+            goto endjob;
404507
+    }
404507
+
404507
     if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY)
404507
         inPostCopy = true;
404507
 
404507
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
404507
index 3bb4b14948..caf967dac5 100644
404507
--- a/src/qemu/qemu_process.c
404507
+++ b/src/qemu/qemu_process.c
404507
@@ -6080,7 +6080,7 @@ qemuProcessLaunch(virConnectPtr conn,
404507
  * function is called after a deferred migration finishes so that we can update
404507
  * state influenced by the migration stream.
404507
  */
404507
-static int
404507
+int
404507
 qemuProcessRefreshState(virQEMUDriverPtr driver,
404507
                         virDomainObjPtr vm,
404507
                         qemuDomainAsyncJob asyncJob)
404507
@@ -6121,9 +6121,6 @@ qemuProcessFinishStartup(virConnectPtr conn,
404507
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
404507
     int ret = -1;
404507
 
404507
-    if (qemuProcessRefreshState(driver, vm, asyncJob) < 0)
404507
-        goto cleanup;
404507
-
404507
     if (startCPUs) {
404507
         VIR_DEBUG("Starting domain CPUs");
404507
         if (qemuProcessStartCPUs(driver, vm, conn,
404507
@@ -6227,11 +6224,17 @@ qemuProcessStart(virConnectPtr conn,
404507
                                  VIR_DOMAIN_PAUSED_USER) < 0)
404507
         goto stop;
404507
 
404507
-    /* Keep watching qemu log for errors during incoming migration, otherwise
404507
-     * unset reporting errors from qemu log. */
404507
-    if (!incoming)
404507
+    if (!incoming) {
404507
+        /* Keep watching qemu log for errors during incoming migration, otherwise
404507
+         * unset reporting errors from qemu log. */
404507
         qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL);
404507
 
404507
+        /* Refresh state of devices from qemu. During migration this needs to
404507
+         * happen after the state information is fully transferred. */
404507
+        if (qemuProcessRefreshState(driver, vm, asyncJob) < 0)
404507
+            goto stop;
404507
+    }
404507
+
404507
     ret = 0;
404507
 
404507
  cleanup:
404507
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
404507
index cd9a720313..b383ff309b 100644
404507
--- a/src/qemu/qemu_process.h
404507
+++ b/src/qemu/qemu_process.h
404507
@@ -129,6 +129,10 @@ int qemuProcessFinishStartup(virConnectPtr conn,
404507
                              bool startCPUs,
404507
                              virDomainPausedReason pausedReason);
404507
 
404507
+int qemuProcessRefreshState(virQEMUDriverPtr driver,
404507
+                            virDomainObjPtr vm,
404507
+                            qemuDomainAsyncJob asyncJob);
404507
+
404507
 typedef enum {
404507
     VIR_QEMU_PROCESS_STOP_MIGRATED      = 1 << 0,
404507
     VIR_QEMU_PROCESS_STOP_NO_RELABEL    = 1 << 1,
404507
-- 
404507
2.16.1
404507