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

[libvirt] [PATCH v3 REBASE 02/16] qemu: introduce qemu domain job status



This patch simply switches code from using VIR_DOMAIN_JOB_* to
introduced QEMU_DOMAIN_JOB_STATUS_*. Later this gives us freedom
to introduce states for postcopy and mirroring phases.
---
 src/qemu/qemu_domain.c           | 27 ++++++++++++++++++++--
 src/qemu/qemu_domain.h           | 10 +++++++-
 src/qemu/qemu_driver.c           | 11 ++++-----
 src/qemu/qemu_migration.c        | 50 +++++++++++++++++++---------------------
 src/qemu/qemu_migration_cookie.c |  2 +-
 src/qemu/qemu_process.c          |  2 +-
 6 files changed, 65 insertions(+), 37 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 8545137..bdd59b5 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -412,11 +412,34 @@ qemuDomainJobInfoUpdateDowntime(qemuDomainJobInfoPtr jobInfo)
     return 0;
 }
 
+static virDomainJobType
+qemuDomainJobStatusToType(qemuDomainJobStatus status)
+{
+    switch (status) {
+    case QEMU_DOMAIN_JOB_STATUS_NONE:
+        break;
+
+    case QEMU_DOMAIN_JOB_STATUS_ACTIVE:
+        return VIR_DOMAIN_JOB_UNBOUNDED;
+
+    case QEMU_DOMAIN_JOB_STATUS_COMPLETED:
+        return VIR_DOMAIN_JOB_COMPLETED;
+
+    case QEMU_DOMAIN_JOB_STATUS_FAILED:
+        return VIR_DOMAIN_JOB_FAILED;
+
+    case QEMU_DOMAIN_JOB_STATUS_CANCELED:
+        return VIR_DOMAIN_JOB_CANCELLED;
+    }
+
+    return VIR_DOMAIN_JOB_NONE;
+}
+
 int
 qemuDomainJobInfoToInfo(qemuDomainJobInfoPtr jobInfo,
                         virDomainJobInfoPtr info)
 {
-    info->type = jobInfo->type;
+    info->type = qemuDomainJobStatusToType(jobInfo->status);
     info->timeElapsed = jobInfo->timeElapsed;
 
     info->memTotal = jobInfo->stats.ram_total;
@@ -576,7 +599,7 @@ qemuDomainJobInfoToParams(qemuDomainJobInfoPtr jobInfo,
                              stats->cpu_throttle_percentage) < 0)
         goto error;
 
-    *type = jobInfo->type;
+    *type = qemuDomainJobStatusToType(jobInfo->status);
     *params = par;
     *nparams = npar;
     return 0;
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 860e70f..7836dc5 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -99,10 +99,18 @@ typedef enum {
 } qemuDomainAsyncJob;
 VIR_ENUM_DECL(qemuDomainAsyncJob)
 
+typedef enum {
+    QEMU_DOMAIN_JOB_STATUS_NONE = 0,
+    QEMU_DOMAIN_JOB_STATUS_ACTIVE,
+    QEMU_DOMAIN_JOB_STATUS_COMPLETED,
+    QEMU_DOMAIN_JOB_STATUS_FAILED,
+    QEMU_DOMAIN_JOB_STATUS_CANCELED,
+} qemuDomainJobStatus;
+
 typedef struct _qemuDomainJobInfo qemuDomainJobInfo;
 typedef qemuDomainJobInfo *qemuDomainJobInfoPtr;
 struct _qemuDomainJobInfo {
-    virDomainJobType type;
+    qemuDomainJobStatus status;
     virDomainJobOperation operation;
     unsigned long long started; /* When the async job started */
     unsigned long long stopped; /* When the domain's CPUs were stopped */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e9f07c6..d5c70ee 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3310,7 +3310,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virDomainPtr dom,
         goto endjob;
     }
 
-    priv->job.current->type = VIR_DOMAIN_JOB_UNBOUNDED;
+    priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_ACTIVE;
 
     /* Pause */
     if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
