render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
23265d
From 626d23419335db221e7b52a5bc07ad4f74391199 Mon Sep 17 00:00:00 2001
23265d
Message-Id: <626d23419335db221e7b52a5bc07ad4f74391199@dist-git>
23265d
From: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
23265d
Date: Fri, 1 Sep 2017 09:49:21 +0300
23265d
Subject: [PATCH] qemu: introduce QEMU_DOMAIN_JOB_STATUS_POSTCOPY
23265d
23265d
Let's introduce QEMU_DOMAIN_JOB_STATUS_POSTCOPY state for job.current->status
23265d
instead of checking job.current->stats.status. The latter can be changed
23265d
when fetching migration statistics. Moving state function from the variable
23265d
and leave only store function seems more managable.
23265d
23265d
This patch removes all state checking usage of stats except for
23265d
qemuDomainGetJobStatsInternal. This place will be handled separately.
23265d
23265d
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
23265d
(cherry picked from commit 09f57f9aaca6d2703567d5cda45d47fc06131ae0)
23265d
23265d
https://bugzilla.redhat.com/show_bug.cgi?id=1530130
23265d
23265d
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
23265d
---
23265d
 src/qemu/qemu_domain.c    |  1 +
23265d
 src/qemu/qemu_domain.h    |  1 +
23265d
 src/qemu/qemu_driver.c    |  5 +++--
23265d
 src/qemu/qemu_migration.c | 18 +++++++++++-------
23265d
 src/qemu/qemu_process.c   |  4 ++--
23265d
 5 files changed, 18 insertions(+), 11 deletions(-)
23265d
23265d
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
23265d
index c9b3e13892..329ec6e2ce 100644
23265d
--- a/src/qemu/qemu_domain.c
23265d
+++ b/src/qemu/qemu_domain.c
23265d
@@ -397,6 +397,7 @@ qemuDomainJobStatusToType(qemuDomainJobStatus status)
23265d
         break;
23265d
 
23265d
     case QEMU_DOMAIN_JOB_STATUS_ACTIVE:
23265d
+    case QEMU_DOMAIN_JOB_STATUS_POSTCOPY:
23265d
         return VIR_DOMAIN_JOB_UNBOUNDED;
23265d
 
23265d
     case QEMU_DOMAIN_JOB_STATUS_COMPLETED:
23265d
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
23265d
index e4e672f872..c8b3873b9f 100644
23265d
--- a/src/qemu/qemu_domain.h
23265d
+++ b/src/qemu/qemu_domain.h
23265d
@@ -102,6 +102,7 @@ VIR_ENUM_DECL(qemuDomainAsyncJob)
23265d
 typedef enum {
23265d
     QEMU_DOMAIN_JOB_STATUS_NONE = 0,
23265d
     QEMU_DOMAIN_JOB_STATUS_ACTIVE,
23265d
+    QEMU_DOMAIN_JOB_STATUS_POSTCOPY,
23265d
     QEMU_DOMAIN_JOB_STATUS_COMPLETED,
23265d
     QEMU_DOMAIN_JOB_STATUS_FAILED,
23265d
     QEMU_DOMAIN_JOB_STATUS_CANCELED,
23265d
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
23265d
index a271f60abf..ecba87a121 100644
23265d
--- a/src/qemu/qemu_driver.c
23265d
+++ b/src/qemu/qemu_driver.c
23265d
@@ -12971,7 +12971,8 @@ qemuDomainGetJobStatsInternal(virQEMUDriverPtr driver,
23265d
     }
23265d
     *jobInfo = *info;
23265d
 
23265d
-    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE) {
23265d
+    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE ||
23265d
+        jobInfo->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY) {
23265d
         if (fetch)
23265d
             ret = qemuMigrationFetchJobStatus(driver, vm, QEMU_ASYNC_JOB_NONE,
23265d
                                               jobInfo);
23265d
@@ -13105,7 +13106,7 @@ static int qemuDomainAbortJob(virDomainPtr dom)
23265d
     }
23265d
 
23265d
     if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT &&
