vz: Use virDomainObjListFindBy{UUID|ID}Ref

For vzDomainLookupByID and vzDomainLookupByUUID 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.

Also adjust the prlsdkHandle{VmState|VmRemoved|Perf}Event APIs
in the same manner.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
This commit is contained in:
John Ferlan 2018-03-09 10:30:47 -05:00
parent d758374de2
commit 3c66d5108f
2 changed files with 13 additions and 11 deletions

View File

@ -555,7 +555,7 @@ vzDomainLookupByID(virConnectPtr conn, int id)
virDomainPtr ret = NULL; virDomainPtr ret = NULL;
virDomainObjPtr dom; virDomainObjPtr dom;
dom = virDomainObjListFindByID(privconn->driver->domains, id); dom = virDomainObjListFindByIDRef(privconn->driver->domains, id);
if (dom == NULL) { if (dom == NULL) {
virReportError(VIR_ERR_NO_DOMAIN, NULL); virReportError(VIR_ERR_NO_DOMAIN, NULL);
@ -568,7 +568,7 @@ vzDomainLookupByID(virConnectPtr conn, int id)
ret = virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id); ret = virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id);
cleanup: cleanup:
virObjectUnlock(dom); virDomainObjEndAPI(&dom);
return ret; return ret;
} }
@ -579,7 +579,7 @@ vzDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
virDomainPtr ret = NULL; virDomainPtr ret = NULL;
virDomainObjPtr dom; virDomainObjPtr dom;
dom = virDomainObjListFindByUUID(privconn->driver->domains, uuid); dom = virDomainObjListFindByUUIDRef(privconn->driver->domains, uuid);
if (dom == NULL) { if (dom == NULL) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
@ -595,7 +595,7 @@ vzDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
ret = virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id); ret = virGetDomain(conn, dom->def->name, dom->def->uuid, dom->def->id);
cleanup: cleanup:
virObjectUnlock(dom); virDomainObjEndAPI(&dom);
return ret; return ret;
} }

View File

@ -2144,7 +2144,7 @@ prlsdkHandleVmStateEvent(vzDriverPtr driver,
virDomainEventType lvEventType = 0; virDomainEventType lvEventType = 0;
int lvEventTypeDetails = 0; int lvEventTypeDetails = 0;
dom = virDomainObjListFindByUUID(driver->domains, uuid); dom = virDomainObjListFindByUUIDRef(driver->domains, uuid);
if (dom == NULL) if (dom == NULL)
return; return;
@ -2166,7 +2166,7 @@ prlsdkHandleVmStateEvent(vzDriverPtr driver,
cleanup: cleanup:
PrlHandle_Free(eventParam); PrlHandle_Free(eventParam);
virObjectUnlock(dom); virDomainObjEndAPI(&dom);
return; return;
} }
@ -2225,7 +2225,7 @@ prlsdkHandleVmRemovedEvent(vzDriverPtr driver,
{ {
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
dom = virDomainObjListFindByUUID(driver->domains, uuid); dom = virDomainObjListFindByUUIDRef(driver->domains, uuid);
/* domain was removed from the list from the libvirt /* domain was removed from the list from the libvirt
* API function in current connection */ * API function in current connection */
if (dom == NULL) if (dom == NULL)
@ -2235,6 +2235,8 @@ prlsdkHandleVmRemovedEvent(vzDriverPtr driver,
VIR_DOMAIN_EVENT_UNDEFINED_REMOVED); VIR_DOMAIN_EVENT_UNDEFINED_REMOVED);
virDomainObjListRemove(driver->domains, dom); virDomainObjListRemove(driver->domains, dom);
virObjectLock(dom);
virDomainObjEndAPI(&dom);
return; return;
} }
@ -2246,7 +2248,7 @@ prlsdkHandlePerfEvent(vzDriverPtr driver,
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
vzDomObjPtr privdom = NULL; vzDomObjPtr privdom = NULL;
if (!(dom = virDomainObjListFindByUUID(driver->domains, uuid))) { if (!(dom = virDomainObjListFindByUUIDRef(driver->domains, uuid))) {
PrlHandle_Free(event); PrlHandle_Free(event);
return; return;
} }
@ -2255,7 +2257,7 @@ prlsdkHandlePerfEvent(vzDriverPtr driver,
PrlHandle_Free(privdom->stats); PrlHandle_Free(privdom->stats);
privdom->stats = event; privdom->stats = event;
virObjectUnlock(dom); virDomainObjEndAPI(&dom);
} }
static void static void
@ -2269,7 +2271,7 @@ prlsdkHandleMigrationProgress(vzDriverPtr driver,
PRL_HANDLE param = PRL_INVALID_HANDLE; PRL_HANDLE param = PRL_INVALID_HANDLE;
PRL_RESULT pret; PRL_RESULT pret;
if (!(dom = virDomainObjListFindByUUID(driver->domains, uuid))) if (!(dom = virDomainObjListFindByUUIDRef(driver->domains, uuid)))
return; return;
pret = PrlEvent_GetParam(event, 0, &param); pret = PrlEvent_GetParam(event, 0, &param);
@ -2283,7 +2285,7 @@ prlsdkHandleMigrationProgress(vzDriverPtr driver,
cleanup: cleanup:
PrlHandle_Free(param); PrlHandle_Free(param);
virObjectUnlock(dom); virDomainObjEndAPI(&dom);
} }
static PRL_RESULT static PRL_RESULT