render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
23265d
From c95e8e44a4b4c07b79cafafe20018c5d2d37bfbd Mon Sep 17 00:00:00 2001
23265d
Message-Id: <c95e8e44a4b4c07b79cafafe20018c5d2d37bfbd@dist-git>
23265d
From: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
23265d
Date: Fri, 1 Sep 2017 09:49:20 +0300
23265d
Subject: [PATCH] qemu: introduce qemu domain job status
23265d
23265d
This patch simply switches code from using VIR_DOMAIN_JOB_* to
23265d
introduced QEMU_DOMAIN_JOB_STATUS_*. Later this gives us freedom
23265d
to introduce states for postcopy and mirroring phases.
23265d
23265d
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
23265d
(cherry picked from commit 751a1c7f0ade5c9e5ea858bbaf97e39950f821e6)
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           | 27 ++++++++++++++++++++--
23265d
 src/qemu/qemu_domain.h           | 10 +++++++-
23265d
 src/qemu/qemu_driver.c           | 10 ++++----
23265d
 src/qemu/qemu_migration.c        | 50 +++++++++++++++++++---------------------
23265d
 src/qemu/qemu_migration_cookie.c |  2 +-
23265d
 src/qemu/qemu_process.c          |  2 +-
23265d
 6 files changed, 65 insertions(+), 36 deletions(-)
23265d
23265d
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
23265d
index 3c2368368f..c9b3e13892 100644
23265d
--- a/src/qemu/qemu_domain.c
23265d
+++ b/src/qemu/qemu_domain.c
23265d
@@ -389,11 +389,34 @@ qemuDomainJobInfoUpdateDowntime(qemuDomainJobInfoPtr jobInfo)
23265d
     return 0;
23265d
 }
23265d
 
23265d
+static virDomainJobType
23265d
+qemuDomainJobStatusToType(qemuDomainJobStatus status)
23265d
+{
23265d
+    switch (status) {
23265d
+    case QEMU_DOMAIN_JOB_STATUS_NONE:
23265d
+        break;
23265d
+
23265d
+    case QEMU_DOMAIN_JOB_STATUS_ACTIVE:
23265d
+        return VIR_DOMAIN_JOB_UNBOUNDED;
23265d
+
23265d
+    case QEMU_DOMAIN_JOB_STATUS_COMPLETED:
23265d
+        return VIR_DOMAIN_JOB_COMPLETED;
23265d
+
23265d
+    case QEMU_DOMAIN_JOB_STATUS_FAILED:
23265d
+        return VIR_DOMAIN_JOB_FAILED;
23265d
+
23265d
+    case QEMU_DOMAIN_JOB_STATUS_CANCELED:
23265d
+        return VIR_DOMAIN_JOB_CANCELLED;
23265d
+    }
23265d
+
23265d
+    return VIR_DOMAIN_JOB_NONE;
23265d
+}
23265d
+
23265d
 int
23265d
 qemuDomainJobInfoToInfo(qemuDomainJobInfoPtr jobInfo,
23265d
                         virDomainJobInfoPtr info)
23265d
 {
23265d
-    info->type = jobInfo->type;
23265d
+    info->type = qemuDomainJobStatusToType(jobInfo->status);
23265d
     info->timeElapsed = jobInfo->timeElapsed;
23265d
 
23265d
     info->memTotal = jobInfo->stats.ram_total;
23265d
@@ -553,7 +576,7 @@ qemuDomainJobInfoToParams(qemuDomainJobInfoPtr jobInfo,
23265d
                              stats->cpu_throttle_percentage) < 0)
23265d
         goto error;
23265d
 
23265d
-    *type = jobInfo->type;
23265d
+    *type = qemuDomainJobStatusToType(jobInfo->status);
23265d
     *params = par;
23265d
     *nparams = npar;
23265d
     return 0;
23265d
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
23265d
index 7002407218..e4e672f872 100644
23265d
--- a/src/qemu/qemu_domain.h
23265d
+++ b/src/qemu/qemu_domain.h
23265d
@@ -99,10 +99,18 @@ typedef enum {
23265d
 } qemuDomainAsyncJob;
23265d
 VIR_ENUM_DECL(qemuDomainAsyncJob)
23265d
 
23265d
+typedef enum {
23265d
+    QEMU_DOMAIN_JOB_STATUS_NONE = 0,
23265d
+    QEMU_DOMAIN_JOB_STATUS_ACTIVE,
23265d
+    QEMU_DOMAIN_JOB_STATUS_COMPLETED,
23265d
+    QEMU_DOMAIN_JOB_STATUS_FAILED,
23265d
+    QEMU_DOMAIN_JOB_STATUS_CANCELED,
23265d
+} qemuDomainJobStatus;
23265d
+
23265d
 typedef struct _qemuDomainJobInfo qemuDomainJobInfo;
