mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-18 18:45:16 +00:00
conf: Rework/rename virDomainObjListFindByIDRef
Rework the code such that virDomainObjListFindByID will always return a locked/ref counted object so that the callers can always do the same cleanup logic to call virDomainObjEndAPI. Makes accessing the objects much more consistent. NB: There were 2 callers (lxcDomainLookupByID and qemuDomainLookupByID) that were already using the ByID name, but not virDomainObjEndAPI - these were changed as well in this update/patch. Signed-off-by: John Ferlan <jferlan@redhat.com> Reviewed-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
parent
fd9ef3b31e
commit
868136624f
@ -844,7 +844,7 @@ bhyveDomainLookupByID(virConnectPtr conn,
|
|||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
|
|
||||||
vm = virDomainObjListFindByIDRef(privconn->domains, id);
|
vm = virDomainObjListFindByID(privconn->domains, id);
|
||||||
|
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
virReportError(VIR_ERR_NO_DOMAIN,
|
virReportError(VIR_ERR_NO_DOMAIN,
|
||||||
|
@ -109,44 +109,27 @@ static int virDomainObjListSearchID(const void *payload,
|
|||||||
return want;
|
return want;
|
||||||
}
|
}
|
||||||
|
|
||||||
static virDomainObjPtr
|
|
||||||
virDomainObjListFindByIDInternal(virDomainObjListPtr doms,
|
|
||||||
int id,
|
|
||||||
bool ref)
|
|
||||||
{
|
|
||||||
virDomainObjPtr obj;
|
|
||||||
virObjectRWLockRead(doms);
|
|
||||||
obj = virHashSearch(doms->objs, virDomainObjListSearchID, &id, NULL);
|
|
||||||
if (ref) {
|
|
||||||
virObjectRef(obj);
|
|
||||||
virObjectRWUnlock(doms);
|
|
||||||
}
|
|
||||||
if (obj) {
|
|
||||||
virObjectLock(obj);
|
|
||||||
if (obj->removing) {
|
|
||||||
virObjectUnlock(obj);
|
|
||||||
if (ref)
|
|
||||||
virObjectUnref(obj);
|
|
||||||
obj = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!ref)
|
|
||||||
virObjectRWUnlock(doms);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
virDomainObjPtr
|
virDomainObjPtr
|
||||||
virDomainObjListFindByID(virDomainObjListPtr doms,
|
virDomainObjListFindByID(virDomainObjListPtr doms,
|
||||||
int id)
|
int id)
|
||||||
{
|
{
|
||||||
return virDomainObjListFindByIDInternal(doms, id, false);
|
virDomainObjPtr obj;
|
||||||
}
|
|
||||||
|
|
||||||
virDomainObjPtr
|
virObjectRWLockRead(doms);
|
||||||
virDomainObjListFindByIDRef(virDomainObjListPtr doms,
|
obj = virHashSearch(doms->objs, virDomainObjListSearchID, &id, NULL);
|
||||||
int id)
|
virObjectRef(obj);
|
||||||
{
|
virObjectRWUnlock(doms);
|
||||||
return virDomainObjListFindByIDInternal(doms, id, true);
|
if (obj) {
|
||||||
|
virObjectLock(obj);
|
||||||
|
if (obj->removing) {
|
||||||
|
virObjectUnlock(obj);
|
||||||
|
virObjectUnref(obj);
|
||||||
|
obj = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,8 +34,6 @@ virDomainObjListPtr virDomainObjListNew(void);
|
|||||||
|
|
||||||
virDomainObjPtr virDomainObjListFindByID(virDomainObjListPtr doms,
|
virDomainObjPtr virDomainObjListFindByID(virDomainObjListPtr doms,
|
||||||
int id);
|
int id);
|
||||||
virDomainObjPtr virDomainObjListFindByIDRef(virDomainObjListPtr doms,
|
|
||||||
int id);
|
|
||||||
virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms,
|
virDomainObjPtr virDomainObjListFindByUUID(virDomainObjListPtr doms,
|
||||||
const unsigned char *uuid);
|
const unsigned char *uuid);
|
||||||
virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
|
virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
|
||||||
|
@ -952,7 +952,6 @@ virDomainObjListCollect;
|
|||||||
virDomainObjListConvert;
|
virDomainObjListConvert;
|
||||||
virDomainObjListExport;
|
virDomainObjListExport;
|
||||||
virDomainObjListFindByID;
|
virDomainObjListFindByID;
|
||||||
virDomainObjListFindByIDRef;
|
|
||||||
virDomainObjListFindByName;
|
virDomainObjListFindByName;
|
||||||
virDomainObjListFindByUUID;
|
virDomainObjListFindByUUID;
|
||||||
virDomainObjListForEach;
|
virDomainObjListForEach;
|
||||||
|
@ -450,7 +450,7 @@ libxlDomainShutdownThread(void *opaque)
|
|||||||
|
|
||||||
cfg = libxlDriverConfigGet(driver);
|
cfg = libxlDriverConfigGet(driver);
|
||||||
|
|
||||||
vm = virDomainObjListFindByIDRef(driver->domains, ev->domid);
|
vm = virDomainObjListFindByID(driver->domains, ev->domid);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
VIR_INFO("Received event for unknown domain ID %d", ev->domid);
|
VIR_INFO("Received event for unknown domain ID %d", ev->domid);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -1082,7 +1082,7 @@ libxlDomainLookupByID(virConnectPtr conn, int id)
|
|||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
|
|
||||||
vm = virDomainObjListFindByIDRef(driver->domains, id);
|
vm = virDomainObjListFindByID(driver->domains, id);
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -262,8 +262,7 @@ static virDomainPtr lxcDomainLookupByID(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ static virDomainPtr openvzDomainLookupByID(virConnectPtr conn,
|
|||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
|
|
||||||
openvzDriverLock(driver);
|
openvzDriverLock(driver);
|
||||||
vm = virDomainObjListFindByIDRef(driver->domains, id);
|
vm = virDomainObjListFindByID(driver->domains, id);
|
||||||
openvzDriverUnlock(driver);
|
openvzDriverUnlock(driver);
|
||||||
|
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
|
@ -1529,7 +1529,7 @@ static virDomainPtr qemuDomainLookupByID(virConnectPtr conn,
|
|||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
|
|
||||||
vm = virDomainObjListFindByID(driver->domains, id);
|
vm = virDomainObjListFindByID(driver->domains, id);
|
||||||
|
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
virReportError(VIR_ERR_NO_DOMAIN,
|
virReportError(VIR_ERR_NO_DOMAIN,
|
||||||
@ -1543,8 +1543,7 @@ static virDomainPtr qemuDomainLookupByID(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1708,7 +1708,7 @@ static virDomainPtr testDomainLookupByID(virConnectPtr conn,
|
|||||||
virDomainPtr ret = NULL;
|
virDomainPtr ret = NULL;
|
||||||
virDomainObjPtr dom;
|
virDomainObjPtr dom;
|
||||||
|
|
||||||
if (!(dom = virDomainObjListFindByIDRef(privconn->domains, id))) {
|
if (!(dom = virDomainObjListFindByID(privconn->domains, id))) {
|
||||||
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1379,7 +1379,7 @@ static virDomainPtr umlDomainLookupByID(virConnectPtr conn,
|
|||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
|
|
||||||
umlDriverLock(driver);
|
umlDriverLock(driver);
|
||||||
vm = virDomainObjListFindByIDRef(driver->domains, id);
|
vm = virDomainObjListFindByID(driver->domains, id);
|
||||||
umlDriverUnlock(driver);
|
umlDriverUnlock(driver);
|
||||||
|
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
|
@ -825,7 +825,7 @@ vmwareDomainLookupByID(virConnectPtr conn, int id)
|
|||||||
virDomainPtr dom = NULL;
|
virDomainPtr dom = NULL;
|
||||||
|
|
||||||
vmwareDriverLock(driver);
|
vmwareDriverLock(driver);
|
||||||
vm = virDomainObjListFindByIDRef(driver->domains, id);
|
vm = virDomainObjListFindByID(driver->domains, id);
|
||||||
vmwareDriverUnlock(driver);
|
vmwareDriverUnlock(driver);
|
||||||
|
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
|
@ -555,7 +555,7 @@ vzDomainLookupByID(virConnectPtr conn, int id)
|
|||||||
virDomainPtr ret = NULL;
|
virDomainPtr ret = NULL;
|
||||||
virDomainObjPtr dom;
|
virDomainObjPtr dom;
|
||||||
|
|
||||||
dom = virDomainObjListFindByIDRef(privconn->driver->domains, id);
|
dom = virDomainObjListFindByID(privconn->driver->domains, id);
|
||||||
|
|
||||||
if (dom == NULL) {
|
if (dom == NULL) {
|
||||||
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
virReportError(VIR_ERR_NO_DOMAIN, NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user