Reference to `maxQueuedJobs` required us to access
config of the qemu-driver. To avoid jobs accessing
them directly, we add callback function `getMaxQueuedJobs`
to job's private-callback functions structure.
Signed-off-by: Prathamesh Chavan <pc44800(a)gmail.com>
---
src/qemu/qemu_domain.c | 11 +++++++++++
src/qemu/qemu_domainjob.c | 9 ++++-----
src/qemu/qemu_domainjob.h | 2 ++
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 8deac9d21e..f366c77191 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -797,6 +797,14 @@ qemuDomainDecreaseJobsQueued(virDomainObjPtr vm)
priv->jobs_queued--;
}
+static int
+qemuDomainGetMaxQueuedJobs(virDomainObjPtr vm)
+{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(priv->driver);
+ return cfg->maxQueuedJobs;
+}
+
static qemuDomainObjPrivateJobCallbacks qemuPrivateJobCallbacks = {
.allocJobPrivate = qemuJobAllocPrivate,
.freeJobPrivate = qemuJobFreePrivate,
@@ -808,6 +816,7 @@ static qemuDomainObjPrivateJobCallbacks qemuPrivateJobCallbacks = {
.getJobsQueued = qemuDomainGetJobsQueued,
.increaseJobsQueued = qemuDomainIncreaseJobsQueued,
.decreaseJobsQueued = qemuDomainDecreaseJobsQueued,
+ .getMaxQueuedJobs = qemuDomainGetMaxQueuedJobs,
};
/**
@@ -2255,6 +2264,8 @@ static void *
qemuDomainObjPrivateAlloc(void *opaque)
{
qemuDomainObjPrivatePtr priv;
+ virQEMUDriverPtr driver = opaque;
+ g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
if (VIR_ALLOC(priv) < 0)
return NULL;
diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c
index e15619b792..4e29c5a460 100644
--- a/src/qemu/qemu_domainjob.c
+++ b/src/qemu/qemu_domainjob.c
@@ -344,7 +344,6 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
unsigned long long then;
bool nested = job == QEMU_JOB_ASYNC_NESTED;
bool async = job == QEMU_JOB_ASYNC;
- g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
const char *blocker = NULL;
const char *agentBlocker = NULL;
int ret = -1;
@@ -370,8 +369,8 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
retry:
if ((!async && job != QEMU_JOB_DESTROY) &&
- cfg->maxQueuedJobs &&
- priv->job.cb->getJobsQueued(obj) > cfg->maxQueuedJobs) {
+ priv->job.cb->getMaxQueuedJobs(obj) &&
+ priv->job.cb->getJobsQueued(obj) >
priv->job.cb->getMaxQueuedJobs(obj)) {
goto error;
}
@@ -501,8 +500,8 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
_("cannot acquire state change lock"));
}
ret = -2;
- } else if (cfg->maxQueuedJobs &&
- priv->job.cb->getJobsQueued(obj) > cfg->maxQueuedJobs) {
+ } else if (priv->job.cb->getMaxQueuedJobs(obj) &&
+ priv->job.cb->getJobsQueued(obj) >
priv->job.cb->getMaxQueuedJobs(obj)) {
if (blocker && agentBlocker) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("cannot acquire state change "
diff --git a/src/qemu/qemu_domainjob.h b/src/qemu/qemu_domainjob.h
index d3bc59cbcb..f3d9218ec0 100644
--- a/src/qemu/qemu_domainjob.h
+++ b/src/qemu/qemu_domainjob.h
@@ -116,6 +116,7 @@ typedef void (*qemuDomainObjCurrentJobInfoInit)(qemuDomainJobObjPtr,
typedef int (*qemuDomainObjGetJobsQueued)(virDomainObjPtr);
typedef void (*qemuDomainObjIncreaseJobsQueued)(virDomainObjPtr);
typedef void (*qemuDomainObjDecreaseJobsQueued)(virDomainObjPtr);
+typedef int (*qemuDomainObjGetMaxQueuedJobs)(virDomainObjPtr);
typedef struct _qemuDomainObjPrivateJobCallbacks qemuDomainObjPrivateJobCallbacks;
typedef qemuDomainObjPrivateJobCallbacks *qemuDomainObjPrivateJobCallbacksPtr;
@@ -130,6 +131,7 @@ struct _qemuDomainObjPrivateJobCallbacks {
qemuDomainObjGetJobsQueued getJobsQueued;
qemuDomainObjIncreaseJobsQueued increaseJobsQueued;
qemuDomainObjDecreaseJobsQueued decreaseJobsQueued;
+ qemuDomainObjGetMaxQueuedJobs getMaxQueuedJobs;
};
struct _qemuDomainJobObj {
--
2.25.1