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;
virDomainObjPtr dom;
dom = virDomainObjListFindByID(privconn->driver->domains, id);
dom = virDomainObjListFindByIDRef(privconn->driver->domains, id);
if (dom == 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);
cleanup:
virObjectUnlock(dom);
virDomainObjEndAPI(&dom);
return ret;
}
@ -579,7 +579,7 @@ vzDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
virDomainPtr ret = NULL;
virDomainObjPtr dom;
dom = virDomainObjListFindByUUID(privconn->driver->domains, uuid);
dom = virDomainObjListFindByUUIDRef(privconn->driver->domains, uuid);
if (dom == NULL) {
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);
cleanup:
virObjectUnlock(dom);
virDomainObjEndAPI(&dom);
return ret;
}

View File

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