提交 6d0b1d2d 编写于 作者: P Prathamesh Chavan 提交者: Michal Privoznik

qemu_domain: Avoid using qemuDomainObjPrivatePtr as parameter

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: NPrathamesh Chavan <pc44800@gmail.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 be997aaa
...@@ -350,15 +350,15 @@ qemuDomainEventEmitJobCompleted(virQEMUDriverPtr driver, ...@@ -350,15 +350,15 @@ qemuDomainEventEmitJobCompleted(virQEMUDriverPtr driver,
static int 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; return -1;
if (virCondInit(&priv->job.asyncCond) < 0) { if (virCondInit(&job->asyncCond) < 0) {
virCondDestroy(&priv->job.cond); virCondDestroy(&job->cond);
return -1; return -1;
} }
...@@ -366,10 +366,8 @@ qemuDomainObjInitJob(qemuDomainObjPrivatePtr priv) ...@@ -366,10 +366,8 @@ qemuDomainObjInitJob(qemuDomainObjPrivatePtr priv)
} }
static void static void
qemuDomainObjResetJob(qemuDomainObjPrivatePtr priv) qemuDomainObjResetJob(qemuDomainJobObjPtr job)
{ {
qemuDomainJobObjPtr job = &priv->job;
job->active = QEMU_JOB_NONE; job->active = QEMU_JOB_NONE;
job->owner = 0; job->owner = 0;
job->ownerAPI = NULL; job->ownerAPI = NULL;
...@@ -378,10 +376,8 @@ qemuDomainObjResetJob(qemuDomainObjPrivatePtr priv) ...@@ -378,10 +376,8 @@ qemuDomainObjResetJob(qemuDomainObjPrivatePtr priv)
static void static void
qemuDomainObjResetAgentJob(qemuDomainObjPrivatePtr priv) qemuDomainObjResetAgentJob(qemuDomainJobObjPtr job)
{ {
qemuDomainJobObjPtr job = &priv->job;
job->agentActive = QEMU_AGENT_JOB_NONE; job->agentActive = QEMU_AGENT_JOB_NONE;
job->agentOwner = 0; job->agentOwner = 0;
job->agentOwnerAPI = NULL; job->agentOwnerAPI = NULL;
...@@ -390,10 +386,8 @@ qemuDomainObjResetAgentJob(qemuDomainObjPrivatePtr priv) ...@@ -390,10 +386,8 @@ qemuDomainObjResetAgentJob(qemuDomainObjPrivatePtr priv)
static void static void
qemuDomainObjResetAsyncJob(qemuDomainObjPrivatePtr priv) qemuDomainObjResetAsyncJob(qemuDomainJobObjPtr job)
{ {
qemuDomainJobObjPtr job = &priv->job;
job->asyncJob = QEMU_ASYNC_JOB_NONE; job->asyncJob = QEMU_ASYNC_JOB_NONE;
job->asyncOwner = 0; job->asyncOwner = 0;
job->asyncOwnerAPI = NULL; job->asyncOwnerAPI = NULL;
...@@ -426,19 +420,19 @@ qemuDomainObjRestoreJob(virDomainObjPtr obj, ...@@ -426,19 +420,19 @@ qemuDomainObjRestoreJob(virDomainObjPtr obj,
job->migParams = g_steal_pointer(&priv->job.migParams); job->migParams = g_steal_pointer(&priv->job.migParams);
job->apiFlags = priv->job.apiFlags; job->apiFlags = priv->job.apiFlags;
qemuDomainObjResetJob(priv); qemuDomainObjResetJob(&priv->job);
qemuDomainObjResetAsyncJob(priv); qemuDomainObjResetAsyncJob(&priv->job);
} }
static void static void
qemuDomainObjFreeJob(qemuDomainObjPrivatePtr priv) qemuDomainObjFreeJob(qemuDomainJobObjPtr job)
{ {
qemuDomainObjResetJob(priv); qemuDomainObjResetJob(job);
qemuDomainObjResetAsyncJob(priv); qemuDomainObjResetAsyncJob(job);
g_clear_pointer(&priv->job.current, qemuDomainJobInfoFree); g_clear_pointer(&job->current, qemuDomainJobInfoFree);
g_clear_pointer(&priv->job.completed, qemuDomainJobInfoFree); g_clear_pointer(&job->completed, qemuDomainJobInfoFree);
virCondDestroy(&priv->job.cond); virCondDestroy(&job->cond);
virCondDestroy(&priv->job.asyncCond); virCondDestroy(&job->asyncCond);
} }
static bool static bool
...@@ -2231,7 +2225,7 @@ qemuDomainObjPrivateAlloc(void *opaque) ...@@ -2231,7 +2225,7 @@ qemuDomainObjPrivateAlloc(void *opaque)
if (VIR_ALLOC(priv) < 0) if (VIR_ALLOC(priv) < 0)
return NULL; return NULL;
if (qemuDomainObjInitJob(priv) < 0) { if (qemuDomainObjInitJob(&priv->job) < 0) {
virReportSystemError(errno, "%s", virReportSystemError(errno, "%s",
_("Unable to init qemu driver mutexes")); _("Unable to init qemu driver mutexes"));
goto error; goto error;
...@@ -2342,7 +2336,7 @@ qemuDomainObjPrivateFree(void *data) ...@@ -2342,7 +2336,7 @@ qemuDomainObjPrivateFree(void *data)
qemuDomainObjPrivateDataClear(priv); qemuDomainObjPrivateDataClear(priv);
virObjectUnref(priv->monConfig); virObjectUnref(priv->monConfig);
qemuDomainObjFreeJob(priv); qemuDomainObjFreeJob(&priv->job);
VIR_FREE(priv->lockState); VIR_FREE(priv->lockState);
VIR_FREE(priv->origname); VIR_FREE(priv->origname);
...@@ -6254,8 +6248,8 @@ qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver, virDomainObjPtr obj) ...@@ -6254,8 +6248,8 @@ qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver, virDomainObjPtr obj)
qemuDomainObjPrivatePtr priv = obj->privateData; qemuDomainObjPrivatePtr priv = obj->privateData;
if (priv->job.active == QEMU_JOB_ASYNC_NESTED) if (priv->job.active == QEMU_JOB_ASYNC_NESTED)
qemuDomainObjResetJob(priv); qemuDomainObjResetJob(&priv->job);
qemuDomainObjResetAsyncJob(priv); qemuDomainObjResetAsyncJob(&priv->job);
qemuDomainObjSaveStatus(driver, obj); qemuDomainObjSaveStatus(driver, obj);
} }
...@@ -6276,28 +6270,28 @@ qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj) ...@@ -6276,28 +6270,28 @@ qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj)
} }
static bool static bool
qemuDomainNestedJobAllowed(qemuDomainObjPrivatePtr priv, qemuDomainJob job) qemuDomainNestedJobAllowed(qemuDomainJobObjPtr jobs, qemuDomainJob newJob)
{ {
return !priv->job.asyncJob || return !jobs->asyncJob ||
job == QEMU_JOB_NONE || newJob == QEMU_JOB_NONE ||
(priv->job.mask & JOB_MASK(job)) != 0; (jobs->mask & JOB_MASK(newJob)) != 0;
} }
bool 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 static bool
qemuDomainObjCanSetJob(qemuDomainObjPrivatePtr priv, qemuDomainObjCanSetJob(qemuDomainJobObjPtr job,
qemuDomainJob job, qemuDomainJob newJob,
qemuDomainAgentJob agentJob) qemuDomainAgentJob newAgentJob)
{ {
return ((job == QEMU_JOB_NONE || return ((newJob == QEMU_JOB_NONE ||
priv->job.active == QEMU_JOB_NONE) && job->active == QEMU_JOB_NONE) &&
(agentJob == QEMU_AGENT_JOB_NONE || (newAgentJob == QEMU_AGENT_JOB_NONE ||
priv->job.agentActive == QEMU_AGENT_JOB_NONE)); job->agentActive == QEMU_AGENT_JOB_NONE));
} }
/* Give up waiting for mutex after 30 seconds */ /* Give up waiting for mutex after 30 seconds */
...@@ -6369,7 +6363,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, ...@@ -6369,7 +6363,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
goto error; goto error;
} }
while (!nested && !qemuDomainNestedJobAllowed(priv, job)) { while (!nested && !qemuDomainNestedJobAllowed(&priv->job, job)) {
if (nowait) if (nowait)
goto cleanup; goto cleanup;
...@@ -6378,7 +6372,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, ...@@ -6378,7 +6372,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
goto error; goto error;
} }
while (!qemuDomainObjCanSetJob(priv, job, agentJob)) { while (!qemuDomainObjCanSetJob(&priv->job, job, agentJob)) {
if (nowait) if (nowait)
goto cleanup; goto cleanup;
...@@ -6389,13 +6383,13 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, ...@@ -6389,13 +6383,13 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
/* No job is active but a new async job could have been started while obj /* No job is active but a new async job could have been started while obj
* was unlocked, so we need to recheck it. */ * was unlocked, so we need to recheck it. */
if (!nested && !qemuDomainNestedJobAllowed(priv, job)) if (!nested && !qemuDomainNestedJobAllowed(&priv->job, job))
goto retry; goto retry;
ignore_value(virTimeMillisNow(&now)); ignore_value(virTimeMillisNow(&now));
if (job) { if (job) {
qemuDomainObjResetJob(priv); qemuDomainObjResetJob(&priv->job);
if (job != QEMU_JOB_ASYNC) { if (job != QEMU_JOB_ASYNC) {
VIR_DEBUG("Started job: %s (async=%s vm=%p name=%s)", VIR_DEBUG("Started job: %s (async=%s vm=%p name=%s)",
...@@ -6410,7 +6404,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, ...@@ -6410,7 +6404,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
VIR_DEBUG("Started async job: %s (vm=%p name=%s)", VIR_DEBUG("Started async job: %s (vm=%p name=%s)",
qemuDomainAsyncJobTypeToString(asyncJob), qemuDomainAsyncJobTypeToString(asyncJob),
obj, obj->def->name); obj, obj->def->name);
qemuDomainObjResetAsyncJob(priv); qemuDomainObjResetAsyncJob(&priv->job);
priv->job.current = g_new0(qemuDomainJobInfo, 1); priv->job.current = g_new0(qemuDomainJobInfo, 1);
priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_ACTIVE; priv->job.current->status = QEMU_DOMAIN_JOB_STATUS_ACTIVE;
priv->job.asyncJob = asyncJob; priv->job.asyncJob = asyncJob;
...@@ -6422,7 +6416,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, ...@@ -6422,7 +6416,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
} }
if (agentJob) { if (agentJob) {
qemuDomainObjResetAgentJob(priv); qemuDomainObjResetAgentJob(&priv->job);
VIR_DEBUG("Started agent job: %s (vm=%p name=%s job=%s async=%s)", VIR_DEBUG("Started agent job: %s (vm=%p name=%s job=%s async=%s)",
qemuDomainAgentJobTypeToString(agentJob), qemuDomainAgentJobTypeToString(agentJob),
...@@ -6467,7 +6461,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, ...@@ -6467,7 +6461,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
duration / 1000, agentDuration / 1000, asyncDuration / 1000); duration / 1000, agentDuration / 1000, asyncDuration / 1000);
if (job) { if (job) {
if (nested || qemuDomainNestedJobAllowed(priv, job)) if (nested || qemuDomainNestedJobAllowed(&priv->job, job))
blocker = priv->job.ownerAPI; blocker = priv->job.ownerAPI;
else else
blocker = priv->job.asyncOwnerAPI; blocker = priv->job.asyncOwnerAPI;
...@@ -6656,7 +6650,7 @@ qemuDomainObjEndJob(virQEMUDriverPtr driver, virDomainObjPtr obj) ...@@ -6656,7 +6650,7 @@ qemuDomainObjEndJob(virQEMUDriverPtr driver, virDomainObjPtr obj)
qemuDomainAsyncJobTypeToString(priv->job.asyncJob), qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
obj, obj->def->name); obj, obj->def->name);
qemuDomainObjResetJob(priv); qemuDomainObjResetJob(&priv->job);
if (qemuDomainTrackJob(job)) if (qemuDomainTrackJob(job))
qemuDomainObjSaveStatus(driver, obj); qemuDomainObjSaveStatus(driver, obj);
/* We indeed need to wake up ALL threads waiting because /* We indeed need to wake up ALL threads waiting because
...@@ -6677,7 +6671,7 @@ qemuDomainObjEndAgentJob(virDomainObjPtr obj) ...@@ -6677,7 +6671,7 @@ qemuDomainObjEndAgentJob(virDomainObjPtr obj)
qemuDomainAsyncJobTypeToString(priv->job.asyncJob), qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
obj, obj->def->name); obj, obj->def->name);
qemuDomainObjResetAgentJob(priv); qemuDomainObjResetAgentJob(&priv->job);
/* We indeed need to wake up ALL threads waiting because /* We indeed need to wake up ALL threads waiting because
* grabbing a job requires checking more variables. */ * grabbing a job requires checking more variables. */
virCondBroadcast(&priv->job.cond); virCondBroadcast(&priv->job.cond);
...@@ -6694,7 +6688,7 @@ qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver, virDomainObjPtr obj) ...@@ -6694,7 +6688,7 @@ qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver, virDomainObjPtr obj)
qemuDomainAsyncJobTypeToString(priv->job.asyncJob), qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
obj, obj->def->name); obj, obj->def->name);
qemuDomainObjResetAsyncJob(priv); qemuDomainObjResetAsyncJob(&priv->job);
qemuDomainObjSaveStatus(driver, obj); qemuDomainObjSaveStatus(driver, obj);
virCondBroadcast(&priv->job.asyncCond); virCondBroadcast(&priv->job.asyncCond);
} }
......
...@@ -860,8 +860,8 @@ void qemuDomainSetFakeReboot(virQEMUDriverPtr driver, ...@@ -860,8 +860,8 @@ void qemuDomainSetFakeReboot(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
bool value); bool value);
bool qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv, bool qemuDomainJobAllowed(qemuDomainJobObjPtr jobs,
qemuDomainJob job); qemuDomainJob newJob);
int qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver, int qemuDomainCheckDiskStartupPolicy(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册