[PATCH v2 1/3] nwfilter: Introduce virNWFilterObjNumOfNWFilters

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

 



Mostly code motion from nwfilter_driver to virnwfilterobj with one caveat
to add the virNWFilterObjListFilter typedef and pass it as an 'aclfilter'
argument to allow for future possible test driver adjustments to count
the number of filters (similar to how node device has done this).

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/virnwfilterobj.c      | 20 ++++++++++++++++++++
 src/conf/virnwfilterobj.h      |  9 +++++++++
 src/libvirt_private.syms       |  1 +
 src/nwfilter/nwfilter_driver.c | 15 ++-------------
 4 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index 7e13afb..5f5da5a 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -305,6 +305,26 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
 }
 
 
+int
+virNWFilterObjNumOfNWFilters(virNWFilterObjListPtr nwfilters,
+                             virConnectPtr conn,
+                             virNWFilterObjListFilter aclfilter)
+{
+    size_t i;
+    int nfilters = 0;
+
+    for (i = 0; i < nwfilters->count; i++) {
+        virNWFilterObjPtr obj = nwfilters->objs[i];
+        virNWFilterObjLock(obj);
+        if (!aclfilter || aclfilter(conn, obj->def))
+            nfilters++;
+        virNWFilterObjUnlock(obj);
+    }
+
+    return nfilters;
+}
+
+
 static virNWFilterObjPtr
 virNWFilterObjLoadConfig(virNWFilterObjListPtr nwfilters,
                          const char *configDir,
diff --git a/src/conf/virnwfilterobj.h b/src/conf/virnwfilterobj.h
index 1d80455..a8ecc35 100644
--- a/src/conf/virnwfilterobj.h
+++ b/src/conf/virnwfilterobj.h
@@ -81,6 +81,15 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
 int
 virNWFilterObjTestUnassignDef(virNWFilterObjPtr nwfilter);
 
+typedef bool
+(*virNWFilterObjListFilter)(virConnectPtr conn,
+                            virNWFilterDefPtr def);
+
+int
+virNWFilterObjNumOfNWFilters(virNWFilterObjListPtr nwfilters,
+                             virConnectPtr conn,
+                             virNWFilterObjListFilter aclfilter);
+
 int
 virNWFilterObjLoadAllConfigs(virNWFilterObjListPtr nwfilters,
                              const char *configDir);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 62bc36a..dfc7d10 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -965,6 +965,7 @@ virNWFilterObjFindByUUID;
 virNWFilterObjListFree;
 virNWFilterObjLoadAllConfigs;
 virNWFilterObjLock;
+virNWFilterObjNumOfNWFilters;
 virNWFilterObjRemove;
 virNWFilterObjTestUnassignDef;
 virNWFilterObjUnlock;
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 4ea216a..70bdea2 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -414,22 +414,11 @@ nwfilterLookupByName(virConnectPtr conn,
 static int
 nwfilterConnectNumOfNWFilters(virConnectPtr conn)
 {
-    size_t i;
-    int n;
-
     if (virConnectNumOfNWFiltersEnsureACL(conn) < 0)
         return -1;
 
-    n = 0;
-    for (i = 0; i < driver->nwfilters.count; i++) {
-        virNWFilterObjPtr obj = driver->nwfilters.objs[i];
-        virNWFilterObjLock(obj);
-        if (virConnectNumOfNWFiltersCheckACL(conn, obj->def))
-            n++;
-        virNWFilterObjUnlock(obj);
-    }
-
-    return n;
+    return virNWFilterObjNumOfNWFilters(&driver->nwfilters, conn,
+                                        virConnectNumOfNWFiltersCheckACL);
 }
 
 
-- 
2.9.3

--
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]
  Powered by Linux