Essentially code motion to move the ListExport function from nwfilter_driver
into virnwfilterobj
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/virnwfilterobj.c | 50 ++++++++++++++++++++++++++++++++++++++++++
src/conf/virnwfilterobj.h | 6 +++++
src/libvirt_private.syms | 1 +
src/nwfilter/nwfilter_driver.c | 42 +++--------------------------------
4 files changed, 60 insertions(+), 39 deletions(-)
diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index 66593b8..e550b22 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -359,6 +359,56 @@ virNWFilterObjGetNames(virNWFilterObjListPtr nwfilters,
}
+int
+virNWFilterObjListExport(virConnectPtr conn,
+ virNWFilterObjListPtr nwfilters,
+ virNWFilterPtr **filters,
+ virNWFilterObjListFilter aclfilter)
+{
+ virNWFilterPtr *tmp_filters = NULL;
+ int nfilters = 0;
+ virNWFilterPtr filter = NULL;
+ virNWFilterObjPtr obj = NULL;
+ size_t i;
+ int ret = -1;
+
+ if (!filters) {
+ ret = nwfilters->count;
+ goto cleanup;
+ }
+
+ if (VIR_ALLOC_N(tmp_filters, nwfilters->count + 1) < 0)
+ goto cleanup;
+
+ for (i = 0; i < nwfilters->count; i++) {
+ obj = nwfilters->objs[i];
+ virNWFilterObjLock(obj);
+ if (aclfilter && aclfilter(conn, obj->def)) {
+ if (!(filter = virGetNWFilter(conn, obj->def->name,
+ obj->def->uuid))) {
+ virNWFilterObjUnlock(obj);
+ goto cleanup;
+ }
+ tmp_filters[nfilters++] = filter;
+ }
+ virNWFilterObjUnlock(obj);
+ }
+
+ *filters = tmp_filters;
+ tmp_filters = NULL;
+ ret = nfilters;
+
+ cleanup:
+ if (tmp_filters) {
+ for (i = 0; i < nfilters; i ++)
+ virObjectUnref(tmp_filters[i]);
+ }
+ VIR_FREE(tmp_filters);
+
+ return ret;
+}
+
+
static virNWFilterObjPtr
virNWFilterObjLoadConfig(virNWFilterObjListPtr nwfilters,
const char *configDir,
diff --git a/src/conf/virnwfilterobj.h b/src/conf/virnwfilterobj.h
index cd1600c..49b1170 100644
--- a/src/conf/virnwfilterobj.h
+++ b/src/conf/virnwfilterobj.h
@@ -98,6 +98,12 @@ virNWFilterObjGetNames(virNWFilterObjListPtr nwfilters,
int maxnames);
int
+virNWFilterObjListExport(virConnectPtr conn,
+ virNWFilterObjListPtr nwfilters,
+ virNWFilterPtr **filters,
+ virNWFilterObjListFilter aclfilter);
+
+int
virNWFilterObjLoadAllConfigs(virNWFilterObjListPtr nwfilters,
const char *configDir);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index fa1219f..8ecf9d6 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -960,6 +960,7 @@ virNWFilterObjAssignDef;
virNWFilterObjFindByName;
virNWFilterObjFindByUUID;
virNWFilterObjGetNames;
+virNWFilterObjListExport;
virNWFilterObjListFree;
virNWFilterObjLoadAllConfigs;
virNWFilterObjLock;
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 0d164a2..f6c419c 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -446,12 +446,7 @@ nwfilterConnectListAllNWFilters(virConnectPtr conn,
virNWFilterPtr **filters,
unsigned int flags)
{
- virNWFilterPtr *tmp_filters = NULL;
- int nfilters = 0;
- virNWFilterPtr filter = NULL;
- virNWFilterObjPtr obj = NULL;
- size_t i;
- int ret = -1;
+ int ret;
virCheckFlags(0, -1);
@@ -459,40 +454,9 @@ nwfilterConnectListAllNWFilters(virConnectPtr conn,
return -1;
nwfilterDriverLock();
-
- if (!filters) {
- ret = driver->nwfilters.count;
- goto cleanup;
- }
-
- if (VIR_ALLOC_N(tmp_filters, driver->nwfilters.count + 1) < 0)
- goto cleanup;
-
- for (i = 0; i < driver->nwfilters.count; i++) {
- obj = driver->nwfilters.objs[i];
- virNWFilterObjLock(obj);
- if (virConnectListAllNWFiltersCheckACL(conn, obj->def)) {
- if (!(filter = virGetNWFilter(conn, obj->def->name,
- obj->def->uuid))) {
- virNWFilterObjUnlock(obj);
- goto cleanup;
- }
- tmp_filters[nfilters++] = filter;
- }
- virNWFilterObjUnlock(obj);
- }
-
- *filters = tmp_filters;
- tmp_filters = NULL;
- ret = nfilters;
-
- cleanup:
+ ret = virNWFilterObjListExport(conn, &driver->nwfilters, filters,
+ virConnectListAllNWFiltersCheckACL);
nwfilterDriverUnlock();
- if (tmp_filters) {
- for (i = 0; i < nfilters; i ++)
- virObjectUnref(tmp_filters[i]);
- }
- VIR_FREE(tmp_filters);
return ret;
}
--
2.9.3