[PATCH v2 03/24] network_conf: Introduce virNetworkObjListNumOfNetworks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



An accessor following pattern laid out by virDomainObjList* APIs.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/conf/network_conf.c  | 26 ++++++++++++++++++++++++++
 src/conf/network_conf.h  |  5 +++++
 src/libvirt_private.syms |  1 +
 3 files changed, 32 insertions(+)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index fdf5907..dea180a 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -4355,3 +4355,29 @@ virNetworkObjListGetNames(virNetworkObjListPtr nets,
         VIR_FREE(names[i]);
     return -1;
 }
+
+int
+virNetworkObjListNumOfNetworks(virNetworkObjListPtr nets,
+                               bool active,
+                               virNetworkObjListFilter filter,
+                               virConnectPtr conn)
+{
+    int count = 0;
+    size_t i;
+
+    for (i = 0; i < nets->count; i++) {
+        virNetworkObjPtr obj = nets->objs[i];
+        virNetworkObjLock(obj);
+        if (filter && !filter(conn, obj->def)) {
+            virNetworkObjUnlock(obj);
+            continue;
+        }
+
+        if ((active && virNetworkObjIsActive(obj)) ||
+            (!active && !virNetworkObjIsActive(obj)))
+            count++;
+        virNetworkObjUnlock(obj);
+    }
+
+    return count;
+}
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 598ddc2..bd9e3b4 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -459,6 +459,11 @@ int virNetworkObjListGetNames(virNetworkObjListPtr nets,
                               virNetworkObjListFilter filter,
                               virConnectPtr conn);
 
+int virNetworkObjListNumOfNetworks(virNetworkObjListPtr nets,
+                                   bool active,
+                                   virNetworkObjListFilter filter,
+                                   virConnectPtr conn);
+
 /* for testing */
 int
 virNetworkDefUpdateSection(virNetworkDefPtr def,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f572592..57c1a8c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -572,6 +572,7 @@ virNetworkObjListExport;
 virNetworkObjListForEach;
 virNetworkObjListFree;
 virNetworkObjListGetNames;
+virNetworkObjListNumOfNetworks;
 virNetworkObjLock;
 virNetworkObjReplacePersistentDef;
 virNetworkObjSetDefTransient;
-- 
2.0.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]