[PATCH v2 02/12] qemu: introduce qemu domain job status

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

 



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    | 24 ++++++++++++++++++++--
 src/qemu/qemu_domain.h    | 11 +++++++++-
 src/qemu/qemu_driver.c    | 11 +++++-----
 src/qemu/qemu_migration.c | 52 +++++++++++++++++++++++------------------------
 src/qemu/qemu_process.c   |  2 +-
 5 files changed, 63 insertions(+), 37 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index acc27d0..3582151 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -386,11 +386,31 @@ qemuDomainJobInfoUpdateDowntime(qemuDomainJobInfoPtr jobInfo)
     return 0;
 }
 
+static virDomainJobType
+qemuDomainJobStatusToType(qemuDomainJobStatus status)
+{
+    switch (status) {
+    case QEMU_DOMAIN_JOB_STATUS_NONE:
+        return VIR_DOMAIN_JOB_NONE;
+    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;
+    }
+
+    /* should not reach here */
+    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->timeRemaining = jobInfo->timeRemaining;
 
@@ -546,7 +566,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 b2db45e..f257dc1 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -98,10 +98,19 @@ 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;
+
     unsigned long long started; /* When the async job started */
     unsigned long long stopped; /* When the domain's CPUs were stopped */
     unsigned long long sent; /* When the source sent status info to the
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b359e77..143d401 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3169,7 +3169,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) {
@@ -13056,14 +13056,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);
@@ -13098,7 +13097,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;
@@ -13139,7 +13138,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 0f4a6cf..c5184b2 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1096,7 +1096,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);
@@ -2196,7 +2196,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"));
@@ -2555,19 +2555,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:
@@ -2654,32 +2654,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;
@@ -2737,7 +2735,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 &&
@@ -2746,18 +2744,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;
@@ -2782,7 +2780,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)
@@ -2790,7 +2788,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 {
@@ -4772,7 +4770,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"));
@@ -4902,8 +4900,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;
@@ -4946,7 +4944,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
@@ -6654,7 +6652,7 @@ qemuMigrationJobStart(virQEMUDriverPtr driver,
                                           JOB_MASK(QEMU_JOB_MIGRATION_OP)));
     }
 
-    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_process.c b/src/qemu/qemu_process.c
index afe3cac..3ac364c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4057,7 +4057,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

--
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