conf: Split FindBy{UUID|Name} into locked helpers

Create helpers virDomainObjListFindByUUIDLocked and
virDomainObjListFindByNameLocked to avoid the need
to lock the domain object list leaving that task
for the caller.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
John Ferlan 2018-03-09 07:09:20 -05:00
parent 5d84835e09
commit cf5184d1e1

View File

@ -133,19 +133,16 @@ virDomainObjListFindByID(virDomainObjListPtr doms,
}
virDomainObjPtr
virDomainObjListFindByUUID(virDomainObjListPtr doms,
const unsigned char *uuid)
static virDomainObjPtr
virDomainObjListFindByUUIDLocked(virDomainObjListPtr doms,
const unsigned char *uuid)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
virDomainObjPtr obj;
virObjectRWLockRead(doms);
virUUIDFormat(uuid, uuidstr);
obj = virHashLookup(doms->objs, uuidstr);
virObjectRef(obj);
virObjectRWUnlock(doms);
if (obj) {
virObjectLock(obj);
if (obj->removing) {
@ -158,15 +155,36 @@ virDomainObjListFindByUUID(virDomainObjListPtr doms,
}
virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
const char *name)
/**
* @doms: Domain object list
* @uuid: UUID to search the doms->objs table
*
* Lookup the @uuid in the doms->objs hash table and return a
* locked and ref counted domain object if found. Caller is
* expected to use the virDomainObjEndAPI when done with the object.
*/
virDomainObjPtr
virDomainObjListFindByUUID(virDomainObjListPtr doms,
const unsigned char *uuid)
{
virDomainObjPtr obj;
virObjectRWLockRead(doms);
obj = virDomainObjListFindByUUIDLocked(doms, uuid);
virObjectRWUnlock(doms);
return obj;
}
static virDomainObjPtr
virDomainObjListFindByNameLocked(virDomainObjListPtr doms,
const char *name)
{
virDomainObjPtr obj;
obj = virHashLookup(doms->objsName, name);
virObjectRef(obj);
virObjectRWUnlock(doms);
if (obj) {
virObjectLock(obj);
if (obj->removing) {
@ -179,6 +197,28 @@ virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
}
/**
* @doms: Domain object list
* @name: Name to search the doms->objsName table
*
* Lookup the @name in the doms->objsName hash table and return a
* locked and ref counted domain object if found. Caller is expected
* to use the virDomainObjEndAPI when done with the object.
*/
virDomainObjPtr
virDomainObjListFindByName(virDomainObjListPtr doms,
const char *name)
{
virDomainObjPtr obj;
virObjectRWLockRead(doms);
obj = virDomainObjListFindByNameLocked(doms, name);
virObjectRWUnlock(doms);
return obj;
}
/**
* @doms: Domain object list pointer
* @vm: Domain object to be added