提交 6477dcc8 编写于 作者: J John Ferlan

uml: Use virDomainObjListFindBy{UUID|ID}Ref

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: NJohn Ferlan <jferlan@redhat.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 7e134bd3
...@@ -171,7 +171,7 @@ umlDomObjFromDomainLocked(struct uml_driver *driver, ...@@ -171,7 +171,7 @@ umlDomObjFromDomainLocked(struct uml_driver *driver,
virDomainObjPtr vm; virDomainObjPtr vm;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) { if (!(vm = virDomainObjListFindByUUIDRef(driver->domains, uuid))) {
virUUIDFormat(uuid, uuidstr); virUUIDFormat(uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN, virReportError(VIR_ERR_NO_DOMAIN,
...@@ -773,8 +773,7 @@ static int umlProcessAutoDestroyDom(void *payload, ...@@ -773,8 +773,7 @@ static int umlProcessAutoDestroyDom(void *payload,
return 0; return 0;
} }
if (!(dom = virDomainObjListFindByUUID(data->driver->domains, if (!(dom = virDomainObjListFindByUUIDRef(data->driver->domains, uuid))) {
uuid))) {
VIR_DEBUG("No domain object to kill"); VIR_DEBUG("No domain object to kill");
return 0; return 0;
} }
...@@ -788,11 +787,10 @@ static int umlProcessAutoDestroyDom(void *payload, ...@@ -788,11 +787,10 @@ static int umlProcessAutoDestroyDom(void *payload,
if (!dom->persistent) { if (!dom->persistent) {
virDomainObjListRemove(data->driver->domains, dom); virDomainObjListRemove(data->driver->domains, dom);
dom = NULL; virObjectLock(dom);
} }
if (dom) virDomainObjEndAPI(&dom);
virObjectUnlock(dom);
if (event) if (event)
umlDomainEventQueue(data->driver, event); umlDomainEventQueue(data->driver, event);
virHashRemoveEntry(data->driver->autodestroy, uuidstr); virHashRemoveEntry(data->driver->autodestroy, uuidstr);
...@@ -1381,7 +1379,7 @@ static virDomainPtr umlDomainLookupByID(virConnectPtr conn, ...@@ -1381,7 +1379,7 @@ static virDomainPtr umlDomainLookupByID(virConnectPtr conn,
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
umlDriverLock(driver); umlDriverLock(driver);
vm = virDomainObjListFindByID(driver->domains, id); vm = virDomainObjListFindByIDRef(driver->domains, id);
umlDriverUnlock(driver); umlDriverUnlock(driver);
if (!vm) { if (!vm) {
...@@ -1396,8 +1394,7 @@ static virDomainPtr umlDomainLookupByID(virConnectPtr conn, ...@@ -1396,8 +1394,7 @@ static virDomainPtr umlDomainLookupByID(virConnectPtr conn,
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
return dom; return dom;
} }
...@@ -1417,8 +1414,7 @@ static virDomainPtr umlDomainLookupByUUID(virConnectPtr conn, ...@@ -1417,8 +1414,7 @@ static virDomainPtr umlDomainLookupByUUID(virConnectPtr conn,
dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id); dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
return dom; return dom;
} }
...@@ -1465,8 +1461,7 @@ static int umlDomainIsActive(virDomainPtr dom) ...@@ -1465,8 +1461,7 @@ static int umlDomainIsActive(virDomainPtr dom)
ret = virDomainObjIsActive(obj); ret = virDomainObjIsActive(obj);
cleanup: cleanup:
if (obj) virDomainObjEndAPI(&obj);
virObjectUnlock(obj);
return ret; return ret;
} }
...@@ -1486,8 +1481,7 @@ static int umlDomainIsPersistent(virDomainPtr dom) ...@@ -1486,8 +1481,7 @@ static int umlDomainIsPersistent(virDomainPtr dom)
ret = obj->persistent; ret = obj->persistent;
cleanup: cleanup:
if (obj) virDomainObjEndAPI(&obj);
virObjectUnlock(obj);
return ret; return ret;
} }
...@@ -1506,8 +1500,7 @@ static int umlDomainIsUpdated(virDomainPtr dom) ...@@ -1506,8 +1500,7 @@ static int umlDomainIsUpdated(virDomainPtr dom)
ret = obj->updated; ret = obj->updated;
cleanup: cleanup:
if (obj) virDomainObjEndAPI(&obj);
virObjectUnlock(obj);
return ret; return ret;
} }
...@@ -1668,8 +1661,7 @@ static int umlDomainShutdownFlags(virDomainPtr dom, ...@@ -1668,8 +1661,7 @@ static int umlDomainShutdownFlags(virDomainPtr dom,
cleanup: cleanup:
VIR_FREE(info); VIR_FREE(info);
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
return ret; return ret;
} }
...@@ -1703,15 +1695,13 @@ umlDomainDestroyFlags(virDomainPtr dom, ...@@ -1703,15 +1695,13 @@ umlDomainDestroyFlags(virDomainPtr dom,
VIR_DOMAIN_EVENT_STOPPED, VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_DESTROYED); VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
if (!vm->persistent) { if (!vm->persistent) {
virDomainObjListRemove(driver->domains, virDomainObjListRemove(driver->domains, vm);
vm); virObjectLock(vm);
vm = NULL;
} }
ret = 0; ret = 0;
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
if (event) if (event)
umlDomainEventQueue(driver, event); umlDomainEventQueue(driver, event);
umlDriverUnlock(driver); umlDriverUnlock(driver);
...@@ -1740,8 +1730,7 @@ static char *umlDomainGetOSType(virDomainPtr dom) { ...@@ -1740,8 +1730,7 @@ static char *umlDomainGetOSType(virDomainPtr dom) {
goto cleanup; goto cleanup;
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
return type; return type;
} }
...@@ -1762,8 +1751,7 @@ umlDomainGetMaxMemory(virDomainPtr dom) ...@@ -1762,8 +1751,7 @@ umlDomainGetMaxMemory(virDomainPtr dom)
ret = virDomainDefGetMemoryTotal(vm->def); ret = virDomainDefGetMemoryTotal(vm->def);
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
return ret; return ret;
} }
...@@ -1789,8 +1777,7 @@ static int umlDomainSetMaxMemory(virDomainPtr dom, unsigned long newmax) ...@@ -1789,8 +1777,7 @@ static int umlDomainSetMaxMemory(virDomainPtr dom, unsigned long newmax)
ret = 0; ret = 0;
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
return ret; return ret;
} }
...@@ -1822,8 +1809,7 @@ static int umlDomainSetMemory(virDomainPtr dom, unsigned long newmem) ...@@ -1822,8 +1809,7 @@ static int umlDomainSetMemory(virDomainPtr dom, unsigned long newmem)
ret = 0; ret = 0;
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
return ret; return ret;
} }
...@@ -1858,8 +1844,7 @@ static int umlDomainGetInfo(virDomainPtr dom, ...@@ -1858,8 +1844,7 @@ static int umlDomainGetInfo(virDomainPtr dom,
ret = 0; ret = 0;
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
return ret; return ret;
} }
...@@ -1886,8 +1871,7 @@ umlDomainGetState(virDomainPtr dom, ...@@ -1886,8 +1871,7 @@ umlDomainGetState(virDomainPtr dom,
ret = 0; ret = 0;
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
return ret; return ret;
} }
...@@ -1913,8 +1897,7 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom, ...@@ -1913,8 +1897,7 @@ static char *umlDomainGetXMLDesc(virDomainPtr dom,
virDomainDefFormatConvertXMLFlags(flags)); virDomainDefFormatConvertXMLFlags(flags));
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
return ret; return ret;
} }
...@@ -1978,8 +1961,7 @@ static int umlDomainCreateWithFlags(virDomainPtr dom, unsigned int flags) ...@@ -1978,8 +1961,7 @@ static int umlDomainCreateWithFlags(virDomainPtr dom, unsigned int flags)
VIR_DOMAIN_EVENT_STARTED_BOOTED); VIR_DOMAIN_EVENT_STARTED_BOOTED);
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
if (event) if (event)
umlDomainEventQueue(driver, event); umlDomainEventQueue(driver, event);
umlDriverUnlock(driver); umlDriverUnlock(driver);
...@@ -2026,8 +2008,7 @@ umlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) ...@@ -2026,8 +2008,7 @@ umlDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
if (virDomainSaveConfig(driver->configDir, driver->caps, if (virDomainSaveConfig(driver->configDir, driver->caps,
vm->newDef ? vm->newDef : vm->def) < 0) { vm->newDef ? vm->newDef : vm->def) < 0) {
virDomainObjListRemove(driver->domains, virDomainObjListRemove(driver->domains, vm);
vm);
vm = NULL; vm = NULL;
goto cleanup; goto cleanup;
} }
...@@ -2077,14 +2058,13 @@ static int umlDomainUndefineFlags(virDomainPtr dom, ...@@ -2077,14 +2058,13 @@ static int umlDomainUndefineFlags(virDomainPtr dom,
vm->persistent = 0; vm->persistent = 0;
} else { } else {
virDomainObjListRemove(driver->domains, vm); virDomainObjListRemove(driver->domains, vm);
vm = NULL; virObjectLock(vm);
} }
ret = 0; ret = 0;
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
umlDriverUnlock(driver); umlDriverUnlock(driver);
return ret; return ret;
} }
...@@ -2190,8 +2170,7 @@ static int umlDomainAttachDevice(virDomainPtr dom, const char *xml) ...@@ -2190,8 +2170,7 @@ static int umlDomainAttachDevice(virDomainPtr dom, const char *xml)
cleanup: cleanup:
virDomainDeviceDefFree(dev); virDomainDeviceDefFree(dev);
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
umlDriverUnlock(driver); umlDriverUnlock(driver);
return ret; return ret;
} }
...@@ -2298,8 +2277,7 @@ static int umlDomainDetachDevice(virDomainPtr dom, const char *xml) ...@@ -2298,8 +2277,7 @@ static int umlDomainDetachDevice(virDomainPtr dom, const char *xml)
cleanup: cleanup:
virDomainDeviceDefFree(dev); virDomainDeviceDefFree(dev);
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
umlDriverUnlock(driver); umlDriverUnlock(driver);
return ret; return ret;
} }
...@@ -2340,8 +2318,7 @@ static int umlDomainGetAutostart(virDomainPtr dom, ...@@ -2340,8 +2318,7 @@ static int umlDomainGetAutostart(virDomainPtr dom,
ret = 0; ret = 0;
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
umlDriverUnlock(driver); umlDriverUnlock(driver);
return ret; return ret;
} }
...@@ -2405,8 +2382,7 @@ static int umlDomainSetAutostart(virDomainPtr dom, ...@@ -2405,8 +2382,7 @@ static int umlDomainSetAutostart(virDomainPtr dom,
cleanup: cleanup:
VIR_FREE(configFile); VIR_FREE(configFile);
VIR_FREE(autostartLink); VIR_FREE(autostartLink);
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
umlDriverUnlock(driver); umlDriverUnlock(driver);
return ret; return ret;
} }
...@@ -2469,8 +2445,7 @@ umlDomainBlockPeek(virDomainPtr dom, ...@@ -2469,8 +2445,7 @@ umlDomainBlockPeek(virDomainPtr dom,
cleanup: cleanup:
VIR_FORCE_CLOSE(fd); VIR_FORCE_CLOSE(fd);
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
return ret; return ret;
} }
...@@ -2534,8 +2509,7 @@ umlDomainOpenConsole(virDomainPtr dom, ...@@ -2534,8 +2509,7 @@ umlDomainOpenConsole(virDomainPtr dom,
ret = 0; ret = 0;
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
umlDriverUnlock(driver); umlDriverUnlock(driver);
return ret; return ret;
} }
...@@ -2834,8 +2808,7 @@ umlDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags) ...@@ -2834,8 +2808,7 @@ umlDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
ret = 0; ret = 0;
cleanup: cleanup:
if (vm) virDomainObjEndAPI(&vm);
virObjectUnlock(vm);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册