提交 f38ea75b 编写于 作者: M Michal Privoznik

qemu_domain: Introduce qemuDomainObjBeginJobNowait

The aim of this API is to allow the caller to do best effort.
Some functions can work even when acquiring the job fails (e.g.
qemuConnectGetAllDomainStats()). But what they can't bear is
delay if they have to wait up to 30 seconds for each domain that
is processing some other job.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 af0715bb
...@@ -6359,11 +6359,16 @@ qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv, qemuDomainJob job) ...@@ -6359,11 +6359,16 @@ qemuDomainJobAllowed(qemuDomainObjPrivatePtr priv, qemuDomainJob job)
* @obj: domain object * @obj: domain object
* @job: qemuDomainJob to start * @job: qemuDomainJob to start
* @asyncJob: qemuDomainAsyncJob to start * @asyncJob: qemuDomainAsyncJob to start
* @nowait: don't wait trying to acquire @job
* *
* Acquires job for a domain object which must be locked before * Acquires job for a domain object which must be locked before
* calling. If there's already a job running waits up to * calling. If there's already a job running waits up to
* QEMU_JOB_WAIT_TIME after which the functions fails reporting * QEMU_JOB_WAIT_TIME after which the functions fails reporting
* an error. * an error unless @nowait is set.
*
* If @nowait is true this function tries to acquire job and if
* it fails, then it returns immediately without waiting. No
* error is reported in this case.
* *
* Returns: 0 on success, * Returns: 0 on success,
* -2 if unable to start job because of timeout or * -2 if unable to start job because of timeout or
...@@ -6374,7 +6379,8 @@ static int ATTRIBUTE_NONNULL(1) ...@@ -6374,7 +6379,8 @@ static int ATTRIBUTE_NONNULL(1)
qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
virDomainObjPtr obj, virDomainObjPtr obj,
qemuDomainJob job, qemuDomainJob job,
qemuDomainAsyncJob asyncJob) qemuDomainAsyncJob asyncJob,
bool nowait)
{ {
qemuDomainObjPrivatePtr priv = obj->privateData; qemuDomainObjPrivatePtr priv = obj->privateData;
unsigned long long now; unsigned long long now;
...@@ -6414,12 +6420,18 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver, ...@@ -6414,12 +6420,18 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
} }
while (!nested && !qemuDomainNestedJobAllowed(priv, job)) { while (!nested && !qemuDomainNestedJobAllowed(priv, job)) {
if (nowait)
goto cleanup;
VIR_DEBUG("Waiting for async job (vm=%p name=%s)", obj, obj->def->name); VIR_DEBUG("Waiting for async job (vm=%p name=%s)", obj, obj->def->name);
if (virCondWaitUntil(&priv->job.asyncCond, &obj->parent.lock, then) < 0) if (virCondWaitUntil(&priv->job.asyncCond, &obj->parent.lock, then) < 0)
goto error; goto error;
} }
while (priv->job.active) { while (priv->job.active) {
if (nowait)
goto cleanup;
VIR_DEBUG("Waiting for job (vm=%p name=%s)", obj, obj->def->name); VIR_DEBUG("Waiting for job (vm=%p name=%s)", obj, obj->def->name);
if (virCondWaitUntil(&priv->job.cond, &obj->parent.lock, then) < 0) if (virCondWaitUntil(&priv->job.cond, &obj->parent.lock, then) < 0)
goto error; goto error;
...@@ -6536,7 +6548,7 @@ int qemuDomainObjBeginJob(virQEMUDriverPtr driver, ...@@ -6536,7 +6548,7 @@ int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
qemuDomainJob job) qemuDomainJob job)
{ {
if (qemuDomainObjBeginJobInternal(driver, obj, job, if (qemuDomainObjBeginJobInternal(driver, obj, job,
QEMU_ASYNC_JOB_NONE) < 0) QEMU_ASYNC_JOB_NONE, false) < 0)
return -1; return -1;
else else
return 0; return 0;
...@@ -6551,7 +6563,7 @@ int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver, ...@@ -6551,7 +6563,7 @@ int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
qemuDomainObjPrivatePtr priv; qemuDomainObjPrivatePtr priv;
if (qemuDomainObjBeginJobInternal(driver, obj, QEMU_JOB_ASYNC, if (qemuDomainObjBeginJobInternal(driver, obj, QEMU_JOB_ASYNC,
asyncJob) < 0) asyncJob, false) < 0)
return -1; return -1;
priv = obj->privateData; priv = obj->privateData;
...@@ -6580,9 +6592,31 @@ qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver, ...@@ -6580,9 +6592,31 @@ qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
return qemuDomainObjBeginJobInternal(driver, obj, return qemuDomainObjBeginJobInternal(driver, obj,
QEMU_JOB_ASYNC_NESTED, QEMU_JOB_ASYNC_NESTED,
QEMU_ASYNC_JOB_NONE); QEMU_ASYNC_JOB_NONE,
false);
} }
/**
* qemuDomainObjBeginJobNowait:
*
* @driver: qemu driver
* @obj: domain object
* @job: qemuDomainJob to start
*
* Acquires job for a domain object which must be locked before
* calling. If there's already a job running it returns
* immediately without any error reported.
*
* Returns: see qemuDomainObjBeginJobInternal
*/
int
qemuDomainObjBeginJobNowait(virQEMUDriverPtr driver,
virDomainObjPtr obj,
qemuDomainJob job)
{
return qemuDomainObjBeginJobInternal(driver, obj, job,
QEMU_ASYNC_JOB_NONE, true);
}
/* /*
* obj must be locked and have a reference before calling * obj must be locked and have a reference before calling
......
...@@ -510,6 +510,10 @@ int qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver, ...@@ -510,6 +510,10 @@ int qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
virDomainObjPtr obj, virDomainObjPtr obj,
qemuDomainAsyncJob asyncJob) qemuDomainAsyncJob asyncJob)
ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_RETURN_CHECK;
int qemuDomainObjBeginJobNowait(virQEMUDriverPtr driver,
virDomainObjPtr obj,
qemuDomainJob job)
ATTRIBUTE_RETURN_CHECK;
void qemuDomainObjEndJob(virQEMUDriverPtr driver, void qemuDomainObjEndJob(virQEMUDriverPtr driver,
virDomainObjPtr obj); virDomainObjPtr obj);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册