nwfilter: Introduce virNWFilterObjNumOfNWFilters

Mostly code motion from nwfilter_driver to virnwfilterobj with one caveat
to add the virNWFilterObjListFilter typedef and pass it as an 'aclfilter'
argument to allow for future possible test driver adjustments to count
the number of filters (similar to how node device has done this).

Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
John Ferlan 2017-03-19 08:20:25 -04:00
parent 84f178bdc7
commit 0c22162836
4 changed files with 32 additions and 13 deletions

View File

@ -305,6 +305,26 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
}
int
virNWFilterObjNumOfNWFilters(virNWFilterObjListPtr nwfilters,
virConnectPtr conn,
virNWFilterObjListFilter aclfilter)
{
size_t i;
int nfilters = 0;
for (i = 0; i < nwfilters->count; i++) {
virNWFilterObjPtr obj = nwfilters->objs[i];
virNWFilterObjLock(obj);
if (!aclfilter || aclfilter(conn, obj->def))
nfilters++;
virNWFilterObjUnlock(obj);
}
return nfilters;
}
static virNWFilterObjPtr
virNWFilterObjLoadConfig(virNWFilterObjListPtr nwfilters,
const char *configDir,

View File

@ -81,6 +81,15 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
int
virNWFilterObjTestUnassignDef(virNWFilterObjPtr nwfilter);
typedef bool
(*virNWFilterObjListFilter)(virConnectPtr conn,
virNWFilterDefPtr def);
int
virNWFilterObjNumOfNWFilters(virNWFilterObjListPtr nwfilters,
virConnectPtr conn,
virNWFilterObjListFilter aclfilter);
int
virNWFilterObjLoadAllConfigs(virNWFilterObjListPtr nwfilters,
const char *configDir);

View File

@ -965,6 +965,7 @@ virNWFilterObjFindByUUID;
virNWFilterObjListFree;
virNWFilterObjLoadAllConfigs;
virNWFilterObjLock;
virNWFilterObjNumOfNWFilters;
virNWFilterObjRemove;
virNWFilterObjTestUnassignDef;
virNWFilterObjUnlock;

View File

@ -414,22 +414,11 @@ nwfilterLookupByName(virConnectPtr conn,
static int
nwfilterConnectNumOfNWFilters(virConnectPtr conn)
{
size_t i;
int n;
if (virConnectNumOfNWFiltersEnsureACL(conn) < 0)
return -1;
n = 0;
for (i = 0; i < driver->nwfilters.count; i++) {
virNWFilterObjPtr obj = driver->nwfilters.objs[i];
virNWFilterObjLock(obj);
if (virConnectNumOfNWFiltersCheckACL(conn, obj->def))
n++;
virNWFilterObjUnlock(obj);
}
return n;
return virNWFilterObjNumOfNWFilters(&driver->nwfilters, conn,
virConnectNumOfNWFiltersCheckACL);
}