mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 02:51:16 +00:00
nwfilter: Introduce virNWFilterObjGetNames
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@redhat.com>
This commit is contained in:
parent
0c22162836
commit
206f71e11d
@ -325,6 +325,39 @@ 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]);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static virNWFilterObjPtr
|
static virNWFilterObjPtr
|
||||||
virNWFilterObjLoadConfig(virNWFilterObjListPtr nwfilters,
|
virNWFilterObjLoadConfig(virNWFilterObjListPtr nwfilters,
|
||||||
const char *configDir,
|
const char *configDir,
|
||||||
|
@ -90,6 +90,13 @@ virNWFilterObjNumOfNWFilters(virNWFilterObjListPtr nwfilters,
|
|||||||
virConnectPtr conn,
|
virConnectPtr conn,
|
||||||
virNWFilterObjListFilter aclfilter);
|
virNWFilterObjListFilter aclfilter);
|
||||||
|
|
||||||
|
int
|
||||||
|
virNWFilterObjGetNames(virNWFilterObjListPtr nwfilters,
|
||||||
|
virConnectPtr conn,
|
||||||
|
virNWFilterObjListFilter aclfilter,
|
||||||
|
char **const names,
|
||||||
|
int maxnames);
|
||||||
|
|
||||||
int
|
int
|
||||||
virNWFilterObjLoadAllConfigs(virNWFilterObjListPtr nwfilters,
|
virNWFilterObjLoadAllConfigs(virNWFilterObjListPtr nwfilters,
|
||||||
const char *configDir);
|
const char *configDir);
|
||||||
|
@ -962,6 +962,7 @@ virNodeDeviceObjUnlock;
|
|||||||
virNWFilterObjAssignDef;
|
virNWFilterObjAssignDef;
|
||||||
virNWFilterObjFindByName;
|
virNWFilterObjFindByName;
|
||||||
virNWFilterObjFindByUUID;
|
virNWFilterObjFindByUUID;
|
||||||
|
virNWFilterObjGetNames;
|
||||||
virNWFilterObjListFree;
|
virNWFilterObjListFree;
|
||||||
virNWFilterObjLoadAllConfigs;
|
virNWFilterObjLoadAllConfigs;
|
||||||
virNWFilterObjLock;
|
virNWFilterObjLock;
|
||||||
|
@ -425,36 +425,19 @@ nwfilterConnectNumOfNWFilters(virConnectPtr conn)
|
|||||||
static int
|
static int
|
||||||
nwfilterConnectListNWFilters(virConnectPtr conn,
|
nwfilterConnectListNWFilters(virConnectPtr conn,
|
||||||
char **const names,
|
char **const names,
|
||||||
int nnames)
|
int maxnames)
|
||||||
{
|
{
|
||||||
int got = 0;
|
int nnames;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (virConnectListNWFiltersEnsureACL(conn) < 0)
|
if (virConnectListNWFiltersEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
nwfilterDriverLock();
|
nwfilterDriverLock();
|
||||||
for (i = 0; i < driver->nwfilters.count && got < nnames; i++) {
|
nnames = virNWFilterObjGetNames(&driver->nwfilters, conn,
|
||||||
virNWFilterObjPtr obj = driver->nwfilters.objs[i];
|
virConnectListNWFiltersCheckACL,
|
||||||
virNWFilterObjLock(obj);
|
names, maxnames);
|
||||||
if (virConnectListNWFiltersCheckACL(conn, obj->def)) {
|
|
||||||
if (VIR_STRDUP(names[got], obj->def->name) < 0) {
|
|
||||||
virNWFilterObjUnlock(obj);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
got++;
|
|
||||||
}
|
|
||||||
virNWFilterObjUnlock(obj);
|
|
||||||
}
|
|
||||||
nwfilterDriverUnlock();
|
nwfilterDriverUnlock();
|
||||||
return got;
|
return nnames;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
nwfilterDriverUnlock();
|
|
||||||
for (i = 0; i < got; i++)
|
|
||||||
VIR_FREE(names[i]);
|
|
||||||
memset(names, 0, nnames * sizeof(*names));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user