23265d
-        (priv->job.current->stats.status == QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY ||
23265d
+        (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY ||
23265d
          (virDomainObjGetState(vm, &reason) == VIR_DOMAIN_PAUSED &&
23265d
           reason == VIR_DOMAIN_PAUSED_POSTCOPY))) {
23265d
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
23265d
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
23265d
index 500f467f25..1726349f94 100644
23265d
--- a/src/qemu/qemu_migration.c
23265d
+++ b/src/qemu/qemu_migration.c
23265d
@@ -1333,6 +1333,10 @@ static void
23265d
 qemuMigrationUpdateJobType(qemuDomainJobInfoPtr jobInfo)
23265d
 {
23265d
     switch ((qemuMonitorMigrationStatus) jobInfo->stats.status) {
23265d
+    case QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY:
23265d
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_POSTCOPY;
23265d
+        break;
23265d
+
23265d
     case QEMU_MONITOR_MIGRATION_STATUS_COMPLETED:
23265d
         jobInfo->status = QEMU_DOMAIN_JOB_STATUS_COMPLETED;
23265d
         break;
23265d
@@ -1351,7 +1355,6 @@ qemuMigrationUpdateJobType(qemuDomainJobInfoPtr jobInfo)
23265d
 
23265d
     case QEMU_MONITOR_MIGRATION_STATUS_SETUP:
23265d
     case QEMU_MONITOR_MIGRATION_STATUS_ACTIVE:
23265d
-    case QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY:
23265d
     case QEMU_MONITOR_MIGRATION_STATUS_CANCELLING:
23265d
     case QEMU_MONITOR_MIGRATION_STATUS_LAST:
23265d
         break;
23265d
@@ -1457,6 +1460,7 @@ qemuMigrationCheckJobStatus(virQEMUDriverPtr driver,
23265d
         break;
23265d
 
23265d
     case QEMU_DOMAIN_JOB_STATUS_ACTIVE:
23265d
+    case QEMU_DOMAIN_JOB_STATUS_POSTCOPY:
23265d
         break;
23265d
     }
23265d
     return 0;
23265d
@@ -1514,8 +1518,7 @@ qemuMigrationCompleted(virQEMUDriverPtr driver,
23265d
      * will continue waiting until the migrate state changes to completed.
23265d
      */
23265d
     if (flags & QEMU_MIGRATION_COMPLETED_POSTCOPY &&
23265d
-        jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE &&
23265d
-        jobInfo->stats.status == QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY) {
23265d
+        jobInfo->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY) {
23265d
         VIR_DEBUG("Migration switched to post-copy");
23265d
         if (updateStats &&
23265d
             qemuMigrationUpdateJobStatus(driver, vm, asyncJob) < 0)
23265d
@@ -1529,7 +1532,8 @@ qemuMigrationCompleted(virQEMUDriverPtr driver,
23265d
         return 0;
23265d
 
23265d
  error:
23265d
-    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE) {
23265d
+    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE ||
23265d
+        jobInfo->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY) {
23265d
         /* The migration was aborted by us rather than QEMU itself. */
23265d
         jobInfo->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
23265d
         return -2;
23265d
@@ -3824,7 +3828,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
23265d
     else if (rc == -1)
23265d
         goto cleanup;
23265d
 
23265d
-    if (priv->job.current->stats.status == QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY)
23265d
+    if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY)
23265d
         inPostCopy = true;
23265d
 
23265d
     /* When migration completed, QEMU will have paused the CPUs for us.
23265d
@@ -3876,7 +3880,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
23265d
         ignore_value(virTimeMillisNow(&priv->job.completed->sent));
23265d
     }
23265d
 
23265d
-    if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE && !inPostCopy)
23265d
+    if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE)
23265d
         priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
23265d
 
23265d
     cookieFlags |= QEMU_MIGRATION_COOKIE_NETWORK |
23265d
@@ -5249,7 +5253,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
23265d
             goto endjob;
23265d
     }
23265d
 
23265d
-    if (priv->job.current->stats.status == QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY)
23265d
+    if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY)
23265d
         inPostCopy = true;
23265d
 
23265d
     if (!(flags & VIR_MIGRATE_PAUSED)) {
23265d
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
23265d
index 3235cebad0..25de367afc 100644
23265d
--- a/src/qemu/qemu_process.c
23265d
+++ b/src/qemu/qemu_process.c
23265d
@@ -723,8 +723,8 @@ qemuProcessHandleStop(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
23265d
         }
23265d
 
23265d
         if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT) {
23265d
-            if (priv->job.current->stats.status ==
23265d
-                        QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY) {
23265d
+            if (priv->job.current->status ==
23265d
+                        QEMU_DOMAIN_JOB_STATUS_POSTCOPY) {
23265d
                 reason = VIR_DOMAIN_PAUSED_POSTCOPY;
23265d
                 detail = VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY;
23265d
             } else {
23265d
-- 
23265d
2.15.1
23265d