[PATCH v2 03/12] qemu: introduce QEMU_DOMAIN_JOB_STATUS_POSTCOPY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Current code consults job.current->stats.status to check for postcopy
state. First it is more correct to check for both job.current->status
and job.current->stats.status.code because on some paths on failures
we change only the former. Second if qemu supports migration events
then stats can change unexpectedly.

Let's introduce QEMU_DOMAIN_JOB_STATUS_POSTCOPY state for job.current->status.

This patch removes all state checking usage of stats except for
qemuDomainGetJobStatsInternal. This place will be handled separately.
---
 src/qemu/qemu_domain.c    |  1 +
 src/qemu/qemu_domain.h    |  1 +
 src/qemu/qemu_driver.c    |  5 +++--
 src/qemu/qemu_migration.c | 18 +++++++++++-------
 src/qemu/qemu_process.c   |  4 ++--
 5 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3582151..952a933 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -393,6 +393,7 @@ qemuDomainJobStatusToType(qemuDomainJobStatus status)
     case QEMU_DOMAIN_JOB_STATUS_NONE:
         return VIR_DOMAIN_JOB_NONE;
     case QEMU_DOMAIN_JOB_STATUS_ACTIVE:
+    case QEMU_DOMAIN_JOB_STATUS_POSTCOPY:
         return VIR_DOMAIN_JOB_UNBOUNDED;
     case QEMU_DOMAIN_JOB_STATUS_COMPLETED:
         return VIR_DOMAIN_JOB_COMPLETED;
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index f257dc1..273145d 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -102,6 +102,7 @@ typedef enum {
     QEMU_DOMAIN_JOB_STATUS_NONE = 0,
     QEMU_DOMAIN_JOB_STATUS_ACTIVE,
     QEMU_DOMAIN_JOB_STATUS_COMPLETED,
+    QEMU_DOMAIN_JOB_STATUS_POSTCOPY,
     QEMU_DOMAIN_JOB_STATUS_FAILED,
     QEMU_DOMAIN_JOB_STATUS_CANCELED,
 } qemuDomainJobStatus;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 143d401..d1a64d7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13062,7 +13062,8 @@ qemuDomainGetJobStatsInternal(virQEMUDriverPtr driver,
     }
     *jobInfo = *info;
 
-    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE) {
+    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE ||
+        jobInfo->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY) {
         if (fetch)
             ret = qemuMigrationFetchJobStatus(driver, vm, QEMU_ASYNC_JOB_NONE,
                                               jobInfo);
@@ -13196,7 +13197,7 @@ static int qemuDomainAbortJob(virDomainPtr dom)
     }
 
     if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT &&
-        (priv->job.current->stats.status == QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY ||
+        (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY ||
          (virDomainObjGetState(vm, &reason) == VIR_DOMAIN_PAUSED &&
           reason == VIR_DOMAIN_PAUSED_POSTCOPY))) {
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index c5184b2..64e5b91 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2558,6 +2558,10 @@ qemuMigrationUpdateJobType(qemuDomainJobInfoPtr jobInfo)
         jobInfo->status = QEMU_DOMAIN_JOB_STATUS_COMPLETED;
         break;
 
+    case QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY:
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_POSTCOPY;
+        break;
+
     case QEMU_MONITOR_MIGRATION_STATUS_INACTIVE:
         jobInfo->status = QEMU_DOMAIN_JOB_STATUS_NONE;
         break;
@@ -2572,7 +2576,6 @@ qemuMigrationUpdateJobType(qemuDomainJobInfoPtr jobInfo)
 
     case QEMU_MONITOR_MIGRATION_STATUS_SETUP:
     case QEMU_MONITOR_MIGRATION_STATUS_ACTIVE:
-    case QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY:
     case QEMU_MONITOR_MIGRATION_STATUS_CANCELLING:
     case QEMU_MONITOR_MIGRATION_STATUS_LAST:
         break;
@@ -2678,6 +2681,7 @@ qemuMigrationCheckJobStatus(virQEMUDriverPtr driver,
         break;
 
     case QEMU_DOMAIN_JOB_STATUS_ACTIVE:
+    case QEMU_DOMAIN_JOB_STATUS_POSTCOPY:
         break;
     }
     return 0;
@@ -2735,8 +2739,7 @@ qemuMigrationCompleted(virQEMUDriverPtr driver,
      * will continue waiting until the migrate state changes to completed.
      */
     if (flags & QEMU_MIGRATION_COMPLETED_POSTCOPY &&
-        jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE &&
-        jobInfo->stats.status == QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY) {
+        jobInfo->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY) {
         VIR_DEBUG("Migration switched to post-copy");
         if (updateStats &&
             qemuMigrationUpdateJobStatus(driver, vm, asyncJob) < 0)
@@ -2750,7 +2753,8 @@ qemuMigrationCompleted(virQEMUDriverPtr driver,
         return 0;
 
  error:
-    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE) {
+    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE ||
+        jobInfo->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY) {
         /* The migration was aborted by us rather than QEMU itself. */
         jobInfo->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
         return -2;
@@ -4852,7 +4856,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
     else if (rc == -1)
         goto cleanup;
 
-    if (priv->job.current->stats.status == QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY)
+    if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY)
         inPostCopy = true;
 
     /* When migration completed, QEMU will have paused the CPUs for us.
@@ -4900,7 +4904,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
         ignore_value(virTimeMillisNow(&priv->job.completed->sent));
     }
 
-    if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE && !inPostCopy)
+    if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE)
         priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
 
     cookieFlags |= QEMU_MIGRATION_COOKIE_NETWORK |
@@ -6264,7 +6268,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
             goto endjob;
     }
 
-    if (priv->job.current->stats.status == QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY)
+    if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY)
         inPostCopy = true;
 
     if (!(flags & VIR_MIGRATE_PAUSED)) {
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 3ac364c..fd34b23 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -703,8 +703,8 @@ qemuProcessHandleStop(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
         }
 
         if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT) {
-            if (priv->job.current->stats.status ==
-                        QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY) {
+            if (priv->job.current->status ==
+                        QEMU_DOMAIN_JOB_STATUS_POSTCOPY) {
                 reason = VIR_DOMAIN_PAUSED_POSTCOPY;
                 detail = VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY;
             } else {
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux