The API will iterate over the list of network object and remove
desired ones from it.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/network_conf.c | 31 +++++++++++++++++++++++++++++++
src/conf/network_conf.h | 3 +++
src/libvirt_private.syms | 1 +
3 files changed, 35 insertions(+)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index dea180a..ea9a9d4 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -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++;
+ }
+ }
+}
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index bd9e3b4..3fbd609 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -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,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 57c1a8c..4ce5e3a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -573,6 +573,7 @@ virNetworkObjListForEach;
virNetworkObjListFree;
virNetworkObjListGetNames;
virNetworkObjListNumOfNetworks;
+virNetworkObjListPrune;
virNetworkObjLock;
virNetworkObjReplacePersistentDef;
virNetworkObjSetDefTransient;
--
2.0.5