Unlike other drivers, this is a test driver only API. Still combining
the logic of testConnectListInterfaces and testConnectListDefinedInterfaces
makes things a bit easier in the long run.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/virinterfaceobj.c | 34 +++++++++++++++++++++++++++++
src/conf/virinterfaceobj.h | 6 ++++++
src/libvirt_private.syms | 1 +
src/test/test_driver.c | 54 +++++++++++-----------------------------------
4 files changed, 53 insertions(+), 42 deletions(-)
diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index 0407c1f..229226a 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -235,3 +235,37 @@ virInterfaceObjNumOfInterfaces(virInterfaceObjListPtr interfaces,
return ninterfaces;
}
+
+
+int
+virInterfaceObjGetNames(virInterfaceObjListPtr interfaces,
+ bool wantActive,
+ char **const names,
+ int maxnames)
+{
+ int nnames = 0;
+ size_t i;
+
+ for (i = 0; i < interfaces->count && nnames < maxnames; i++) {
+ virInterfaceObjPtr obj = interfaces->objs[i];
+ virInterfaceObjLock(obj);
+ if ((wantActive && virInterfaceObjIsActive(obj)) ||
+ (!wantActive && !virInterfaceObjIsActive(obj))) {
+ if (VIR_STRDUP(names[nnames], obj->def->name) < 0) {
+ virInterfaceObjUnlock(obj);
+ goto failure;
+ }
+ nnames++;
+ }
+ virInterfaceObjUnlock(obj);
+ }
+
+ return nnames;
+
+ failure:
+ while (--nnames >= 0)
+ VIR_FREE(names[nnames]);
+ memset(names, 0, maxnames * sizeof(*names));
+
+ return -1;
+}
diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h
index 2f07174..5b0527d 100644
--- a/src/conf/virinterfaceobj.h
+++ b/src/conf/virinterfaceobj.h
@@ -85,4 +85,10 @@ int
virInterfaceObjNumOfInterfaces(virInterfaceObjListPtr interfaces,
bool wantActive);
+int
+virInterfaceObjGetNames(virInterfaceObjListPtr interfaces,
+ bool wantActive,
+ char **const names,
+ int maxnames);
+
#endif /* __VIRINTERFACEOBJ_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 96aacaa..88e530c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -935,6 +935,7 @@ virDomainObjListRename;
virInterfaceObjAssignDef;
virInterfaceObjFindByMACString;
virInterfaceObjFindByName;
+virInterfaceObjGetNames;
virInterfaceObjListClone;
virInterfaceObjListFree;
virInterfaceObjLock;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 6910681..4e10eb2 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3657,33 +3657,18 @@ static int testConnectNumOfInterfaces(virConnectPtr conn)
return ninterfaces;
}
-static int testConnectListInterfaces(virConnectPtr conn, char **const names, int nnames)
+static int testConnectListInterfaces(virConnectPtr conn, char **const names, int
maxnames)
{
testDriverPtr privconn = conn->privateData;
- int n = 0;
- size_t i;
+ int nnames;
+
+ memset(names, 0, maxnames * sizeof(*names));
testDriverLock(privconn);
- memset(names, 0, sizeof(*names)*nnames);
- for (i = 0; (i < privconn->ifaces.count) && (n < nnames); i++) {
- virInterfaceObjLock(privconn->ifaces.objs[i]);
- if (virInterfaceObjIsActive(privconn->ifaces.objs[i])) {
- if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) <
0) {
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- goto error;
- }
- }
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- }
+ nnames = virInterfaceObjGetNames(&privconn->ifaces, true, names, maxnames);
testDriverUnlock(privconn);
- return n;
-
- error:
- for (n = 0; n < nnames; n++)
- VIR_FREE(names[n]);
- testDriverUnlock(privconn);
- return -1;
+ return nnames;
}
static int testConnectNumOfDefinedInterfaces(virConnectPtr conn)
@@ -3697,33 +3682,18 @@ static int testConnectNumOfDefinedInterfaces(virConnectPtr conn)
return ninterfaces;
}
-static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const names, int
nnames)
+static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const names, int
maxnames)
{
testDriverPtr privconn = conn->privateData;
- int n = 0;
- size_t i;
+ int nnames;
+
+ memset(names, 0, maxnames * sizeof(*names));
testDriverLock(privconn);
- memset(names, 0, sizeof(*names)*nnames);
- for (i = 0; (i < privconn->ifaces.count) && (n < nnames); i++) {
- virInterfaceObjLock(privconn->ifaces.objs[i]);
- if (!virInterfaceObjIsActive(privconn->ifaces.objs[i])) {
- if (VIR_STRDUP(names[n++], privconn->ifaces.objs[i]->def->name) <
0) {
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- goto error;
- }
- }
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- }
+ nnames = virInterfaceObjGetNames(&privconn->ifaces, false, names, maxnames);
testDriverUnlock(privconn);
- return n;
-
- error:
- for (n = 0; n < nnames; n++)
- VIR_FREE(names[n]);
- testDriverUnlock(privconn);
- return -1;
+ return nnames;
}
static virInterfacePtr testInterfaceLookupByName(virConnectPtr conn,
--
2.9.3