mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-26 23:55:23 +00:00
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:
parent
206f71e11d
commit
c7aa5c430c
@ -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
|
static virNWFilterObjPtr
|
||||||
virNWFilterObjLoadConfig(virNWFilterObjListPtr nwfilters,
|
virNWFilterObjLoadConfig(virNWFilterObjListPtr nwfilters,
|
||||||
const char *configDir,
|
const char *configDir,
|
||||||
|
@ -97,6 +97,12 @@ virNWFilterObjGetNames(virNWFilterObjListPtr nwfilters,
|
|||||||
char **const names,
|
char **const names,
|
||||||
int maxnames);
|
int maxnames);
|
||||||
|
|
||||||
|
int
|
||||||
|
virNWFilterObjListExport(virConnectPtr conn,
|
||||||
|
virNWFilterObjListPtr nwfilters,
|
||||||
|
virNWFilterPtr **filters,
|
||||||
|
virNWFilterObjListFilter aclfilter);
|
||||||
|
|
||||||
int
|
int
|
||||||
virNWFilterObjLoadAllConfigs(virNWFilterObjListPtr nwfilters,
|
virNWFilterObjLoadAllConfigs(virNWFilterObjListPtr nwfilters,
|
||||||
const char *configDir);
|
const char *configDir);
|
||||||
|
@ -963,6 +963,7 @@ virNWFilterObjAssignDef;
|
|||||||
virNWFilterObjFindByName;
|
virNWFilterObjFindByName;
|
||||||
virNWFilterObjFindByUUID;
|
virNWFilterObjFindByUUID;
|
||||||
virNWFilterObjGetNames;
|
virNWFilterObjGetNames;
|
||||||
|
virNWFilterObjListExport;
|
||||||
virNWFilterObjListFree;
|
virNWFilterObjListFree;
|
||||||
virNWFilterObjLoadAllConfigs;
|
virNWFilterObjLoadAllConfigs;
|
||||||
virNWFilterObjLock;
|
virNWFilterObjLock;
|
||||||
|
@ -446,12 +446,7 @@ nwfilterConnectListAllNWFilters(virConnectPtr conn,
|
|||||||
virNWFilterPtr **filters,
|
virNWFilterPtr **filters,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virNWFilterPtr *tmp_filters = NULL;
|
int ret;
|
||||||
int nfilters = 0;
|
|
||||||
virNWFilterPtr filter = NULL;
|
|
||||||
virNWFilterObjPtr obj = NULL;
|
|
||||||
size_t i;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
@ -459,40 +454,9 @@ nwfilterConnectListAllNWFilters(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
nwfilterDriverLock();
|
nwfilterDriverLock();
|
||||||
|
ret = virNWFilterObjListExport(conn, &driver->nwfilters, filters,
|
||||||
if (!filters) {
|
virConnectListAllNWFiltersCheckACL);
|
||||||
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:
|
|
||||||
nwfilterDriverUnlock();
|
nwfilterDriverUnlock();
|
||||||
if (tmp_filters) {
|
|
||||||
for (i = 0; i < nfilters; i ++)
|
|
||||||
virObjectUnref(tmp_filters[i]);
|
|
||||||
}
|
|
||||||
VIR_FREE(tmp_filters);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user