[PATCH v2 2/3] nwfilter: Introduce virNWFilterObjGetNames

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

 



Mostly code motion to move nwfilterConnectListNWFilters into nwfilterobj.c
and rename to virNWFilterObjGetNames.

Also includes a couple of variable name adjustments to keep code consistent
with other drivers.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/virnwfilterobj.c      | 33 +++++++++++++++++++++++++++++++++
 src/conf/virnwfilterobj.h      |  7 +++++++
 src/libvirt_private.syms       |  1 +
 src/nwfilter/nwfilter_driver.c | 29 ++++++-----------------------
 4 files changed, 47 insertions(+), 23 deletions(-)

diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index 5f5da5a..ce19e60 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -325,6 +325,39 @@ virNWFilterObjNumOfNWFilters(virNWFilterObjListPtr nwfilters,
 }
 
 
+int
+virNWFilterObjGetNames(virNWFilterObjListPtr nwfilters,
+                       virConnectPtr conn,
+                       virNWFilterObjListFilter aclfilter,
+                       char **const names,
+                       int maxnames)
+{
+    int nnames = 0;
+    size_t i;
+
+    for (i = 0; i < nwfilters->count && nnames < maxnames; i++) {
+        virNWFilterObjPtr obj = nwfilters->objs[i];
+        virNWFilterObjLock(obj);
+        if (!aclfilter || aclfilter(conn, obj->def)) {
+            if (VIR_STRDUP(names[nnames], obj->def->name) < 0) {
+                virNWFilterObjUnlock(obj);
+                goto failure;
+            }
+            nnames++;
+        }
+        virNWFilterObjUnlock(obj);
+    }
+
+    return nnames;
+
+ failure:
+    while (--nnames >= 0)
+        VIR_FREE(names[nnames]);
+
+    return -1;
+}
+
+
 static virNWFilterObjPtr
 virNWFilterObjLoadConfig(virNWFilterObjListPtr nwfilters,
                          const char *configDir,
diff --git a/src/conf/virnwfilterobj.h b/src/conf/virnwfilterobj.h
index a8ecc35..cd1600c 100644
--- a/src/conf/virnwfilterobj.h
+++ b/src/conf/virnwfilterobj.h
@@ -91,6 +91,13 @@ virNWFilterObjNumOfNWFilters(virNWFilterObjListPtr nwfilters,
                              virNWFilterObjListFilter aclfilter);
 
 int
+virNWFilterObjGetNames(virNWFilterObjListPtr nwfilters,
+                       virConnectPtr conn,
+                       virNWFilterObjListFilter aclfilter,
+                       char **const names,
+                       int maxnames);
+
+int
 virNWFilterObjLoadAllConfigs(virNWFilterObjListPtr nwfilters,
                              const char *configDir);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index dfc7d10..033cdc6 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -962,6 +962,7 @@ virNodeDeviceObjUnlock;
 virNWFilterObjAssignDef;
 virNWFilterObjFindByName;
 virNWFilterObjFindByUUID;
+virNWFilterObjGetNames;
 virNWFilterObjListFree;
 virNWFilterObjLoadAllConfigs;
 virNWFilterObjLock;
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 70bdea2..0d164a2 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -425,36 +425,19 @@ nwfilterConnectNumOfNWFilters(virConnectPtr conn)
 static int
 nwfilterConnectListNWFilters(virConnectPtr conn,
                              char **const names,
-                             int nnames)
+                             int maxnames)
 {
-    int got = 0;
-    size_t i;
+    int nnames;
 
     if (virConnectListNWFiltersEnsureACL(conn) < 0)
         return -1;
 
     nwfilterDriverLock();
-    for (i = 0; i < driver->nwfilters.count && got < nnames; i++) {
-        virNWFilterObjPtr obj = driver->nwfilters.objs[i];
-        virNWFilterObjLock(obj);
-        if (virConnectListNWFiltersCheckACL(conn, obj->def)) {
-            if (VIR_STRDUP(names[got], obj->def->name) < 0) {
-                virNWFilterObjUnlock(obj);
-                goto cleanup;
-            }
-            got++;
-        }
-        virNWFilterObjUnlock(obj);
-    }
-    nwfilterDriverUnlock();
-    return got;
-
- cleanup:
+    nnames = virNWFilterObjGetNames(&driver->nwfilters, conn,
+                                    virConnectListNWFiltersCheckACL,
+                                    names, maxnames);
     nwfilterDriverUnlock();
-    for (i = 0; i < got; i++)
-        VIR_FREE(names[i]);
-    memset(names, 0, nnames * sizeof(*names));
-    return -1;
+    return nnames;
 }
 
 
-- 
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