[libvirt PATCH 13/80] qemu: Add qemuDomainObjRestoreAsyncJob

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

 



The code for setting up a previously active backup job in
qemuProcessRecoverJob is generalized into a dedicated function so that
it can be later reused in other places.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/qemu/qemu_domainjob.c | 35 +++++++++++++++++++++++++++++++++++
 src/qemu/qemu_domainjob.h |  8 ++++++++
 src/qemu/qemu_process.c   | 29 +++++++----------------------
 3 files changed, 50 insertions(+), 22 deletions(-)

diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c
index 1e5724b505..1f82457bd4 100644
--- a/src/qemu/qemu_domainjob.c
+++ b/src/qemu/qemu_domainjob.c
@@ -249,6 +249,41 @@ qemuDomainObjPreserveJob(virDomainObj *obj,
     return 0;
 }
 
+
+void
+qemuDomainObjRestoreAsyncJob(virDomainObj *vm,
+                             virDomainAsyncJob asyncJob,
+                             int phase,
+                             virDomainJobOperation operation,
+                             qemuDomainJobStatsType statsType,
+                             virDomainJobStatus status,
+                             unsigned long long allowedJobs)
+{
+    qemuDomainObjPrivate *priv = vm->privateData;
+    qemuDomainJobObj *job = &priv->job;
+    unsigned long long now;
+
+    VIR_DEBUG("Restoring %s async job for domain %s",
+              virDomainAsyncJobTypeToString(asyncJob), vm->def->name);
+
+    ignore_value(virTimeMillisNow(&now));
+
+    priv->job.jobsQueued++;
+    job->asyncJob = asyncJob;
+    job->phase = phase;
+    job->asyncOwnerAPI = g_strdup(virThreadJobGet());
+    job->asyncStarted = now;
+
+    qemuDomainObjSetAsyncJobMask(vm, allowedJobs);
+
+    job->current = virDomainJobDataInit(&qemuJobDataPrivateDataCallbacks);
+    qemuDomainJobSetStatsType(priv->job.current, statsType);
+    job->current->operation = operation;
+    job->current->status = status;
+    job->current->started = now;
+}
+
+
 void
 qemuDomainObjClearJob(qemuDomainJobObj *job)
 {
diff --git a/src/qemu/qemu_domainjob.h b/src/qemu/qemu_domainjob.h
index 2bbccf6329..069bb9f8cb 100644
--- a/src/qemu/qemu_domainjob.h
+++ b/src/qemu/qemu_domainjob.h
@@ -160,6 +160,14 @@ void qemuDomainObjSetAsyncJobMask(virDomainObj *obj,
                                   unsigned long long allowedJobs);
 int qemuDomainObjPreserveJob(virDomainObj *obj,
                              qemuDomainJobObj *job);
+void
+qemuDomainObjRestoreAsyncJob(virDomainObj *vm,
+                             virDomainAsyncJob asyncJob,
+                             int phase,
+                             virDomainJobOperation operation,
+                             qemuDomainJobStatsType statsType,
+                             virDomainJobStatus status,
+                             unsigned long long allowedJobs);
 void qemuDomainObjDiscardAsyncJob(virDomainObj *obj);
 void qemuDomainObjReleaseAsyncJob(virDomainObj *obj);
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index db0d9935be..590e989126 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3628,7 +3628,6 @@ qemuProcessRecoverJob(virQEMUDriver *driver,
     qemuDomainObjPrivate *priv = vm->privateData;
     virDomainState state;
     int reason;
-    unsigned long long now;
 
     state = virDomainObjGetState(vm, &reason);
 
@@ -3685,28 +3684,14 @@ qemuProcessRecoverJob(virQEMUDriver *driver,
         break;
 
     case VIR_ASYNC_JOB_BACKUP:
-        ignore_value(virTimeMillisNow(&now));
-
         /* Restore the config of the async job which is not persisted */
-        priv->job.jobsQueued++;
-        priv->job.asyncJob = VIR_ASYNC_JOB_BACKUP;
-        priv->job.asyncOwnerAPI = g_strdup(virThreadJobGet());
-        priv->job.asyncStarted = now;
-
-        qemuDomainObjSetAsyncJobMask(vm, (VIR_JOB_DEFAULT_MASK |
-                                          JOB_MASK(VIR_JOB_SUSPEND) |
-                                          JOB_MASK(VIR_JOB_MODIFY)));
-
-        /* We reset the job parameters for backup so that the job will look
-         * active. This is possible because we are able to recover the state
-         * of blockjobs and also the backup job allows all sub-job types */
-        priv->job.current = virDomainJobDataInit(&qemuJobDataPrivateDataCallbacks);
-
-        qemuDomainJobSetStatsType(priv->job.current,
-                                  QEMU_DOMAIN_JOB_STATS_TYPE_BACKUP);
-        priv->job.current->operation = VIR_DOMAIN_JOB_OPERATION_BACKUP;
-        priv->job.current->status = VIR_DOMAIN_JOB_STATUS_ACTIVE;
-        priv->job.current->started = now;
+        qemuDomainObjRestoreAsyncJob(vm, VIR_ASYNC_JOB_BACKUP, 0,
+                                     VIR_DOMAIN_JOB_OPERATION_BACKUP,
+                                     QEMU_DOMAIN_JOB_STATS_TYPE_BACKUP,
+                                     VIR_DOMAIN_JOB_STATUS_ACTIVE,
+                                     (VIR_JOB_DEFAULT_MASK |
+                                      JOB_MASK(VIR_JOB_SUSPEND) |
+                                      JOB_MASK(VIR_JOB_MODIFY)));
         break;
 
     case VIR_ASYNC_JOB_NONE:
-- 
2.35.1




[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