network_conf: Introduce virNetworkObjListPrune

The API will iterate over the list of network object and remove
desired ones from it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2015-03-04 17:38:39 +01:00
parent 0ae7def635
commit 292acd202f
3 changed files with 35 additions and 0 deletions

View File

@ -4381,3 +4381,34 @@ virNetworkObjListNumOfNetworks(virNetworkObjListPtr nets,
return count;
}
/**
* virNetworkObjListPrune:
* @nets: a list of network objects
* @flags: bitwise-OR of virConnectListAllNetworksFlags
*
* Iterate over list of network objects and remove the desired
* ones from it.
*/
void
virNetworkObjListPrune(virNetworkObjListPtr nets,
unsigned int flags)
{
size_t i = 0;
while (i < nets->count) {
virNetworkObjPtr obj = nets->objs[i];
virNetworkObjLock(obj);
if (virNetworkMatch(obj, flags)) {
virNetworkObjUnlock(obj);
virNetworkObjFree(obj);
VIR_DELETE_ELEMENT(nets->objs, i, nets->count);
} else {
virNetworkObjUnlock(obj);
i++;
}
}
}

View File

@ -464,6 +464,9 @@ int virNetworkObjListNumOfNetworks(virNetworkObjListPtr nets,
virNetworkObjListFilter filter,
virConnectPtr conn);
void virNetworkObjListPrune(virNetworkObjListPtr nets,
unsigned int flags);
/* for testing */
int
virNetworkDefUpdateSection(virNetworkDefPtr def,

View File

@ -573,6 +573,7 @@ virNetworkObjListForEach;
virNetworkObjListFree;
virNetworkObjListGetNames;
virNetworkObjListNumOfNetworks;
virNetworkObjListPrune;
virNetworkObjLock;
virNetworkObjReplacePersistentDef;
virNetworkObjSetDefTransient;