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.
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 | 81 ++++++++++++++++++----------------------------------
1 file changed, 28 insertions(+), 53 deletions(-)
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index d10a9ba62..41c607e66 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,
@@ -767,8 +767,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;
}
@@ -780,11 +779,10 @@ static int umlProcessAutoDestroyDom(void *payload,
VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
- if (dom && !dom->persistent)
+ if (!dom->persistent)
virDomainObjListRemove(data->driver->domains, dom);
- if (dom)
- virObjectUnlock(dom);
+ virDomainObjEndAPI(&dom);
if (event)
umlDomainEventQueue(data->driver, event);
virHashRemoveEntry(data->driver->autodestroy, uuidstr);
@@ -1381,7 +1379,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) {
@@ -1396,8 +1394,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;
}
@@ -1417,8 +1414,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;
}
@@ -1465,8 +1461,7 @@ static int umlDomainIsActive(virDomainPtr dom)
ret = virDomainObjIsActive(obj);
cleanup:
- if (obj)
- virObjectUnlock(obj);
+ virDomainObjEndAPI(&obj);
return ret;
}
@@ -1486,8 +1481,7 @@ static int umlDomainIsPersistent(virDomainPtr dom)
ret = obj->persistent;
cleanup:
- if (obj)
- virObjectUnlock(obj);
+ virDomainObjEndAPI(&obj);
return ret;
}
@@ -1506,8 +1500,7 @@ static int umlDomainIsUpdated(virDomainPtr dom)
ret = obj->updated;
cleanup:
- if (obj)
- virObjectUnlock(obj);
+ virDomainObjEndAPI(&obj);
return ret;
}
@@ -1668,8 +1661,7 @@ static int umlDomainShutdownFlags(virDomainPtr dom,
cleanup:
VIR_FREE(info);
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1710,8 +1702,7 @@ umlDomainDestroyFlags(virDomainPtr dom,
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
if (event)
umlDomainEventQueue(driver, event);
umlDriverUnlock(driver);
@@ -1740,8 +1731,7 @@ static char *umlDomainGetOSType(virDomainPtr dom) {
goto cleanup;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return type;
}
@@ -1762,8 +1752,7 @@ umlDomainGetMaxMemory(virDomainPtr dom)
ret = virDomainDefGetMemoryTotal(vm->def);
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1789,8 +1778,7 @@ static int umlDomainSetMaxMemory(virDomainPtr dom, unsigned long
newmax)
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1822,8 +1810,7 @@ static int umlDomainSetMemory(virDomainPtr dom, unsigned long
newmem)
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1858,8 +1845,7 @@ static int umlDomainGetInfo(virDomainPtr dom,
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1886,8 +1872,7 @@ umlDomainGetState(virDomainPtr dom,
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1913,8 +1898,7 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom,
virDomainDefFormatConvertXMLFlags(flags));
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -1978,8 +1962,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);
@@ -2083,8 +2066,7 @@ static int umlDomainUndefineFlags(virDomainPtr dom,
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
umlDriverUnlock(driver);
return ret;
}
@@ -2190,8 +2172,7 @@ static int umlDomainAttachDevice(virDomainPtr dom, const char *xml)
cleanup:
virDomainDeviceDefFree(dev);
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
umlDriverUnlock(driver);
return ret;
}
@@ -2298,8 +2279,7 @@ static int umlDomainDetachDevice(virDomainPtr dom, const char *xml)
cleanup:
virDomainDeviceDefFree(dev);
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
umlDriverUnlock(driver);
return ret;
}
@@ -2340,8 +2320,7 @@ static int umlDomainGetAutostart(virDomainPtr dom,
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
umlDriverUnlock(driver);
return ret;
}
@@ -2405,8 +2384,7 @@ static int umlDomainSetAutostart(virDomainPtr dom,
cleanup:
VIR_FREE(configFile);
VIR_FREE(autostartLink);
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
umlDriverUnlock(driver);
return ret;
}
@@ -2469,8 +2447,7 @@ umlDomainBlockPeek(virDomainPtr dom,
cleanup:
VIR_FORCE_CLOSE(fd);
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
@@ -2537,8 +2514,7 @@ umlDomainOpenConsole(virDomainPtr dom,
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
umlDriverUnlock(driver);
return ret;
}
@@ -2837,8 +2813,7 @@ umlDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
ret = 0;
cleanup:
- if (vm)
- virObjectUnlock(vm);
+ virDomainObjEndAPI(&vm);
return ret;
}
--
2.13.6