mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
libxl: use virDomainObjBeginJob()
This patch removes libxlDomainObjBeginJob() and replaces it with generalized virDomainObjBeginJob(). Signed-off-by: Kristina Hanicova <khanicov@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
0d22febfc6
commit
31d9c22d8e
@ -43,64 +43,6 @@
|
||||
VIR_LOG_INIT("libxl.libxl_domain");
|
||||
|
||||
|
||||
/* Give up waiting for mutex after 30 seconds */
|
||||
#define LIBXL_JOB_WAIT_TIME (1000ull * 30)
|
||||
|
||||
/*
|
||||
* obj must be locked before calling, libxlDriverPrivate *must NOT be locked
|
||||
*
|
||||
* This must be called by anything that will change the VM state
|
||||
* in any way
|
||||
*
|
||||
* Upon successful return, the object will have its ref count increased,
|
||||
* successful calls must be followed by EndJob eventually
|
||||
*/
|
||||
int
|
||||
libxlDomainObjBeginJob(libxlDriverPrivate *driver G_GNUC_UNUSED,
|
||||
virDomainObj *obj,
|
||||
virDomainJob job)
|
||||
{
|
||||
unsigned long long now;
|
||||
unsigned long long then;
|
||||
|
||||
if (virTimeMillisNow(&now) < 0)
|
||||
return -1;
|
||||
then = now + LIBXL_JOB_WAIT_TIME;
|
||||
|
||||
while (obj->job->active) {
|
||||
VIR_DEBUG("Wait normal job condition for starting job: %s",
|
||||
virDomainJobTypeToString(job));
|
||||
if (virCondWaitUntil(&obj->job->cond, &obj->parent.lock, then) < 0)
|
||||
goto error;
|
||||
}
|
||||
|
||||
virDomainObjResetJob(obj->job);
|
||||
|
||||
VIR_DEBUG("Starting job: %s", virDomainJobTypeToString(job));
|
||||
obj->job->active = job;
|
||||
obj->job->owner = virThreadSelfID();
|
||||
obj->job->started = now;
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
VIR_WARN("Cannot start job (%s) for domain %s;"
|
||||
" current job is (%s) owned by (%llu)",
|
||||
virDomainJobTypeToString(job),
|
||||
obj->def->name,
|
||||
virDomainJobTypeToString(obj->job->active),
|
||||
obj->job->owner);
|
||||
|
||||
if (errno == ETIMEDOUT)
|
||||
virReportError(VIR_ERR_OPERATION_TIMEOUT,
|
||||
"%s", _("cannot acquire state change lock"));
|
||||
else
|
||||
virReportSystemError(errno,
|
||||
"%s", _("cannot acquire job mutex"));
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* obj must be locked before calling
|
||||
*
|
||||
@ -460,7 +402,7 @@ libxlDomainShutdownThread(void *opaque)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (xl_reason == LIBXL_SHUTDOWN_REASON_POWEROFF) {
|
||||
@ -589,7 +531,7 @@ libxlDomainDeathThread(void *opaque)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_DESTROYED);
|
||||
|
@ -49,12 +49,6 @@ extern const struct libxl_event_hooks ev_hooks;
|
||||
int
|
||||
libxlDomainObjPrivateInitCtx(virDomainObj *vm);
|
||||
|
||||
int
|
||||
libxlDomainObjBeginJob(libxlDriverPrivate *driver,
|
||||
virDomainObj *obj,
|
||||
virDomainJob job)
|
||||
G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
void
|
||||
libxlDomainObjEndJob(libxlDriverPrivate *driver,
|
||||
virDomainObj *obj);
|
||||
|
@ -326,7 +326,7 @@ libxlAutostartDomain(virDomainObj *vm,
|
||||
virObjectLock(vm);
|
||||
virResetLastError();
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (vm->autostart && !virDomainObjIsActive(vm) &&
|
||||
@ -1049,7 +1049,7 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml,
|
||||
NULL)))
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0) {
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) {
|
||||
if (!vm->persistent)
|
||||
virDomainObjListRemove(driver->domains, vm);
|
||||
goto cleanup;
|
||||
@ -1159,7 +1159,7 @@ libxlDomainSuspend(virDomainPtr dom)
|
||||
if (virDomainSuspendEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -1212,7 +1212,7 @@ libxlDomainResume(virDomainPtr dom)
|
||||
if (virDomainResumeEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -1373,7 +1373,7 @@ libxlDomainDestroyFlags(virDomainPtr dom,
|
||||
if (virDomainDestroyFlagsEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -1446,7 +1446,7 @@ libxlDomainPMSuspendForDuration(virDomainPtr dom,
|
||||
if (virDomainPMSuspendForDurationEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -1499,7 +1499,7 @@ libxlDomainPMWakeup(virDomainPtr dom, unsigned int flags)
|
||||
if (virDomainPMWakeupEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_PMSUSPENDED) {
|
||||
@ -1633,7 +1633,7 @@ libxlDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
||||
if (virDomainSetMemoryFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainLiveConfigHelperMethod(cfg->caps, driver->xmlopt, vm, &flags,
|
||||
@ -1902,7 +1902,7 @@ libxlDomainSaveFlags(virDomainPtr dom, const char *to, const char *dxml,
|
||||
if (virDomainSaveFlagsEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -1967,7 +1967,7 @@ libxlDomainRestoreFlags(virConnectPtr conn, const char *from,
|
||||
NULL)))
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0) {
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) {
|
||||
if (!vm->persistent)
|
||||
virDomainObjListRemove(driver->domains, vm);
|
||||
goto cleanup;
|
||||
@ -2014,7 +2014,7 @@ libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int flags)
|
||||
if (virDomainCoreDumpEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -2103,7 +2103,7 @@ libxlDomainManagedSave(virDomainPtr dom, unsigned int flags)
|
||||
if (virDomainManagedSaveEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -2248,7 +2248,7 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
||||
if (virDomainSetVcpusFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!virDomainObjIsActive(vm) && (flags & VIR_DOMAIN_VCPU_LIVE)) {
|
||||
@ -2446,7 +2446,7 @@ libxlDomainPinVcpuFlags(virDomainPtr dom, unsigned int vcpu,
|
||||
if (virDomainPinVcpuFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainLiveConfigHelperMethod(cfg->caps, driver->xmlopt, vm,
|
||||
@ -2777,7 +2777,7 @@ libxlDomainCreateWithFlags(virDomainPtr dom,
|
||||
if (virDomainCreateWithFlagsEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjIsActive(vm)) {
|
||||
@ -4095,7 +4095,7 @@ libxlDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
|
||||
if (virDomainAttachDeviceFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
|
||||
@ -4189,7 +4189,7 @@ libxlDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
|
||||
if (virDomainDetachDeviceFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
|
||||
@ -4477,7 +4477,7 @@ libxlDomainSetAutostart(virDomainPtr dom, int autostart)
|
||||
if (virDomainSetAutostartEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!vm->persistent) {
|
||||
@ -4683,7 +4683,7 @@ libxlDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
||||
if (virDomainSetSchedulerParametersFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -5000,7 +5000,7 @@ libxlDomainInterfaceStats(virDomainPtr dom,
|
||||
if (virDomainInterfaceStatsEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_QUERY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -5168,7 +5168,7 @@ libxlDomainMemoryStats(virDomainPtr dom,
|
||||
if (virDomainMemoryStatsEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_QUERY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -5522,7 +5522,7 @@ libxlDomainBlockStats(virDomainPtr dom,
|
||||
if (virDomainBlockStatsEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_QUERY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -5572,7 +5572,7 @@ libxlDomainBlockStatsFlags(virDomainPtr dom,
|
||||
if (virDomainBlockStatsFlagsEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_QUERY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -6368,7 +6368,7 @@ libxlDomainSetMetadata(virDomainPtr dom,
|
||||
if (virDomainSetMetadataEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = virDomainObjSetMetadata(vm, type, metadata, key, uri,
|
||||
|
@ -383,7 +383,7 @@ libxlDomainMigrationSrcBegin(virConnectPtr conn,
|
||||
* terminated in the confirm phase. Errors in the begin or perform
|
||||
* phase will also terminate the job.
|
||||
*/
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(mig = libxlMigrationCookieNew(vm)))
|
||||
@ -553,7 +553,7 @@ libxlDomainMigrationDstPrepareTunnel3(virConnectPtr dconn,
|
||||
* Unless an error is encountered in this function, the job will
|
||||
* be terminated in the finish phase.
|
||||
*/
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto error;
|
||||
|
||||
priv = vm->privateData;
|
||||
@ -662,7 +662,7 @@ libxlDomainMigrationDstPrepare(virConnectPtr dconn,
|
||||
* Unless an error is encountered in this function, the job will
|
||||
* be terminated in the finish phase.
|
||||
*/
|
||||
if (libxlDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
||||
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||
goto error;
|
||||
|
||||
priv = vm->privateData;
|
||||
|
Loading…
Reference in New Issue
Block a user