[GSoC][PATCH 1/2] qemu_domain: Avoid using qemuDomainObjPrivatePtr as parameter

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

 



In functions `qemuDomainObjInitJob`, `qemuDomainObjResetJob`,
`qemuDomainObjResetAgentJob`, `qemuDomainObjResetAsyncJob`,
`qemuDomainObjFreeJob`, `qemuDomainJobAllowed`,
`qemuDomainNestedJobAllowed` we avoid sending the complete
qemuDomainObjPrivatePtr as parameter and instead just send
qemuDomainJobObjPtr.

This is done in a effort to separating the qemu-job APIs into
a spearate file.

Signed-off-by: Prathamesh Chavan <pc44800@xxxxxxxxx>
---
 src/qemu/qemu_domain.c | 94 ++++++++++++++++++++----------------------
 src/qemu/qemu_domain.h |  4 +-
 2 files changed, 46 insertions(+), 52 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2375b0de35..1ddaa922c5 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -350,15 +350,15 @@ qemuDomainEventEmitJobCompleted(virQEMUDriverPtr driver,
 
 
 static int
-qemuDomainObjInitJob(qemuDomainObjPrivatePtr priv)
+qemuDomainObjInitJob(qemuDomainJobObjPtr job)
 {
-    memset(&priv->job, 0, sizeof(priv->job));
+    memset(job, 0, sizeof(*job));
 
-    if (virCondInit(&priv->job.cond) < 0)
+    if (virCondInit(&job->cond) < 0)
         return -1;
 
-    if (virCondInit(&priv->job.asyncCond) < 0) {
-        virCondDestroy(&priv->job.cond);
+    if (virCondInit(&job->asyncCond) < 0) {
+        virCondDestroy(&job->cond);
         return -1;
     }
 
@@ -366,10 +366,8 @@ qemuDomainObjInitJob(qemuDomainObjPrivatePtr priv)
 }
 
 static void
-qemuDomainObjResetJob(qemuDomainObjPrivatePtr priv)
+qemuDomainObjResetJob(qemuDomainJobObjPtr job)
 {
-    qemuDomainJobObjPtr job = &priv->job;
-
     job->active = QEMU_JOB_NONE;
     job->owner = 0;
     job->ownerAPI = NULL;
@@ -378,10 +376,8 @@ qemuDomainObjResetJob(qemuDomainObjPrivatePtr priv)
 
 
 static void
-qemuDomainObjResetAgentJob(qemuDomainObjPrivatePtr priv)
+qemuDomainObjResetAgentJob(qemuDomainJobObjPtr job)
 {
-    qemuDomainJobObjPtr job = &priv->job;
-
     job->agentActive = QEMU_AGENT_JOB_NONE;
     job->agentOwner = 0;
     job->agentOwnerAPI = NULL;
@@ -390,10 +386,8 @@ qemuDomainObjResetAgentJob(qemuDomainObjPrivatePtr priv)
 
 
 static void
-qemuDomainObjResetAsyncJob(qemuDomainObjPrivatePtr priv)
+qemuDomainObjResetAsyncJob(qemuDomainJobObjPtr job)
 {
-    qemuDomainJobObjPtr job = &priv->job;
-
     job->asyncJob = QEMU_ASYNC_JOB_NONE;
     job->asyncOwner = 0;
     job->asyncOwnerAPI = NULL;
@@ -426,19 +420,19 @@ qemuDomainObjRestoreJob(virDomainObjPtr obj,
     job->migParams = g_steal_pointer(&priv->job.migParams);
     job->apiFlags = priv->job.apiFlags;
 
-    qemuDomainObjResetJob(priv);
-    qemuDomainObjResetAsyncJob(priv);
+    qemuDomainObjResetJob(&priv->job);
+    qemuDomainObjResetAsyncJob(&priv->job);
 }
 
 static void
-qemuDomainObjFreeJob(qemuDomainObjPrivatePtr priv)
+qemuDomainObjFreeJob(qemuDomainJobObjPtr job)
 {
-    qemuDomainObjResetJob(priv);
-    qemuDomainObjResetAsyncJob(priv);
-    g_clear_pointer(&priv->job.current, qemuDomainJobInfoFree);
-    g_clear_pointer(&priv->job.completed, qemuDomainJobInfoFree);
-    virCondDestroy(&priv->job.cond);
-    virCondDestroy(&priv->job.asyncCond);
+    qemuDomainObjResetJob(job);
+    qemuDomainObjResetAsyncJob(job);
+    g_clear_pointer(&job->current, qemuDomainJobInfoFree);
+    g_clear_pointer(&job->completed, qemuDomainJobInfoFree);
+    virCondDestroy(&job->cond);
+    virCondDestroy(&job->asyncCond);
 }
 
 static bool
@@ -2231,7 +2225,7 @@ qemuDomainObjPrivateAlloc(void *opaque)
     if (VIR_ALLOC(priv) < 0)
         return NULL;
 
-    if (qemuDomainObjInitJob(priv) < 0) {
+    if (qemuDomainObjInitJob(&priv->job) < 0) {
         virReportSystemError(errno, "%s",
                              _("Unable to init qemu driver mutexes"));
         goto error;
@@ -2342,7 +2336,7 @@ qemuDomainObjPrivateFree(void *data)
     qemuDomainObjPrivateDataClear(priv);
 
     virObjectUnref(priv->monConfig);
-    qemuDomainObjFreeJob(priv);
+    qemuDomainObjFreeJob(&priv->job);
     VIR_FREE(priv->lockState);
     VIR_FREE(priv->origname);
 
@@ -6215,8 +6209,8 @@ qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver, virDomainObjPtr obj)
     qemuDomainObjPrivatePtr priv = obj->privateData;
 
     if (priv->job.active == QEMU_JOB_ASYNC_NESTED)
-        qemuDomainObjResetJob(priv);
-    qemuDomainObjResetAsyncJob(priv);
+        qemuDomainObjResetJob(&priv->job);
+    qemuDomainObjResetAsyncJob(&priv->job);
     qemuDomainObjSaveStatus(driver, obj);
 }
 
@@ -6237,28 +6231,28 @@ qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj)
 }
 
 static bool
-qemuDomainNestedJobAllowed(qemuDomainObjPrivatePtr priv, qemuDomainJob job)
+qemuDomainNestedJobAllowed(qemuDomainJobObjPtr jobs, qemuDomainJob newJob)
 {
-    return !priv->job.asyncJob ||
-           job == QEMU_JOB_NONE ||
-           (priv->job.mask & JOB_MASK(job)) != 0;
+    return !jobs->asyncJob ||
+           newJob == QEMU_JOB_NONE ||
+           (jobs->mask & JOB_MASK(newJob)) != 0;
 }
 
 bool
-qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv, qemuDomainJob job)
+qemuDomainJobAllowed(qemuDomainJobObjPtr jobs, qemuDomainJob newJob)
 {
-    return !priv->job.active && qemuDomainNestedJobAllowed(priv, job);
+    return !jobs->active && qemuDomainNestedJobAllowed(jobs, newJob);
 }
 
 static bool
-qemuDomainObjCanSetJob(qemuDomainObjPrivatePtr priv,
-                       qemuDomainJob job,
-                       qemuDomainAgentJob agentJob)
+qemuDomainObjCanSetJob(qemuDomainJobObjPtr job,
+                       qemuDomainJob newJob,
+                       qemuDomainAgentJob newAgentJob)
 {
-    return ((job == QEMU_JOB_NONE ||
-             priv->job.active == QEMU_JOB_NONE) &&
-            (agentJob == QEMU_AGENT_JOB_NONE ||
-             priv->job.agentActive == QEMU_AGENT_JOB_NONE));
+    return ((newJob == QEMU_JOB_NONE ||
+             job->active == QEMU_JOB_NONE) &&
+            (newAgentJob == QEMU_AGENT_JOB_NONE ||
+             job->agentActive == QEMU_AGENT_JOB_NONE));
 }
 
 /* Give up waiting for mutex after 30 seconds */
@@ -6330,7 +6324,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
         goto error;
     }
 
-    while (!nested && !qemuDomainNestedJobAllowed(priv, job)) {
+    while (!nested && !qemuDomainNestedJobAllowed(&priv->job, job)) {
         if (nowait)
             goto cleanup;
 
@@ -6339,7 +6333,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
             goto error;
     }
 
-    while (!qemuDomainObjCanSetJob(priv, job, agentJob)) {
+    while (!qemuDomainObjCanSetJob(&priv->job, job, agentJob)) {
         if (nowait)
             goto cleanup;
 
@@ -6350,13 +6344,13 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
 
     /* No job is active but a new async job could have been started while obj
      * was unlocked, so we need to recheck it. */
-    if (!nested && !qemuDomainNestedJobAllowed(priv, job))
+    if (!nested && !qemuDomainNestedJobAllowed(&priv->job, job))
         goto retry;
 
     ignore_value(virTimeMillisNow(&now));
 
     if (job) {
-        qemuDomainObjResetJob(priv);
+        qemuDomainObjResetJob(&priv->job);
 
         if (job != QEMU_JOB_ASYNC) {
             VIR_DEBUG("Started job: %s (async=%s vm=%p name=%s)",
@@ -6371,7 +6365,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
             VIR_DEBUG("Started async job: %s (vm=%p name=%s)",
                       qemuDomainAsyncJobTypeToString(asyncJob),
                       obj, obj->def->name);
-            qemuDomainObjResetAsyncJob(priv);
+            qemuDomainObjResetAsyncJob(&priv->job);
             priv->job.current = g_new0(qemuDomainJobInfo, 1);
             priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_ACTIVE;
             priv->job.asyncJob = asyncJob;
@@ -6383,7 +6377,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
     }
 
     if (agentJob) {
-        qemuDomainObjResetAgentJob(priv);
+        qemuDomainObjResetAgentJob(&priv->job);
 
         VIR_DEBUG("Started agent job: %s (vm=%p name=%s job=%s async=%s)",
                   qemuDomainAgentJobTypeToString(agentJob),
@@ -6428,7 +6422,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
              duration / 1000, agentDuration / 1000, asyncDuration / 1000);
 
     if (job) {
-        if (nested || qemuDomainNestedJobAllowed(priv, job))
+        if (nested || qemuDomainNestedJobAllowed(&priv->job, job))
             blocker = priv->job.ownerAPI;
         else
             blocker = priv->job.asyncOwnerAPI;
@@ -6617,7 +6611,7 @@ qemuDomainObjEndJob(virQEMUDriverPtr driver, virDomainObjPtr obj)
               qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
               obj, obj->def->name);
 
-    qemuDomainObjResetJob(priv);
+    qemuDomainObjResetJob(&priv->job);
     if (qemuDomainTrackJob(job))
         qemuDomainObjSaveStatus(driver, obj);
     /* We indeed need to wake up ALL threads waiting because
@@ -6638,7 +6632,7 @@ qemuDomainObjEndAgentJob(virDomainObjPtr obj)
               qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
               obj, obj->def->name);
 
-    qemuDomainObjResetAgentJob(priv);
+    qemuDomainObjResetAgentJob(&priv->job);
     /* We indeed need to wake up ALL threads waiting because
      * grabbing a job requires checking more variables. */
     virCondBroadcast(&priv->job.cond);
@@ -6655,7 +6649,7 @@ qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver, virDomainObjPtr obj)
               qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
               obj, obj->def->name);
 
-    qemuDomainObjResetAsyncJob(priv);
+    qemuDomainObjResetAsyncJob(&priv->job);
     qemuDomainObjSaveStatus(driver, obj);
     virCondBroadcast(&priv->job.asyncCond);
 }
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index e78a2b935d..19e80fef2b 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -860,8 +860,8 @@ void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
                              virDomainObjPtr vm,
                              bool value);
 
-bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv,
-                          qemuDomainJob job);
+bool qemuDomainJobAllowed(qemuDomainJobObjPtr jobs,
+                          qemuDomainJob newJob);
 
 int qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
-- 
2.17.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