nwfilter: Introduce virNWFilterObjListExport

Essentially code motion to move the ListExport function from nwfilter_driver
into virnwfilterobj

Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
John Ferlan 2017-03-20 07:08:46 -04:00
parent 206f71e11d
commit c7aa5c430c
4 changed files with 60 additions and 39 deletions

View File

@ -358,6 +358,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,

View File

@ -97,6 +97,12 @@ virNWFilterObjGetNames(virNWFilterObjListPtr nwfilters,
char **const names,
int maxnames);
int
virNWFilterObjListExport(virConnectPtr conn,
virNWFilterObjListPtr nwfilters,
virNWFilterPtr **filters,
virNWFilterObjListFilter aclfilter);
int
virNWFilterObjLoadAllConfigs(virNWFilterObjListPtr nwfilters,
const char *configDir);

View File

@ -963,6 +963,7 @@ virNWFilterObjAssignDef;
virNWFilterObjFindByName;
virNWFilterObjFindByUUID;
virNWFilterObjGetNames;
virNWFilterObjListExport;
virNWFilterObjListFree;
virNWFilterObjLoadAllConfigs;
virNWFilterObjLock;

View File

@ -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;
}