23265d
 typedef qemuDomainJobInfo *qemuDomainJobInfoPtr;
23265d
 struct _qemuDomainJobInfo {
23265d
-    virDomainJobType type;
23265d
+    qemuDomainJobStatus status;
23265d
     virDomainJobOperation operation;
23265d
     unsigned long long started; /* When the async job started */
23265d
     unsigned long long stopped; /* When the domain's CPUs were stopped */
23265d
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
23265d
index 1c60d533e8..a271f60abf 100644
23265d
--- a/src/qemu/qemu_driver.c
23265d
+++ b/src/qemu/qemu_driver.c
23265d
@@ -3299,7 +3299,7 @@ qemuDomainSaveInternal(virQEMUDriverPtr driver, virDomainPtr dom,
23265d
         goto endjob;
23265d
     }
23265d
 
23265d
-    priv->job.current->type = VIR_DOMAIN_JOB_UNBOUNDED;
23265d
+    priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_ACTIVE;
23265d
 
23265d
     /* Pause */
23265d
     if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
23265d
@@ -12965,13 +12965,13 @@ qemuDomainGetJobStatsInternal(virQEMUDriverPtr driver,
23265d
         info = priv->job.current;
23265d
 
23265d
     if (!info) {
23265d
-        jobInfo->type = VIR_DOMAIN_JOB_NONE;
23265d
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_NONE;
23265d
         ret = 0;
23265d
         goto cleanup;
23265d
     }
23265d
     *jobInfo = *info;
23265d
 
23265d
-    if (jobInfo->type == VIR_DOMAIN_JOB_UNBOUNDED) {
23265d
+    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE) {
23265d
         if (fetch)
23265d
             ret = qemuMigrationFetchJobStatus(driver, vm, QEMU_ASYNC_JOB_NONE,
23265d
                                               jobInfo);
23265d
@@ -13006,7 +13006,7 @@ qemuDomainGetJobInfo(virDomainPtr dom,
23265d
     if (qemuDomainGetJobStatsInternal(driver, vm, false, &jobInfo) < 0)
23265d
         goto cleanup;
23265d
 
23265d
-    if (jobInfo.type == VIR_DOMAIN_JOB_NONE) {
23265d
+    if (jobInfo.status == QEMU_DOMAIN_JOB_STATUS_NONE) {
23265d
         memset(info, 0, sizeof(*info));
23265d
         info->type = VIR_DOMAIN_JOB_NONE;
23265d
         ret = 0;
23265d
@@ -13047,7 +13047,7 @@ qemuDomainGetJobStats(virDomainPtr dom,
23265d
     if (qemuDomainGetJobStatsInternal(driver, vm, completed, &jobInfo) < 0)
23265d
         goto cleanup;
23265d
 
23265d
-    if (jobInfo.type == VIR_DOMAIN_JOB_NONE) {
23265d
+    if (jobInfo.status == QEMU_DOMAIN_JOB_STATUS_NONE) {
23265d
         *type = VIR_DOMAIN_JOB_NONE;
23265d
         *params = NULL;
23265d
         *nparams = 0;
23265d
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
23265d
index 60722cbf6c..500f467f25 100644
23265d
--- a/src/qemu/qemu_migration.c
23265d
+++ b/src/qemu/qemu_migration.c
23265d
@@ -965,7 +965,7 @@ qemuMigrationDriveMirror(virQEMUDriverPtr driver,
23265d
             goto cleanup;
23265d
 
23265d
         if (priv->job.abortJob) {
23265d
-            priv->job.current->type = VIR_DOMAIN_JOB_CANCELLED;
23265d
+            priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_CANCELED;
23265d
             virReportError(VIR_ERR_OPERATION_ABORTED, _("%s: %s"),
23265d
                            qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
23265d
                            _("canceled by client"));
23265d
@@ -1334,19 +1334,19 @@ qemuMigrationUpdateJobType(qemuDomainJobInfoPtr jobInfo)
23265d
 {
23265d
     switch ((qemuMonitorMigrationStatus) jobInfo->stats.status) {
23265d
     case QEMU_MONITOR_MIGRATION_STATUS_COMPLETED:
23265d
-        jobInfo->type = VIR_DOMAIN_JOB_COMPLETED;
23265d
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_COMPLETED;
23265d
         break;
23265d
 
23265d
     case QEMU_MONITOR_MIGRATION_STATUS_INACTIVE:
23265d
-        jobInfo->type = VIR_DOMAIN_JOB_NONE;
23265d
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_NONE;
23265d
         break;
23265d
 
23265d
     case QEMU_MONITOR_MIGRATION_STATUS_ERROR:
23265d
-        jobInfo->type = VIR_DOMAIN_JOB_FAILED;
23265d
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
23265d
         break;
23265d
 
23265d
     case QEMU_MONITOR_MIGRATION_STATUS_CANCELLED:
23265d
-        jobInfo->type = VIR_DOMAIN_JOB_CANCELLED;
23265d
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_CANCELED;
23265d
         break;
23265d
 
23265d
     case QEMU_MONITOR_MIGRATION_STATUS_SETUP:
23265d
@@ -1433,32 +1433,30 @@ qemuMigrationCheckJobStatus(virQEMUDriverPtr driver,
23265d
     else if (qemuMigrationUpdateJobStatus(driver, vm, asyncJob) < 0)
23265d
         return -1;
23265d
 
23265d
-    switch (jobInfo->type) {
23265d
-    case VIR_DOMAIN_JOB_NONE:
23265d
+    switch (jobInfo->status) {
23265d
+    case QEMU_DOMAIN_JOB_STATUS_NONE:
23265d
         virReportError(VIR_ERR_OPERATION_FAILED, _("%s: %s"),
23265d
                        qemuMigrationJobName(vm), _("is not active"));
23265d
         return -1;
23265d
 
23265d
-    case VIR_DOMAIN_JOB_FAILED:
23265d
+    case QEMU_DOMAIN_JOB_STATUS_FAILED:
23265d
         virReportError(VIR_ERR_OPERATION_FAILED, _("%s: %s"),
23265d
                        qemuMigrationJobName(vm), _("unexpectedly failed"));
23265d
         return -1;
23265d
 
23265d
-    case VIR_DOMAIN_JOB_CANCELLED:
23265d
+    case QEMU_DOMAIN_JOB_STATUS_CANCELED:
23265d
         virReportError(VIR_ERR_OPERATION_ABORTED, _("%s: %s"),
23265d
                        qemuMigrationJobName(vm), _("canceled by client"));
23265d
         return -1;
23265d
 
23265d
-    case VIR_DOMAIN_JOB_COMPLETED:
23265d
+    case QEMU_DOMAIN_JOB_STATUS_COMPLETED:
23265d
         /* Fetch statistics of a completed migration */
23265d
         if (events && updateJobStats &&
23265d
             qemuMigrationUpdateJobStatus(driver, vm, asyncJob) < 0)
23265d
             return -1;
23265d
         break;
23265d
 
23265d
-    case VIR_DOMAIN_JOB_BOUNDED:
23265d
-    case VIR_DOMAIN_JOB_UNBOUNDED:
23265d
-    case VIR_DOMAIN_JOB_LAST:
23265d
+    case QEMU_DOMAIN_JOB_STATUS_ACTIVE:
23265d
         break;
23265d
     }
23265d
     return 0;
23265d
@@ -1516,7 +1514,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->type == VIR_DOMAIN_JOB_UNBOUNDED &&
23265d
+        jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE &&
23265d
         jobInfo->stats.status == QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY) {
23265d
         VIR_DEBUG("Migration switched to post-copy");
23265d
         if (updateStats &&
23265d
@@ -1525,18 +1523,18 @@ qemuMigrationCompleted(virQEMUDriverPtr driver,
23265d
         return 1;
23265d
     }
23265d
 
23265d
-    if (jobInfo->type == VIR_DOMAIN_JOB_COMPLETED)
23265d
+    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_COMPLETED)
23265d
         return 1;
23265d
     else
23265d
         return 0;
23265d
 
23265d
  error:
23265d
-    if (jobInfo->type == VIR_DOMAIN_JOB_UNBOUNDED) {
23265d
+    if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE) {
23265d
         /* The migration was aborted by us rather than QEMU itself. */
23265d
-        jobInfo->type = VIR_DOMAIN_JOB_FAILED;
23265d
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
23265d
         return -2;
23265d
-    } else if (jobInfo->type == VIR_DOMAIN_JOB_COMPLETED) {
23265d
-        jobInfo->type = VIR_DOMAIN_JOB_FAILED;
23265d
+    } else if (jobInfo->status == QEMU_DOMAIN_JOB_STATUS_COMPLETED) {
23265d
+        jobInfo->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
23265d
         return -1;
23265d
     } else {
23265d
         return -1;
23265d
@@ -1561,7 +1559,7 @@ qemuMigrationWaitForCompletion(virQEMUDriverPtr driver,
23265d
 
23265d
     flags |= QEMU_MIGRATION_COMPLETED_UPDATE_STATS;
23265d
 
23265d
-    jobInfo->type = VIR_DOMAIN_JOB_UNBOUNDED;
23265d
+    jobInfo->status = QEMU_DOMAIN_JOB_STATUS_ACTIVE;
23265d
     while ((rv = qemuMigrationCompleted(driver, vm, asyncJob,
23265d
                                         dconn, flags)) != 1) {
23265d
         if (rv < 0)
23265d
@@ -1569,7 +1567,7 @@ qemuMigrationWaitForCompletion(virQEMUDriverPtr driver,
23265d
 
23265d
         if (events) {
23265d
             if (virDomainObjWait(vm) < 0) {
23265d
-                jobInfo->type = VIR_DOMAIN_JOB_FAILED;
23265d
+                jobInfo->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
23265d
                 return -2;
23265d
             }
23265d
         } else {
23265d
@@ -3744,7 +3742,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
23265d
          * as this is a critical section so we are guaranteed
23265d
          * priv->job.abortJob will not change */
23265d
         ignore_value(qemuDomainObjExitMonitor(driver, vm));
23265d
-        priv->job.current->type = VIR_DOMAIN_JOB_CANCELLED;
23265d
+        priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_CANCELED;
23265d
         virReportError(VIR_ERR_OPERATION_ABORTED, _("%s: %s"),
23265d
                        qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
23265d
                        _("canceled by client"));
23265d
@@ -3878,8 +3876,8 @@ qemuMigrationRun(virQEMUDriverPtr driver,
23265d
         ignore_value(virTimeMillisNow(&priv->job.completed->sent));
23265d
     }
23265d
 
23265d
-    if (priv->job.current->type == VIR_DOMAIN_JOB_UNBOUNDED && !inPostCopy)
23265d
-        priv->job.current->type = VIR_DOMAIN_JOB_FAILED;
23265d
+    if (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_ACTIVE && !inPostCopy)
23265d
+        priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
23265d
 
23265d
     cookieFlags |= QEMU_MIGRATION_COOKIE_NETWORK |
23265d
                    QEMU_MIGRATION_COOKIE_STATS;
23265d
@@ -3921,7 +3919,7 @@ qemuMigrationRun(virQEMUDriverPtr driver,
23265d
     goto cleanup;
23265d
 
23265d
  cancelPostCopy:
23265d
-    priv->job.current->type = VIR_DOMAIN_JOB_FAILED;
23265d
+    priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_FAILED;
23265d
     if (inPostCopy)
23265d
         goto cancel;
23265d
     else
23265d
@@ -5640,7 +5638,7 @@ qemuMigrationJobStart(virQEMUDriverPtr driver,
23265d
         return -1;
23265d
 
23265d
     qemuDomainObjSetAsyncJobMask(vm, mask);
23265d
-    priv->job.current->type = VIR_DOMAIN_JOB_UNBOUNDED;
23265d
+    priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_ACTIVE;
23265d
 
23265d
     return 0;
23265d
 }
23265d
diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c
23265d
index 5f8595fdba..4914c77ef0 100644
23265d
--- a/src/qemu/qemu_migration_cookie.c
23265d
+++ b/src/qemu/qemu_migration_cookie.c
23265d
@@ -974,7 +974,7 @@ qemuMigrationCookieStatisticsXMLParse(xmlXPathContextPtr ctxt)
23265d
         goto cleanup;
23265d
 
23265d
     stats = &jobInfo->stats;
23265d
-    jobInfo->type = VIR_DOMAIN_JOB_COMPLETED;
23265d
+    jobInfo->status = QEMU_DOMAIN_JOB_STATUS_COMPLETED;
23265d
 
23265d
     virXPathULongLong("string(./started[1])", ctxt, &jobInfo->started);
23265d
     virXPathULongLong("string(./stopped[1])", ctxt, &jobInfo->stopped);
23265d
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
23265d
index 6ce33c0134..3235cebad0 100644
23265d
--- a/src/qemu/qemu_process.c
23265d
+++ b/src/qemu/qemu_process.c
23265d
@@ -3950,7 +3950,7 @@ qemuProcessBeginJob(virQEMUDriverPtr driver,
23265d
         return -1;
23265d
 
23265d
     qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_NONE);
23265d
-    priv->job.current->type = VIR_DOMAIN_JOB_UNBOUNDED;
23265d
+    priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_ACTIVE;
23265d
 
23265d
     return 0;
23265d
 }
23265d
-- 
23265d
2.15.1
23265d