mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
nodedev: Introduce virNodeDeviceObjGetNames
Unify the *ListDevice API into virnodedeviceobj.c from node_device_driver and test_driver. The only real difference between the two is that the test driver doesn't call the aclfilter API. The name of the new API follows that of other drivers to "GetNames". NB: Change some variable names to match what they really are - consistency with other drivers. Also added a clear of the input names. This also allows virNodeDeviceObjHasCap to be static to virnodedeviceobj Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
be3c2dfd1a
commit
d06d1a329d
@ -33,7 +33,7 @@
|
||||
VIR_LOG_INIT("conf.virnodedeviceobj");
|
||||
|
||||
|
||||
int
|
||||
static int
|
||||
virNodeDeviceObjHasCap(const virNodeDeviceObj *dev,
|
||||
const char *cap)
|
||||
{
|
||||
@ -496,6 +496,39 @@ virNodeDeviceObjNumOfDevices(virNodeDeviceObjListPtr devs,
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virNodeDeviceObjGetNames(virNodeDeviceObjListPtr devs,
|
||||
virConnectPtr conn,
|
||||
virNodeDeviceObjListFilter aclfilter,
|
||||
const char *cap,
|
||||
char **const names,
|
||||
int maxnames)
|
||||
{
|
||||
int nnames = 0;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < devs->count && nnames < maxnames; i++) {
|
||||
virNodeDeviceObjPtr obj = devs->objs[i];
|
||||
virNodeDeviceObjLock(obj);
|
||||
if (aclfilter && aclfilter(conn, obj->def) &&
|
||||
(!cap || virNodeDeviceObjHasCap(obj, cap))) {
|
||||
if (VIR_STRDUP(names[nnames++], obj->def->name) < 0) {
|
||||
virNodeDeviceObjUnlock(obj);
|
||||
goto failure;
|
||||
}
|
||||
}
|
||||
virNodeDeviceObjUnlock(obj);
|
||||
}
|
||||
|
||||
return nnames;
|
||||
|
||||
failure:
|
||||
while (--nnames >= 0)
|
||||
VIR_FREE(names[nnames]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && \
|
||||
virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FLAG))
|
||||
static bool
|
||||
|
@ -40,10 +40,6 @@ struct _virNodeDeviceDriverState {
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
virNodeDeviceObjHasCap(const virNodeDeviceObj *dev,
|
||||
const char *cap);
|
||||
|
||||
virNodeDeviceObjPtr
|
||||
virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs,
|
||||
const char *name);
|
||||
@ -88,6 +84,14 @@ virNodeDeviceObjNumOfDevices(virNodeDeviceObjListPtr devs,
|
||||
const char *cap,
|
||||
virNodeDeviceObjListFilter aclfilter);
|
||||
|
||||
int
|
||||
virNodeDeviceObjGetNames(virNodeDeviceObjListPtr devs,
|
||||
virConnectPtr conn,
|
||||
virNodeDeviceObjListFilter aclfilter,
|
||||
const char *cap,
|
||||
char **const names,
|
||||
int maxnames);
|
||||
|
||||
int
|
||||
virNodeDeviceObjListExport(virConnectPtr conn,
|
||||
virNodeDeviceObjList devobjs,
|
||||
|
@ -948,8 +948,8 @@ virInterfaceObjUnlock;
|
||||
virNodeDeviceObjAssignDef;
|
||||
virNodeDeviceObjFindByName;
|
||||
virNodeDeviceObjFindBySysfsPath;
|
||||
virNodeDeviceObjGetNames;
|
||||
virNodeDeviceObjGetParentHost;
|
||||
virNodeDeviceObjHasCap;
|
||||
virNodeDeviceObjListExport;
|
||||
virNodeDeviceObjListFree;
|
||||
virNodeDeviceObjLock;
|
||||
|
@ -174,14 +174,15 @@ nodeNumOfDevices(virConnectPtr conn,
|
||||
return ndevs;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
nodeListDevices(virConnectPtr conn,
|
||||
const char *cap,
|
||||
char **const names, int maxnames,
|
||||
char **const names,
|
||||
int maxnames,
|
||||
unsigned int flags)
|
||||
{
|
||||
int ndevs = 0;
|
||||
size_t i;
|
||||
int nnames;
|
||||
|
||||
if (virNodeListDevicesEnsureACL(conn) < 0)
|
||||
return -1;
|
||||
@ -189,29 +190,12 @@ nodeListDevices(virConnectPtr conn,
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
nodeDeviceLock();
|
||||
for (i = 0; i < driver->devs.count && ndevs < maxnames; i++) {
|
||||
virNodeDeviceObjPtr obj = driver->devs.objs[i];
|
||||
virNodeDeviceObjLock(obj);
|
||||
if (virNodeListDevicesCheckACL(conn, obj->def) &&
|
||||
(cap == NULL ||
|
||||
virNodeDeviceObjHasCap(obj, cap))) {
|
||||
if (VIR_STRDUP(names[ndevs++], obj->def->name) < 0) {
|
||||
virNodeDeviceObjUnlock(obj);
|
||||
goto failure;
|
||||
}
|
||||
}
|
||||
virNodeDeviceObjUnlock(obj);
|
||||
}
|
||||
nnames = virNodeDeviceObjGetNames(&driver->devs, conn,
|
||||
virNodeListDevicesCheckACL,
|
||||
cap, names, maxnames);
|
||||
nodeDeviceUnlock();
|
||||
|
||||
return ndevs;
|
||||
|
||||
failure:
|
||||
nodeDeviceUnlock();
|
||||
--ndevs;
|
||||
while (--ndevs >= 0)
|
||||
VIR_FREE(names[ndevs]);
|
||||
return -1;
|
||||
return nnames;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -5382,6 +5382,7 @@ testNodeNumOfDevices(virConnectPtr conn,
|
||||
return ndevs;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
testNodeListDevices(virConnectPtr conn,
|
||||
const char *cap,
|
||||
@ -5390,35 +5391,19 @@ testNodeListDevices(virConnectPtr conn,
|
||||
unsigned int flags)
|
||||
{
|
||||
testDriverPtr driver = conn->privateData;
|
||||
int ndevs = 0;
|
||||
size_t i;
|
||||
int nnames = 0;
|
||||
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
testDriverLock(driver);
|
||||
for (i = 0; i < driver->devs.count && ndevs < maxnames; i++) {
|
||||
virNodeDeviceObjLock(driver->devs.objs[i]);
|
||||
if (cap == NULL ||
|
||||
virNodeDeviceObjHasCap(driver->devs.objs[i], cap)) {
|
||||
if (VIR_STRDUP(names[ndevs++], driver->devs.objs[i]->def->name) < 0) {
|
||||
virNodeDeviceObjUnlock(driver->devs.objs[i]);
|
||||
goto failure;
|
||||
}
|
||||
}
|
||||
virNodeDeviceObjUnlock(driver->devs.objs[i]);
|
||||
}
|
||||
nnames = virNodeDeviceObjGetNames(&driver->devs, conn, NULL,
|
||||
cap, names, maxnames);
|
||||
testDriverUnlock(driver);
|
||||
|
||||
return ndevs;
|
||||
|
||||
failure:
|
||||
testDriverUnlock(driver);
|
||||
--ndevs;
|
||||
while (--ndevs >= 0)
|
||||
VIR_FREE(names[ndevs]);
|
||||
return -1;
|
||||
return nnames;
|
||||
}
|
||||
|
||||
|
||||
static virNodeDevicePtr
|
||||
testNodeDeviceLookupByName(virConnectPtr conn, const char *name)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user