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(a)redhat.com>
---
src/conf/virnwfilterobj.c | 34 ++++++++++++++++++++++++++++++++++
src/conf/virnwfilterobj.h | 7 +++++++
src/libvirt_private.syms | 1 +
src/nwfilter/nwfilter_driver.c | 29 ++++++-----------------------
4 files changed, 48 insertions(+), 23 deletions(-)
diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index 86d77ce..66593b8 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -325,6 +325,40 @@ 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]);
+ memset(names, 0, maxnames * sizeof(*names));
+
+ 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 706b2b4..fa1219f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -959,6 +959,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