1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-12 13:17:58 +03:00

interface: Introduce virInterfaceObjNumOfInterfaces

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@redhat.com>
This commit is contained in:
John Ferlan 2017-04-06 09:23:17 -04:00
parent 4c661a944d
commit 7dc4513808
4 changed files with 30 additions and 18 deletions

View File

@ -215,3 +215,22 @@ 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))
ninterfaces++;
virInterfaceObjUnlock(obj);
}
return ninterfaces;
}

View File

@ -81,4 +81,8 @@ typedef bool
(*virInterfaceObjListFilter)(virConnectPtr conn,
virInterfaceDefPtr def);
int
virInterfaceObjNumOfInterfaces(virInterfaceObjListPtr interfaces,
bool wantActive);
#endif /* __VIRINTERFACEOBJ_H__ */

View File

@ -938,6 +938,7 @@ virInterfaceObjFindByName;
virInterfaceObjListClone;
virInterfaceObjListFree;
virInterfaceObjLock;
virInterfaceObjNumOfInterfaces;
virInterfaceObjRemove;
virInterfaceObjUnlock;

View File

@ -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)