`qemuDomainJobPrivateJobCallbacks` structure was nested inside `qemuDomainJobPrivateCallbacks` structure, so that in future we may add generic callbacks that we can't really categorize into the later callback structure. Signed-off-by: Prathamesh Chavan <pc44800@xxxxxxxxx> --- src/qemu/qemu_domain.c | 8 ++++++-- src/qemu/qemu_domainjob.c | 40 +++++++++++++++++++-------------------- src/qemu/qemu_domainjob.h | 39 ++++++++++++++++++++++---------------- 3 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f366c77191..87c72575d0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -805,7 +805,7 @@ qemuDomainGetMaxQueuedJobs(virDomainObjPtr vm) return cfg->maxQueuedJobs; } -static qemuDomainObjPrivateJobCallbacks qemuPrivateJobCallbacks = { +static qemuDomainJobPrivateJobCallbacks qemuJobPrivateJobCallbacks = { .allocJobPrivate = qemuJobAllocPrivate, .freeJobPrivate = qemuJobFreePrivate, .resetJobPrivate = qemuJobResetPrivate, @@ -819,6 +819,10 @@ static qemuDomainObjPrivateJobCallbacks qemuPrivateJobCallbacks = { .getMaxQueuedJobs = qemuDomainGetMaxQueuedJobs, }; +static qemuDomainJobPrivateCallbacks qemuJobPrivateCallbacks = { + .jobcb = &qemuJobPrivateJobCallbacks, +}; + /** * qemuDomainObjFromDomain: * @domain: Domain pointer that has to be looked up @@ -2270,7 +2274,7 @@ qemuDomainObjPrivateAlloc(void *opaque) if (VIR_ALLOC(priv) < 0) return NULL; - if (qemuDomainObjInitJob(&priv->job, &qemuPrivateJobCallbacks) < 0) { + if (qemuDomainObjInitJob(&priv->job, &qemuJobPrivateCallbacks) < 0) { virReportSystemError(errno, "%s", _("Unable to init qemu driver mutexes")); goto error; diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c index 4e29c5a460..3480be88c3 100644 --- a/src/qemu/qemu_domainjob.c +++ b/src/qemu/qemu_domainjob.c @@ -117,21 +117,21 @@ qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job, int qemuDomainObjInitJob(qemuDomainJobObjPtr job, - qemuDomainObjPrivateJobCallbacksPtr cb) + qemuDomainJobPrivateCallbacksPtr cb) { memset(job, 0, sizeof(*job)); job->cb = cb; - if (!(job->privateData = job->cb->allocJobPrivate())) + if (!(job->privateData = job->cb->jobcb->allocJobPrivate())) return -1; if (virCondInit(&job->cond) < 0) { - job->cb->freeJobPrivate(job->privateData); + job->cb->jobcb->freeJobPrivate(job->privateData); return -1; } if (virCondInit(&job->asyncCond) < 0) { - job->cb->freeJobPrivate(job->privateData); + job->cb->jobcb->freeJobPrivate(job->privateData); virCondDestroy(&job->cond); return -1; } @@ -171,7 +171,7 @@ qemuDomainObjResetAsyncJob(qemuDomainJobObjPtr job) job->mask = QEMU_JOB_DEFAULT_MASK; job->abortJob = false; VIR_FREE(job->error); - job->cb->resetJobPrivate(job->privateData); + job->cb->jobcb->resetJobPrivate(job->privateData); job->apiFlags = 0; } @@ -190,7 +190,7 @@ qemuDomainObjRestoreJob(virDomainObjPtr obj, job->privateData = g_steal_pointer(&priv->job.privateData); job->apiFlags = priv->job.apiFlags; - if (!(priv->job.privateData = priv->job.cb->allocJobPrivate())) + if (!(priv->job.privateData = priv->job.cb->jobcb->allocJobPrivate())) return -1; job->cb = priv->job.cb; @@ -204,7 +204,7 @@ qemuDomainObjFreeJob(qemuDomainJobObjPtr job) { qemuDomainObjResetJob(job); qemuDomainObjResetAsyncJob(job); - job->cb->freeJobPrivate(job->privateData); + job->cb->jobcb->freeJobPrivate(job->privateData); virCondDestroy(&job->cond); virCondDestroy(&job->asyncCond); } @@ -364,13 +364,13 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, if (virTimeMillisNow(&now) < 0) return -1; - priv->job.cb->increaseJobsQueued(obj); + priv->job.cb->jobcb->increaseJobsQueued(obj); then = now + QEMU_JOB_WAIT_TIME; retry: if ((!async && job != QEMU_JOB_DESTROY) && - priv->job.cb->getMaxQueuedJobs(obj) && - priv->job.cb->getJobsQueued(obj) > priv->job.cb->getMaxQueuedJobs(obj)) { + priv->job.cb->jobcb->getMaxQueuedJobs(obj) && + priv->job.cb->jobcb->getJobsQueued(obj) > priv->job.cb->jobcb->getMaxQueuedJobs(obj)) { goto error; } @@ -416,7 +416,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, qemuDomainAsyncJobTypeToString(asyncJob), obj, obj->def->name); qemuDomainObjResetAsyncJob(&priv->job); - priv->job.cb->currentJobInfoInit(&priv->job, now); + priv->job.cb->jobcb->currentJobInfoInit(&priv->job, now); priv->job.asyncJob = asyncJob; priv->job.asyncOwner = virThreadSelfID(); priv->job.asyncOwnerAPI = virThreadJobGet(); @@ -500,8 +500,8 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, _("cannot acquire state change lock")); } ret = -2; - } else if (priv->job.cb->getMaxQueuedJobs(obj) && - priv->job.cb->getJobsQueued(obj) > priv->job.cb->getMaxQueuedJobs(obj)) { + } else if (priv->job.cb->jobcb->getMaxQueuedJobs(obj) && + priv->job.cb->jobcb->getJobsQueued(obj) > priv->job.cb->jobcb->getMaxQueuedJobs(obj)) { if (blocker && agentBlocker) { virReportError(VIR_ERR_OPERATION_FAILED, _("cannot acquire state change " @@ -531,7 +531,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, } cleanup: - priv->job.cb->decreaseJobsQueued(obj); + priv->job.cb->jobcb->decreaseJobsQueued(obj); return ret; } @@ -586,7 +586,7 @@ int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver, return -1; priv = obj->privateData; - priv->job.cb->setJobInfoOperation(&priv->job, operation); + priv->job.cb->jobcb->setJobInfoOperation(&priv->job, operation); priv->job.apiFlags = apiFlags; return 0; } @@ -652,7 +652,7 @@ qemuDomainObjEndJob(virQEMUDriverPtr driver, virDomainObjPtr obj) qemuDomainObjPrivatePtr priv = obj->privateData; qemuDomainJob job = priv->job.active; - priv->job.cb->decreaseJobsQueued(obj); + priv->job.cb->jobcb->decreaseJobsQueued(obj); VIR_DEBUG("Stopping job: %s (async=%s vm=%p name=%s)", qemuDomainJobTypeToString(job), @@ -673,7 +673,7 @@ qemuDomainObjEndAgentJob(virDomainObjPtr obj) qemuDomainObjPrivatePtr priv = obj->privateData; qemuDomainAgentJob agentJob = priv->job.agentActive; - priv->job.cb->decreaseJobsQueued(obj); + priv->job.cb->jobcb->decreaseJobsQueued(obj); VIR_DEBUG("Stopping agent job: %s (async=%s vm=%p name=%s)", qemuDomainAgentJobTypeToString(agentJob), @@ -691,7 +691,7 @@ qemuDomainObjEndAsyncJob(virQEMUDriverPtr driver, virDomainObjPtr obj) { qemuDomainObjPrivatePtr priv = obj->privateData; - priv->job.cb->decreaseJobsQueued(obj); + priv->job.cb->jobcb->decreaseJobsQueued(obj); VIR_DEBUG("Stopping async job: %s (vm=%p name=%s)", qemuDomainAsyncJobTypeToString(priv->job.asyncJob), @@ -744,7 +744,7 @@ qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf, if (priv->job.asyncJob != QEMU_ASYNC_JOB_NONE) virBufferAsprintf(&attrBuf, " flags='0x%lx'", priv->job.apiFlags); - if (priv->job.cb->formatJob(&childBuf, &priv->job, vm) < 0) + if (priv->job.cb->jobcb->formatJob(&childBuf, &priv->job, vm) < 0) return -1; virXMLFormatElement(buf, "job", &attrBuf, &childBuf); @@ -804,7 +804,7 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm, return -1; } - if (priv->job.cb->parseJob(ctxt, job, vm) < 0) + if (priv->job.cb->jobcb->parseJob(ctxt, job, vm) < 0) return -1; return 0; diff --git a/src/qemu/qemu_domainjob.h b/src/qemu/qemu_domainjob.h index f3d9218ec0..211503b439 100644 --- a/src/qemu/qemu_domainjob.h +++ b/src/qemu/qemu_domainjob.h @@ -118,20 +118,27 @@ typedef void (*qemuDomainObjIncreaseJobsQueued)(virDomainObjPtr); typedef void (*qemuDomainObjDecreaseJobsQueued)(virDomainObjPtr); typedef int (*qemuDomainObjGetMaxQueuedJobs)(virDomainObjPtr); -typedef struct _qemuDomainObjPrivateJobCallbacks qemuDomainObjPrivateJobCallbacks; -typedef qemuDomainObjPrivateJobCallbacks *qemuDomainObjPrivateJobCallbacksPtr; -struct _qemuDomainObjPrivateJobCallbacks { - qemuDomainObjPrivateJobAlloc allocJobPrivate; - qemuDomainObjPrivateJobFree freeJobPrivate; - qemuDomainObjPrivateJobReset resetJobPrivate; - qemuDomainObjPrivateJobFormat formatJob; - qemuDomainObjPrivateJobParse parseJob; - qemuDomainObjJobInfoSetOperation setJobInfoOperation; - qemuDomainObjCurrentJobInfoInit currentJobInfoInit; - qemuDomainObjGetJobsQueued getJobsQueued; - qemuDomainObjIncreaseJobsQueued increaseJobsQueued; - qemuDomainObjDecreaseJobsQueued decreaseJobsQueued; - qemuDomainObjGetMaxQueuedJobs getMaxQueuedJobs; +typedef struct _qemuDomainJobPrivateJobCallbacks qemuDomainJobPrivateJobCallbacks; +typedef qemuDomainJobPrivateJobCallbacks *qemuDomainJobPrivateJobCallbacksPtr; +struct _qemuDomainJobPrivateJobCallbacks { + qemuDomainObjPrivateJobAlloc allocJobPrivate; + qemuDomainObjPrivateJobFree freeJobPrivate; + qemuDomainObjPrivateJobReset resetJobPrivate; + qemuDomainObjPrivateJobFormat formatJob; + qemuDomainObjPrivateJobParse parseJob; + qemuDomainObjJobInfoSetOperation setJobInfoOperation; + qemuDomainObjCurrentJobInfoInit currentJobInfoInit; + qemuDomainObjGetJobsQueued getJobsQueued; + qemuDomainObjIncreaseJobsQueued increaseJobsQueued; + qemuDomainObjDecreaseJobsQueued decreaseJobsQueued; + qemuDomainObjGetMaxQueuedJobs getMaxQueuedJobs; +}; + +typedef struct _qemuDomainJobPrivateCallbacks qemuDomainJobPrivateCallbacks; +typedef qemuDomainJobPrivateCallbacks *qemuDomainJobPrivateCallbacksPtr; +struct _qemuDomainJobPrivateCallbacks { + /* Job related callbacks */ + qemuDomainJobPrivateJobCallbacksPtr jobcb; }; struct _qemuDomainJobObj { @@ -162,7 +169,7 @@ struct _qemuDomainJobObj { unsigned long apiFlags; /* flags passed to the API which started the async job */ void *privateData; /* job specific collection of data */ - qemuDomainObjPrivateJobCallbacksPtr cb; + qemuDomainJobPrivateCallbacksPtr cb; }; const char *qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job, @@ -216,7 +223,7 @@ void qemuDomainObjFreeJob(qemuDomainJobObjPtr job); int qemuDomainObjInitJob(qemuDomainJobObjPtr job, - qemuDomainObjPrivateJobCallbacksPtr cb); + qemuDomainJobPrivateCallbacksPtr cb); bool qemuDomainJobAllowed(qemuDomainJobObjPtr jobs, qemuDomainJob newJob); -- 2.25.1