From c43c661fe4d5ca25b118cd830e2d7f7960b2a490 Mon Sep 17 00:00:00 2001 From: Martin Kletzander <mkletzan@redhat.com> Date: Wed, 15 Jul 2015 09:07:50 +0200 Subject: [PATCH] qemu: Remove double unlock for domains The virDomainObjListRemove() function unlocks a domain that it's given due to legacy code. And because of that code, which should be refactored, that last virObjectUnlock() cannot be just removed. So instead, lock it right back for qemu for now. All calls to qemuDomainRemoveInactive() are followed by code that unlocks the domain again, plus the domain should be locked during qemuDomainObjEndJob(), so the right place to lock it is right after virDomainObjListRemove(). The only place where this would cause a problem is the autodestroy callback, so we need to get another reference there and uref+unlock it afterwards. Luckily, returning NULL from that function doesn't mean an error, and only means that it doesn't need to be unlocked anymore. Signed-off-by: Martin Kletzander <mkletzan@redhat.com> --- src/qemu/qemu_domain.c | 13 +++++++++++++ src/qemu/qemu_process.c | 19 ++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8b050a0439..6ba8087c10 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2593,6 +2593,19 @@ qemuDomainRemoveInactive(virQEMUDriverPtr driver, virObjectRef(vm); virDomainObjListRemove(driver->domains, vm); + /* + * virDomainObjListRemove() leaves the domain unlocked so it can + * be unref'd for other drivers that depend on that, but we still + * need to reset a job and we have a reference from the API that + * called this function. So we need to lock it back. This is + * just a workaround for the qemu driver. + * + * XXX: Ideally, the global handling of domain objects and object + * lists would be refactored so we don't need hacks like + * this, but since that requires refactor of all drivers, + * it's a work for another day. + */ + virObjectLock(vm); virObjectUnref(cfg); if (haveJob) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 694c5cd65b..505778ec2f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -295,12 +295,12 @@ qemuProcessHandleMonitorEOF(qemuMonitorPtr mon ATTRIBUTE_UNUSED, if (priv->beingDestroyed) { VIR_DEBUG("Domain is being destroyed, EOF is expected"); - goto unlock; + goto cleanup; } if (!virDomainObjIsActive(vm)) { VIR_DEBUG("Domain %p is not active, ignoring EOF", vm); - goto unlock; + goto cleanup; } if (priv->monJSON && !priv->gotShutdown) { @@ -323,15 +323,11 @@ qemuProcessHandleMonitorEOF(qemuMonitorPtr mon ATTRIBUTE_UNUSED, qemuProcessStop(driver, vm, stopReason, stopFlags); virDomainAuditStop(vm, auditReason); - if (!vm->persistent) { + if (!vm->persistent) qemuDomainRemoveInactive(driver, vm); - goto cleanup; - } - - unlock: - virObjectUnlock(vm); cleanup: + virObjectUnlock(vm); if (event) qemuDomainEventQueue(driver, event); } @@ -5703,6 +5699,8 @@ qemuProcessAutoDestroy(virDomainObjPtr dom, VIR_DEBUG("vm=%s, conn=%p", dom->def->name, conn); + virObjectRef(dom); + if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_IN) stopFlags |= VIR_QEMU_PROCESS_STOP_MIGRATED; @@ -5727,15 +5725,14 @@ qemuProcessAutoDestroy(virDomainObjPtr dom, qemuDomainObjEndJob(driver, dom); - if (!dom->persistent) { + if (!dom->persistent) qemuDomainRemoveInactive(driver, dom); - dom = NULL; - } if (event) qemuDomainEventQueue(driver, event); cleanup: + virDomainObjEndAPI(&dom); return dom; } -- GitLab