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: John Ferlan <jferlan@xxxxxxxxxx> --- src/conf/virnodedeviceobj.c | 22 ++++++++++++++++++++++ src/conf/virnodedeviceobj.h | 6 ++++++ src/libvirt_private.syms | 1 + src/node_device/node_device_driver.c | 12 ++---------- src/test/test_driver.c | 6 +----- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 3fe3ae5..f0c20c2 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -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 diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index e32bbf8..7d303a0 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -83,6 +83,12 @@ typedef bool virNodeDeviceDefPtr def); int +virNodeDeviceObjNumOfDevices(virNodeDeviceObjListPtr devs, + virConnectPtr conn, + const char *cap, + virNodeDeviceObjListFilter aclfilter); + +int virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjList devobjs, virNodeDevicePtr **devices, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 92083e5..104ed88 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -951,6 +951,7 @@ virNodeDeviceObjHasCap; virNodeDeviceObjListExport; virNodeDeviceObjListFree; virNodeDeviceObjLock; +virNodeDeviceObjNumOfDevices; virNodeDeviceObjRemove; virNodeDeviceObjUnlock; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index 99f7bc5..f90b168 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -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; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index cce4d2d..2f1f4fa 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5385,15 +5385,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; -- 2.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list