mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 14:57:42 +00:00
conf: Move and use virDomainObjListRemoveLocked
Rather than open code within virDomainObjListRemove, just call the *Locked function. Additionally, add comments to virDomainObjListRemove to describe the usage model. Signed-off-by: John Ferlan <jferlan@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
7ae289203a
commit
2d2ed7b6f6
@ -355,26 +355,50 @@ virDomainObjPtr virDomainObjListAdd(virDomainObjListPtr doms,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/* The caller must hold lock on 'doms' in addition to 'virDomainObjListRemove'
|
||||||
* The caller must hold a lock on the driver owning 'doms',
|
* requirements
|
||||||
* and must also have locked 'dom', to ensure no one else
|
*
|
||||||
* is either waiting for 'dom' or still using it
|
* Can be used to remove current element while iterating with
|
||||||
|
* virDomainObjListForEach
|
||||||
*/
|
*/
|
||||||
void virDomainObjListRemove(virDomainObjListPtr doms,
|
void
|
||||||
virDomainObjPtr dom)
|
virDomainObjListRemoveLocked(virDomainObjListPtr doms,
|
||||||
|
virDomainObjPtr dom)
|
||||||
{
|
{
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
|
|
||||||
dom->removing = true;
|
|
||||||
virUUIDFormat(dom->def->uuid, uuidstr);
|
virUUIDFormat(dom->def->uuid, uuidstr);
|
||||||
virObjectRef(dom);
|
|
||||||
virObjectUnlock(dom);
|
|
||||||
|
|
||||||
virObjectRWLockWrite(doms);
|
|
||||||
virObjectLock(dom);
|
|
||||||
virHashRemoveEntry(doms->objs, uuidstr);
|
virHashRemoveEntry(doms->objs, uuidstr);
|
||||||
virHashRemoveEntry(doms->objsName, dom->def->name);
|
virHashRemoveEntry(doms->objsName, dom->def->name);
|
||||||
virObjectUnlock(dom);
|
virObjectUnlock(dom);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @doms: Pointer to the domain object list
|
||||||
|
* @dom: Domain pointer from either after Add or FindBy* API where the
|
||||||
|
* @dom was successfully added to both the doms->objs and ->objsName
|
||||||
|
* hash tables that now would need to be removed.
|
||||||
|
*
|
||||||
|
* The caller must hold a lock on the driver owning 'doms',
|
||||||
|
* and must also have locked and ref counted 'dom', to ensure
|
||||||
|
* no one else is either waiting for 'dom' or still using it.
|
||||||
|
*
|
||||||
|
* When this function returns, @dom will be removed from the hash
|
||||||
|
* tables, unlocked, and returned with the refcnt that was present
|
||||||
|
* upon entry.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
virDomainObjListRemove(virDomainObjListPtr doms,
|
||||||
|
virDomainObjPtr dom)
|
||||||
|
{
|
||||||
|
dom->removing = true;
|
||||||
|
virObjectRef(dom);
|
||||||
|
virObjectUnlock(dom);
|
||||||
|
virObjectRWLockWrite(doms);
|
||||||
|
virObjectLock(dom);
|
||||||
|
virDomainObjListRemoveLocked(doms, dom);
|
||||||
virObjectUnref(dom);
|
virObjectUnref(dom);
|
||||||
virObjectRWUnlock(doms);
|
virObjectRWUnlock(doms);
|
||||||
}
|
}
|
||||||
@ -446,24 +470,6 @@ virDomainObjListRename(virDomainObjListPtr doms,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The caller must hold lock on 'doms' in addition to 'virDomainObjListRemove'
|
|
||||||
* requirements
|
|
||||||
*
|
|
||||||
* Can be used to remove current element while iterating with
|
|
||||||
* virDomainObjListForEach
|
|
||||||
*/
|
|
||||||
void virDomainObjListRemoveLocked(virDomainObjListPtr doms,
|
|
||||||
virDomainObjPtr dom)
|
|
||||||
{
|
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
|
||||||
|
|
||||||
virUUIDFormat(dom->def->uuid, uuidstr);
|
|
||||||
|
|
||||||
virHashRemoveEntry(doms->objs, uuidstr);
|
|
||||||
virHashRemoveEntry(doms->objsName, dom->def->name);
|
|
||||||
virObjectUnlock(dom);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static virDomainObjPtr
|
static virDomainObjPtr
|
||||||
virDomainObjListLoadConfig(virDomainObjListPtr doms,
|
virDomainObjListLoadConfig(virDomainObjListPtr doms,
|
||||||
|
Loading…
Reference in New Issue
Block a user