Unify the NumOfVolumes API into virstorageobj.c from storage_driver and test_driver. The only real difference between the two is the test driver doesn't call using the aclfilter API. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/conf/virstorageobj.c | 19 +++++++++++++++++++ src/conf/virstorageobj.h | 11 +++++++++++ src/libvirt_private.syms | 1 + src/storage/storage_driver.c | 10 +++------- src/test/test_driver.c | 3 ++- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 34f2eb7..e57694c 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -195,6 +195,25 @@ virStorageVolDefFindByName(virStoragePoolObjPtr pool, } +int +virStoragePoolObjNumOfVolumes(virStorageVolDefListPtr volumes, + virConnectPtr conn, + virStoragePoolDefPtr pooldef, + virStoragePoolVolumeACLFilter aclfilter) +{ + int nvolumes = 0; + size_t i; + + for (i = 0; i < volumes->count; i++) { + virStorageVolDefPtr def = volumes->objs[i]; + if (aclfilter && aclfilter(conn, pooldef, def)) + nvolumes++; + } + + return nvolumes; +} + + virStoragePoolObjPtr virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def) diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index ecba94e..3effe7a 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -108,6 +108,17 @@ virStorageVolDefFindByName(virStoragePoolObjPtr pool, void virStoragePoolObjClearVols(virStoragePoolObjPtr pool); +typedef bool +(*virStoragePoolVolumeACLFilter)(virConnectPtr conn, + virStoragePoolDefPtr pool, + virStorageVolDefPtr def); + +int +virStoragePoolObjNumOfVolumes(virStorageVolDefListPtr volumes, + virConnectPtr conn, + virStoragePoolDefPtr pooldef, + virStoragePoolVolumeACLFilter aclfilter); + virStoragePoolObjPtr virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools, virStoragePoolDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 92083e5..9580622 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1002,6 +1002,7 @@ virStoragePoolObjListFree; virStoragePoolObjLoadAllConfigs; virStoragePoolObjLoadAllState; virStoragePoolObjLock; +virStoragePoolObjNumOfVolumes; virStoragePoolObjRemove; virStoragePoolObjSaveDef; virStoragePoolObjSourceFindDuplicate; diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index fea7698..7d2f74d 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1390,7 +1390,6 @@ storagePoolNumOfVolumes(virStoragePoolPtr obj) { virStoragePoolObjPtr pool; int ret = -1; - size_t i; if (!(pool = virStoragePoolObjFromStoragePool(obj))) return -1; @@ -1403,12 +1402,9 @@ storagePoolNumOfVolumes(virStoragePoolPtr obj) _("storage pool '%s' is not active"), pool->def->name); goto cleanup; } - ret = 0; - for (i = 0; i < pool->volumes.count; i++) { - if (virStoragePoolNumOfVolumesCheckACL(obj->conn, pool->def, - pool->volumes.objs[i])) - ret++; - } + + ret = virStoragePoolObjNumOfVolumes(&pool->volumes, obj->conn, pool->def, + virStoragePoolNumOfVolumesCheckACL); cleanup: virStoragePoolObjUnlock(pool); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index cce4d2d..a4b5833 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4821,7 +4821,8 @@ testStoragePoolNumOfVolumes(virStoragePoolPtr pool) goto cleanup; } - ret = privpool->volumes.count; + ret = virStoragePoolObjNumOfVolumes(&privpool->volumes, pool->conn, + privpool->def, NULL); cleanup: if (privpool) -- 2.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list