For umlDomObjFromDomainLocked and umlDomainLookupByID let's
return a locked and referenced @vm object so that callers
can then use the common and more consistent virDomainObjEndAPI
in order to handle cleanup rather than needing to know that the
returned object is locked and calling virObjectUnlock. This
means for some consumers we need to relock the @dom after a
virDomainObjListRemove, but before calling virDomainObjEndAPI.
The LookupByName already returns the ref counted and locked object,
so this will make things more consistent.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/uml/uml_driver.c | 91 ++++++++++++++++++----------------------------------
1 file changed, 32 insertions(+), 59 deletions(-)
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index b81da7cb2e..93d8a9f57c 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -171,7 +171,7 @@ umlDomObjFromDomainLocked(struct uml_driver *driver,
virDomainObjPtr vm;
char uuidstr[VIR_UUID_STRING_BUFLEN];
- if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) {
+ if (!(vm = virDomainObjListFindByUUIDRef(driver->domains, uuid))) {
virUUIDFormat(uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
@@ -773,8 +773,7 @@ static int umlProcessAutoDestroyDom(void *payload,
return 0;
}
- if (!(dom = virDomainObjListFindByUUID(data->driver->domains,
- uuid))) {
+ if (!(dom = virDomainObjListFindByUUIDRef(data->driver->domains, uuid))) {
VIR_DEBUG("No domain object to kill");
return 0;
}
@@ -788,11 +787,10 @@ static int umlProcessAutoDestroyDom(void *payload,
if (!dom->persistent) {
virDomainObjListRemove(data->driver->domains, dom);
- dom = NULL;
+ virObjectLock(dom);
}
- if (dom)
- virObjectUnlock(dom);
+ virDomainObjEndAPI(&dom);
if (event)
umlDomainEventQueue(data->driver, event);
virHashRemoveEntry(data->driver->autodestroy, uuidstr);
@@ -1389,7 +1387,7 @@ static virDomainPtr umlDomainLookupByID(virConnectPtr conn,
virDomainPtr dom = NULL;
umlDriverLock(driver);
- vm = virDomainObjListFindByID(driver->domains, id);
+ vm = virDomainObjListFindByIDRef(driver->domains, id);
umlDriverUnlock(driver);
if (!vm) {
@@ -1404,8 +1402,7 @@ static virDomainPtr umlDomainLookupByID(virConnectPtr conn,
dom = virGetDomain(conn, vm->def->name, vm->def->uuid,
vm->def->id);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return dom;
}
@@ -1425,8 +1422,7 @@ static virDomainPtr umlDomainLookupByUUID(virConnectPtr conn,
dom = virGetDomain(conn, vm->def->name, vm->def->uuid,
vm->def->id);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return dom;
}
@@ -1473,8 +1469,7 @@ static int umlDomainIsActive(virDomainPtr dom)
ret = virDomainObjIsActive(obj);
cleanup:
- if (obj)
- virObjectUnlock(obj);
+ virDomainObjEndAPI(&obj);
return ret;
}
@@ -1494,8 +1489,7 @@ static int umlDomainIsPersistent(virDomainPtr dom)
ret = obj->persistent;
cleanup:
- if (obj)
- virObjectUnlock(obj);
+ virDomainObjEndAPI(&obj);
return ret;
}
@@ -1514,8 +1508,7 @@ static int umlDomainIsUpdated(virDomainPtr dom)
ret = obj->updated;
cleanup:
- if (obj)
- virObjectUnlock(obj);
+ virDomainObjEndAPI(&obj);
return ret;
}
@@ -1676,8 +1669,7 @@ static int umlDomainShutdownFlags(virDomainPtr dom,
cleanup:
VIR_FREE(info);
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1711,15 +1703,13 @@ umlDomainDestroyFlags(virDomainPtr dom,
VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
if (!vm->persistent) {
- virDomainObjListRemove(driver->domains,
- vm);
- vm = NULL;
+ virDomainObjListRemove(driver->domains, vm);
+ virObjectLock(vm);
}
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
if (event)
umlDomainEventQueue(driver, event);
umlDriverUnlock(driver);
@@ -1748,8 +1738,7 @@ static char *umlDomainGetOSType(virDomainPtr dom) {
goto cleanup;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return type;
}
@@ -1770,8 +1759,7 @@ umlDomainGetMaxMemory(virDomainPtr dom)
ret = virDomainDefGetMemoryTotal(vm->def);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1797,8 +1785,7 @@ static int umlDomainSetMaxMemory(virDomainPtr dom, unsigned long
newmax)
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1830,8 +1817,7 @@ static int umlDomainSetMemory(virDomainPtr dom, unsigned long
newmem)
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1866,8 +1852,7 @@ static int umlDomainGetInfo(virDomainPtr dom,
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1894,8 +1879,7 @@ umlDomainGetState(virDomainPtr dom,
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1921,8 +1905,7 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom,
virDomainDefFormatConvertXMLFlags(flags));
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1986,8 +1969,7 @@ static int umlDomainCreateWithFlags(virDomainPtr dom, unsigned int
flags)
VIR_DOMAIN_EVENT_STARTED_BOOTED);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
if (event)
umlDomainEventQueue(driver, event);
umlDriverUnlock(driver);
@@ -2034,8 +2016,7 @@ umlDomainDefineXMLFlags(virConnectPtr conn, const char *xml,
unsigned int flags)
if (virDomainSaveConfig(driver->configDir, driver->caps,
vm->newDef ? vm->newDef : vm->def) < 0) {
- virDomainObjListRemove(driver->domains,
- vm);
+ virDomainObjListRemove(driver->domains, vm);
vm = NULL;
goto cleanup;
}
@@ -2085,14 +2066,13 @@ static int umlDomainUndefineFlags(virDomainPtr dom,
vm->persistent = 0;
} else {
virDomainObjListRemove(driver->domains, vm);
- vm = NULL;
+ virObjectLock(vm);
}
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
umlDriverUnlock(driver);
return ret;
}
@@ -2198,8 +2178,7 @@ static int umlDomainAttachDevice(virDomainPtr dom, const char *xml)
cleanup:
virDomainDeviceDefFree(dev);
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
umlDriverUnlock(driver);
return ret;
}
@@ -2306,8 +2285,7 @@ static int umlDomainDetachDevice(virDomainPtr dom, const char *xml)
cleanup:
virDomainDeviceDefFree(dev);
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
umlDriverUnlock(driver);
return ret;
}
@@ -2348,8 +2326,7 @@ static int umlDomainGetAutostart(virDomainPtr dom,
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
umlDriverUnlock(driver);
return ret;
}
@@ -2413,8 +2390,7 @@ static int umlDomainSetAutostart(virDomainPtr dom,
cleanup:
VIR_FREE(configFile);
VIR_FREE(autostartLink);
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
umlDriverUnlock(driver);
return ret;
}
@@ -2477,8 +2453,7 @@ umlDomainBlockPeek(virDomainPtr dom,
cleanup:
VIR_FORCE_CLOSE(fd);
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -2545,8 +2520,7 @@ umlDomainOpenConsole(virDomainPtr dom,
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
umlDriverUnlock(driver);
return ret;
}
@@ -2845,8 +2819,7 @@ umlDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
--
2.13.6