@@ -12942,14 +12942,13 @@ qemuDomainGetJobStatsInternal(virQEMUDriverPtr driver,
         info = priv->job.current;
 
     if (!info) {
-        jobInfo->type = VIR_DOMAIN_JOB_NONE;
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_NONE;
         ret = 0;
         goto cleanup;
     }
     *jobInfo = *info;
 
-    if (jobInfo->type == VIR_DOMAIN_JOB_BOUNDED ||
-        jobInfo->type == VIR_DOMAIN_JOB_UNBOUNDED) {
+    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE) {
         if (fetch)
             ret = qemuMigrationFetchJobStatus(driver, vm, QEMU_ASYNC_JOB_NONE,
                                               jobInfo);
@@ -12984,7 +12983,7 @@ qemuDomainGetJobInfo(virDomainPtr dom,
     if (qemuDomainGetJobStatsInternal(driver, vm, false, &jobInfo) < 0)
         goto cleanup;
 
-    if (jobInfo.type == VIR_DOMAIN_JOB_NONE) {
+    if (jobInfo.status == QEMU_DOMAIN_JOB_STATUS_NONE) {
         memset(info, 0, sizeof(*info));
         info->type = VIR_DOMAIN_JOB_NONE;
         ret = 0;
@@ -13025,7 +13024,7 @@ qemuDomainGetJobStats(virDomainPtr dom,
     if (qemuDomainGetJobStatsInternal(driver, vm, completed, &jobInfo) < 0)
         goto cleanup;
 
-    if (jobInfo.type == VIR_DOMAIN_JOB_NONE) {
+    if (jobInfo.status == QEMU_DOMAIN_JOB_STATUS_NONE) {
         *type = VIR_DOMAIN_JOB_NONE;
         *params = NULL;
         *nparams = 0;
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index ca1f671..01416a6 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -966,7 +966,7 @@ qemuMigrationDriveMirror(virQEMUDriverPtr driver,
             goto cleanup;
 
         if (priv->job.abortJob) {
-            priv->job.current->type = VIR_DOMAIN_JOB_CANCELLED;
+            priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_CANCELED;
             virReportError(VIR_ERR_OPERATION_ABORTED, _("%s: %s"),
                            qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
                            _("canceled by client"));
@@ -1347,19 +1347,19 @@ qemuMigrationUpdateJobType(qemuDomainJobInfoPtr jobInfo)
 {
     switch ((qemuMonitorMigrationStatus) jobInfo->stats.status) {
     case QEMU_MONITOR_MIGRATION_STATUS_COMPLETED:
-        jobInfo->type = VIR_DOMAIN_JOB_COMPLETED;
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_COMPLETED;
         break;
 
     case QEMU_MONITOR_MIGRATION_STATUS_INACTIVE:
-        jobInfo->type = VIR_DOMAIN_JOB_NONE;
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_NONE;
         break;
 
     case QEMU_MONITOR_MIGRATION_STATUS_ERROR:
-        jobInfo->type = VIR_DOMAIN_JOB_FAILED;
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
         break;
 
     case QEMU_MONITOR_MIGRATION_STATUS_CANCELLED:
-        jobInfo->type = VIR_DOMAIN_JOB_CANCELLED;
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_CANCELED;
         break;
 
     case QEMU_MONITOR_MIGRATION_STATUS_SETUP:
@@ -1446,32 +1446,30 @@ qemuMigrationCheckJobStatus(virQEMUDriverPtr driver,
     else if (qemuMigrationUpdateJobStatus(driver, vm, asyncJob) < 0)
         return -1;
 
-    switch (jobInfo->type) {
-    case VIR_DOMAIN_JOB_NONE:
+    switch (jobInfo->status) {
+    case QEMU_DOMAIN_JOB_STATUS_NONE:
         virReportError(VIR_ERR_OPERATION_FAILED, _("%s: %s"),
                        qemuMigrationJobName(vm), _("is not active"));
         return -1;
 
-    case VIR_DOMAIN_JOB_FAILED:
+    case QEMU_DOMAIN_JOB_STATUS_FAILED:
         virReportError(VIR_ERR_OPERATION_FAILED, _("%s: %s"),
                        qemuMigrationJobName(vm), _("unexpectedly failed"));
         return -1;
 
-    case VIR_DOMAIN_JOB_CANCELLED:
+    case QEMU_DOMAIN_JOB_STATUS_CANCELED:
         virReportError(VIR_ERR_OPERATION_ABORTED, _("%s: %s"),
                        qemuMigrationJobName(vm), _("canceled by client"));
         return -1;
 
-    case VIR_DOMAIN_JOB_COMPLETED:
+    case QEMU_DOMAIN_JOB_STATUS_COMPLETED:
         /* Fetch statistics of a completed migration */
         if (events && updateJobStats &&
             qemuMigrationUpdateJobStatus(driver, vm, asyncJob) < 0)
             return -1;
         break;
 
-    case VIR_DOMAIN_JOB_BOUNDED:
-    case VIR_DOMAIN_JOB_UNBOUNDED:
-    case VIR_DOMAIN_JOB_LAST:
+    case QEMU_DOMAIN_JOB_STATUS_ACTIVE:
         break;
     }
     return 0;
@@ -1529,7 +1527,7 @@ qemuMigrationCompleted(virQEMUDriverPtr driver,
      * will continue waiting until the migrate state changes to completed.
      */
     if (flags & QEMU_MIGRATION_COMPLETED_POSTCOPY &&
-        jobInfo->type == VIR_DOMAIN_JOB_UNBOUNDED &&
+        jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE &&
         jobInfo->stats.status == QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY) {
         VIR_DEBUG("Migration switched to post-copy");
         if (updateStats &&
@@ -1538,18 +1536,18 @@ qemuMigrationCompleted(virQEMUDriverPtr driver,
         return 1;
     }
 
-    if (jobInfo->type == VIR_DOMAIN_JOB_COMPLETED)
+    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_COMPLETED)
         return 1;
     else
         return 0;
 
  error:
-    if (jobInfo->type == VIR_DOMAIN_JOB_UNBOUNDED) {
+    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE) {
         /* The migration was aborted by us rather than QEMU itself. */
-        jobInfo->type = VIR_DOMAIN_JOB_FAILED;
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
         return -2;
-    } else if (jobInfo->type == VIR_DOMAIN_JOB_COMPLETED) {
-        jobInfo->type = VIR_DOMAIN_JOB_FAILED;
+    } else if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_COMPLETED) {
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
         return -1;
     } else {
         return -1;
@@ -1574,7 +1572,7 @@ qemuMigrationWaitForCompletion(virQEMUDriverPtr driver,
 
     flags |= QEMU_MIGRATION_COMPLETED_UPDATE_STATS;
 
-    jobInfo->type = VIR_DOMAIN_JOB_UNBOUNDED;
+    jobInfo->status = QEMU_DOMAIN_JOB_STATUS_ACTIVE;
     while ((rv = qemuMigrationCompleted(driver, vm, asyncJob,
                                         dconn, flags)) != 1) {
         if (rv < 0)
@@ -1582,7 +1580,7 @@ qemuMigrationWaitForCompletion(virQEMUDriverPtr driver,
 
         if (events) {
             if (virDomainObjWait(vm) < 0) {
-                jobInfo->type = VIR_DOMAIN_JOB_FAILED;
+                jobInfo->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
                 return -2;
             }
         } else {
@@ -3756,7 +3754,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
          * as this is a critical section so we are guaranteed
          * priv->job.abortJob will not change */
         ignore_value(qemuDomainObjExitMonitor(driver, vm));
-        priv->job.current->type = VIR_DOMAIN_JOB_CANCELLED;
+        priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_CANCELED;
         virReportError(VIR_ERR_OPERATION_ABORTED, _("%s: %s"),
                        qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
                        _("canceled by client"));
@@ -3890,8 +3888,8 @@ qemuMigrationRun(virQEMUDriverPtr driver,
         ignore_value(virTimeMillisNow(&priv->job.completed->sent));
     }
 
-    if (priv->job.current->type == VIR_DOMAIN_JOB_UNBOUNDED && !inPostCopy)
-        priv->job.current->type = VIR_DOMAIN_JOB_FAILED;
+    if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE && !inPostCopy)
+        priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
 
     cookieFlags |= QEMU_MIGRATION_COOKIE_NETWORK |
                    QEMU_MIGRATION_COOKIE_STATS;
@@ -3933,7 +3931,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
     goto cleanup;
 
  cancelPostCopy:
-    priv->job.current->type = VIR_DOMAIN_JOB_FAILED;
+    priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
     if (inPostCopy)
         goto cancel;
     else
@@ -5652,7 +5650,7 @@ qemuMigrationJobStart(virQEMUDriverPtr driver,
         return -1;
 
     qemuDomainObjSetAsyncJobMask(vm, mask);
-    priv->job.current->type = VIR_DOMAIN_JOB_UNBOUNDED;
+    priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_ACTIVE;
 
     return 0;
 }
diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c
index 5f8595f..4914c77 100644
--- a/src/qemu/qemu_migration_cookie.c
+++ b/src/qemu/qemu_migration_cookie.c
@@ -974,7 +974,7 @@ qemuMigrationCookieStatisticsXMLParse(xmlXPathContextPtr ctxt)
         goto cleanup;
 
     stats = &jobInfo->stats;
-    jobInfo->type = VIR_DOMAIN_JOB_COMPLETED;
+    jobInfo->status = QEMU_DOMAIN_JOB_STATUS_COMPLETED;
 
     virXPathULongLong("string(./started[1])", ctxt, &jobInfo->started);
     virXPathULongLong("string(./stopped[1])", ctxt, &jobInfo->stopped);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 589d0ed..0f96b28 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3979,7 +3979,7 @@ qemuProcessBeginJob(virQEMUDriverPtr driver,
         return -1;
 
     qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_NONE);
-    priv->job.current->type = VIR_DOMAIN_JOB_UNBOUNDED;
+    priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_ACTIVE;
 
     return 0;
 }
-- 
1.8.3.1


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