提交 be3c2dfd 编写于 作者: J John Ferlan

nodedev: Introduce virNodeDeviceObjNumOfDevices

Unify the NumOfDevices 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.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 4fba4015
......@@ -474,6 +474,28 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj,
}
int
virNodeDeviceObjNumOfDevices(virNodeDeviceObjListPtr devs,
virConnectPtr conn,
const char *cap,
virNodeDeviceObjListFilter aclfilter)
{
size_t i;
int ndevs = 0;
for (i = 0; i < devs->count; i++) {
virNodeDeviceObjPtr obj = devs->objs[i];
virNodeDeviceObjLock(obj);
if (aclfilter && aclfilter(conn, obj->def) &&
(!cap || virNodeDeviceObjHasCap(obj, cap)))
++ndevs;
virNodeDeviceObjUnlock(obj);
}
return ndevs;
}
#define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && \
virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FLAG))
static bool
......
......@@ -82,6 +82,12 @@ typedef bool
(*virNodeDeviceObjListFilter)(virConnectPtr conn,
virNodeDeviceDefPtr def);
int
virNodeDeviceObjNumOfDevices(virNodeDeviceObjListPtr devs,
virConnectPtr conn,
const char *cap,
virNodeDeviceObjListFilter aclfilter);
int
virNodeDeviceObjListExport(virConnectPtr conn,
virNodeDeviceObjList devobjs,
......
......@@ -953,6 +953,7 @@ virNodeDeviceObjHasCap;
virNodeDeviceObjListExport;
virNodeDeviceObjListFree;
virNodeDeviceObjLock;
virNodeDeviceObjNumOfDevices;
virNodeDeviceObjRemove;
virNodeDeviceObjUnlock;
......
......@@ -160,7 +160,6 @@ nodeNumOfDevices(virConnectPtr conn,
unsigned int flags)
{
int ndevs = 0;
size_t i;
if (virNodeNumOfDevicesEnsureACL(conn) < 0)
return -1;
......@@ -168,15 +167,8 @@ nodeNumOfDevices(virConnectPtr conn,
virCheckFlags(0, -1);
nodeDeviceLock();
for (i = 0; i < driver->devs.count; i++) {
virNodeDeviceObjPtr obj = driver->devs.objs[i];
virNodeDeviceObjLock(obj);
if (virNodeNumOfDevicesCheckACL(conn, obj->def) &&
((cap == NULL) ||
virNodeDeviceObjHasCap(obj, cap)))
++ndevs;
virNodeDeviceObjUnlock(obj);
}
ndevs = virNodeDeviceObjNumOfDevices(&driver->devs, conn, cap,
virNodeNumOfDevicesCheckACL);
nodeDeviceUnlock();
return ndevs;
......
......@@ -5372,15 +5372,11 @@ testNodeNumOfDevices(virConnectPtr conn,
{
testDriverPtr driver = conn->privateData;
int ndevs = 0;
size_t i;
virCheckFlags(0, -1);
testDriverLock(driver);
for (i = 0; i < driver->devs.count; i++)
if ((cap == NULL) ||
virNodeDeviceObjHasCap(driver->devs.objs[i], cap))
++ndevs;
ndevs = virNodeDeviceObjNumOfDevices(&driver->devs, conn, cap, NULL);
testDriverUnlock(driver);
return ndevs;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册