mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
LXC: use virDomainObjBeginJob()
This patch removes virLXCDomainObjBeginJob() and replaces it with call to the 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
31d9c22d8e
commit
28ed7ceb4e
@ -35,63 +35,6 @@
|
|||||||
VIR_LOG_INIT("lxc.lxc_domain");
|
VIR_LOG_INIT("lxc.lxc_domain");
|
||||||
|
|
||||||
|
|
||||||
/* Give up waiting for mutex after 30 seconds */
|
|
||||||
#define LXC_JOB_WAIT_TIME (1000ull * 30)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* obj must be locked before calling, virLXCDriver *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
|
|
||||||
virLXCDomainObjBeginJob(virLXCDriver *driver G_GNUC_UNUSED,
|
|
||||||
virDomainObj *obj,
|
|
||||||
virDomainJob job)
|
|
||||||
{
|
|
||||||
unsigned long long now;
|
|
||||||
unsigned long long then;
|
|
||||||
|
|
||||||
if (virTimeMillisNow(&now) < 0)
|
|
||||||
return -1;
|
|
||||||
then = now + LXC_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();
|
|
||||||
|
|
||||||
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 and have a reference before calling
|
* obj must be locked and have a reference before calling
|
||||||
*
|
*
|
||||||
|
@ -72,12 +72,6 @@ extern virXMLNamespace virLXCDriverDomainXMLNamespace;
|
|||||||
extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks;
|
extern virDomainXMLPrivateDataCallbacks virLXCDriverPrivateDataCallbacks;
|
||||||
extern virDomainDefParserConfig virLXCDriverDomainDefParserConfig;
|
extern virDomainDefParserConfig virLXCDriverDomainDefParserConfig;
|
||||||
|
|
||||||
int
|
|
||||||
virLXCDomainObjBeginJob(virLXCDriver *driver,
|
|
||||||
virDomainObj *obj,
|
|
||||||
virDomainJob job)
|
|
||||||
G_GNUC_WARN_UNUSED_RESULT;
|
|
||||||
|
|
||||||
void
|
void
|
||||||
virLXCDomainObjEndJob(virLXCDriver *driver,
|
virLXCDomainObjEndJob(virLXCDriver *driver,
|
||||||
virDomainObj *obj);
|
virDomainObj *obj);
|
||||||
|
@ -648,7 +648,7 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
|
|||||||
if (virDomainSetMemoryFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
if (virDomainSetMemoryFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
||||||
@ -762,7 +762,7 @@ lxcDomainSetMemoryParameters(virDomainPtr dom,
|
|||||||
if (virDomainSetMemoryParametersEnsureACL(dom->conn, vm->def, flags) < 0)
|
if (virDomainSetMemoryParametersEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* QEMU and LXC implementation are identical */
|
/* QEMU and LXC implementation are identical */
|
||||||
@ -983,7 +983,7 @@ static int lxcDomainCreateWithFiles(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjIsActive(vm)) {
|
if (virDomainObjIsActive(vm)) {
|
||||||
@ -1105,7 +1105,7 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
|
|||||||
NULL)))
|
NULL)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0) {
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) {
|
||||||
if (!vm->persistent)
|
if (!vm->persistent)
|
||||||
virDomainObjListRemove(driver->domains, vm);
|
virDomainObjListRemove(driver->domains, vm);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1350,7 +1350,7 @@ lxcDomainDestroyFlags(virDomainPtr dom,
|
|||||||
if (virDomainDestroyFlagsEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainDestroyFlagsEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_DESTROY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_DESTROY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
@ -1816,7 +1816,7 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
|
|||||||
if (!(caps = virLXCDriverGetCapabilities(driver, false)))
|
if (!(caps = virLXCDriverGetCapabilities(driver, false)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
||||||
@ -2035,7 +2035,7 @@ lxcDomainBlockStats(virDomainPtr dom,
|
|||||||
if (virDomainBlockStatsEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainBlockStatsEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_QUERY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
@ -2118,7 +2118,7 @@ lxcDomainBlockStatsFlags(virDomainPtr dom,
|
|||||||
if (virDomainBlockStatsFlagsEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainBlockStatsFlagsEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_QUERY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
@ -2254,7 +2254,7 @@ lxcDomainSetBlkioParameters(virDomainPtr dom,
|
|||||||
if (virDomainSetBlkioParametersEnsureACL(dom->conn, vm->def, flags) < 0)
|
if (virDomainSetBlkioParametersEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
||||||
@ -2396,7 +2396,7 @@ lxcDomainInterfaceStats(virDomainPtr dom,
|
|||||||
if (virDomainInterfaceStatsEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainInterfaceStatsEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_QUERY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
@ -2456,7 +2456,7 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
|
|||||||
if (virDomainSetAutostartEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainSetAutostartEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!vm->persistent) {
|
if (!vm->persistent) {
|
||||||
@ -2607,7 +2607,7 @@ static int lxcDomainSuspend(virDomainPtr dom)
|
|||||||
if (virDomainSuspendEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainSuspendEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
@ -2657,7 +2657,7 @@ static int lxcDomainResume(virDomainPtr dom)
|
|||||||
if (virDomainResumeEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainResumeEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
@ -2786,7 +2786,7 @@ lxcDomainSendProcessSignal(virDomainPtr dom,
|
|||||||
if (virDomainSendProcessSignalEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainSendProcessSignalEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
@ -2871,7 +2871,7 @@ lxcDomainShutdownFlags(virDomainPtr dom,
|
|||||||
if (virDomainShutdownFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
if (virDomainShutdownFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
@ -2947,7 +2947,7 @@ lxcDomainReboot(virDomainPtr dom,
|
|||||||
if (virDomainRebootEnsureACL(dom->conn, vm->def, flags) < 0)
|
if (virDomainRebootEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
@ -4278,7 +4278,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
|
|||||||
if (virDomainAttachDeviceFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
if (virDomainAttachDeviceFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
|
if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
|
||||||
@ -4383,7 +4383,7 @@ static int lxcDomainUpdateDeviceFlags(virDomainPtr dom,
|
|||||||
if (virDomainUpdateDeviceFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
if (virDomainUpdateDeviceFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
|
if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
|
||||||
@ -4446,7 +4446,7 @@ static int lxcDomainDetachDeviceFlags(virDomainPtr dom,
|
|||||||
if (virDomainDetachDeviceFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
if (virDomainDetachDeviceFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
|
if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
|
||||||
@ -4546,7 +4546,7 @@ static int lxcDomainLxcOpenNamespace(virDomainPtr dom,
|
|||||||
if (virDomainLxcOpenNamespaceEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainLxcOpenNamespaceEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_QUERY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
@ -4629,7 +4629,7 @@ lxcDomainMemoryStats(virDomainPtr dom,
|
|||||||
if (virDomainMemoryStatsEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainMemoryStatsEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_QUERY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
@ -4799,7 +4799,7 @@ lxcDomainSetMetadata(virDomainPtr dom,
|
|||||||
if (virDomainSetMetadataEnsureACL(dom->conn, vm->def, flags) < 0)
|
if (virDomainSetMetadataEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_MODIFY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = virDomainObjSetMetadata(vm, type, metadata, key, uri,
|
ret = virDomainObjSetMetadata(vm, type, metadata, key, uri,
|
||||||
@ -4905,7 +4905,7 @@ lxcDomainGetHostname(virDomainPtr dom,
|
|||||||
if (virDomainGetHostnameEnsureACL(dom->conn, vm->def) < 0)
|
if (virDomainGetHostnameEnsureACL(dom->conn, vm->def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCDomainObjBeginJob(driver, vm, VIR_JOB_QUERY) < 0)
|
if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user