mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03:00
interface: Introduce virInterfaceObjGetNames
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@redhat.com>
This commit is contained in:
parent
7dc4513808
commit
a9d33be34e
@ -234,3 +234,35 @@ 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)) {
|
||||
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]);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -85,4 +85,10 @@ int
|
||||
virInterfaceObjNumOfInterfaces(virInterfaceObjListPtr interfaces,
|
||||
bool wantActive);
|
||||
|
||||
int
|
||||
virInterfaceObjGetNames(virInterfaceObjListPtr interfaces,
|
||||
bool wantActive,
|
||||
char **const names,
|
||||
int maxnames);
|
||||
|
||||
#endif /* __VIRINTERFACEOBJ_H__ */
|
||||
|
@ -935,6 +935,7 @@ virDomainObjListRename;
|
||||
virInterfaceObjAssignDef;
|
||||
virInterfaceObjFindByMACString;
|
||||
virInterfaceObjFindByName;
|
||||
virInterfaceObjGetNames;
|
||||
virInterfaceObjListClone;
|
||||
virInterfaceObjListFree;
|
||||
virInterfaceObjLock;
|
||||
|
@ -3657,33 +3657,16 @@ 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;
|
||||
|
||||
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 +3680,16 @@ 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;
|
||||
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user