Unlike other drivers, this is a test driver only API. Still combining
the logic of testConnectNumOfInterfaces and testConnectNumOfDefinedInterfaces
makes things a bit easier in the long run.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/virinterfaceobj.c | 20 ++++++++++++++++++++
src/conf/virinterfaceobj.h | 4 ++++
src/libvirt_private.syms | 1 +
src/test/test_driver.c | 24 ++++++------------------
4 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index 3af972b..0407c1f 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -215,3 +215,23 @@ virInterfaceObjRemove(virInterfaceObjListPtr interfaces,
virInterfaceObjUnlock(interfaces->objs[i]);
}
}
+
+
+int
+virInterfaceObjNumOfInterfaces(virInterfaceObjListPtr interfaces,
+ bool wantActive)
+{
+ size_t i;
+ int ninterfaces = 0;
+
+ for (i = 0; (i < interfaces->count); i++) {
+ virInterfaceObjPtr obj = interfaces->objs[i];
+ virInterfaceObjLock(obj);
+ if ((wantActive && virInterfaceObjIsActive(obj)) ||
+ (!wantActive && !virInterfaceObjIsActive(obj)))
+ ninterfaces++;
+ virInterfaceObjUnlock(obj);
+ }
+
+ return ninterfaces;
+}
diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h
index 6c5e2e7..2f07174 100644
--- a/src/conf/virinterfaceobj.h
+++ b/src/conf/virinterfaceobj.h
@@ -81,4 +81,8 @@ typedef bool
(*virInterfaceObjListFilter)(virConnectPtr conn,
virInterfaceDefPtr def);
+int
+virInterfaceObjNumOfInterfaces(virInterfaceObjListPtr interfaces,
+ bool wantActive);
+
#endif /* __VIRINTERFACEOBJ_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 92083e5..96aacaa 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -938,6 +938,7 @@ virInterfaceObjFindByName;
virInterfaceObjListClone;
virInterfaceObjListFree;
virInterfaceObjLock;
+virInterfaceObjNumOfInterfaces;
virInterfaceObjRemove;
virInterfaceObjUnlock;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index cce4d2d..6910681 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3649,18 +3649,12 @@ testInterfaceObjFindByName(testDriverPtr privconn,
static int testConnectNumOfInterfaces(virConnectPtr conn)
{
testDriverPtr privconn = conn->privateData;
- size_t i;
- int count = 0;
+ int ninterfaces;
testDriverLock(privconn);
- for (i = 0; (i < privconn->ifaces.count); i++) {
- virInterfaceObjLock(privconn->ifaces.objs[i]);
- if (virInterfaceObjIsActive(privconn->ifaces.objs[i]))
- count++;
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- }
+ ninterfaces = virInterfaceObjNumOfInterfaces(&privconn->ifaces, true);
testDriverUnlock(privconn);
- return count;
+ return ninterfaces;
}
static int testConnectListInterfaces(virConnectPtr conn, char **const names, int nnames)
@@ -3695,18 +3689,12 @@ static int testConnectListInterfaces(virConnectPtr conn, char
**const names, int
static int testConnectNumOfDefinedInterfaces(virConnectPtr conn)
{
testDriverPtr privconn = conn->privateData;
- size_t i;
- int count = 0;
+ int ninterfaces;
testDriverLock(privconn);
- for (i = 0; i < privconn->ifaces.count; i++) {
- virInterfaceObjLock(privconn->ifaces.objs[i]);
- if (!virInterfaceObjIsActive(privconn->ifaces.objs[i]))
- count++;
- virInterfaceObjUnlock(privconn->ifaces.objs[i]);
- }
+ ninterfaces = virInterfaceObjNumOfInterfaces(&privconn->ifaces, false);
testDriverUnlock(privconn);
- return count;
+ return ninterfaces;
}
static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const names, int
nnames)
--
2.9.3