提交 4a440e43 编写于 作者: J John Ferlan

storage: Introduce virStoragePoolObjNumOfVolumes

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: NJohn Ferlan <jferlan@redhat.com>
上级 8d04ea16
......@@ -195,6 +195,26 @@ 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))
continue;
nvolumes++;
}
return nvolumes;
}
virStoragePoolObjPtr
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
virStoragePoolDefPtr def)
......
......@@ -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);
......
......@@ -1005,6 +1005,7 @@ virStoragePoolObjListFree;
virStoragePoolObjLoadAllConfigs;
virStoragePoolObjLoadAllState;
virStoragePoolObjLock;
virStoragePoolObjNumOfVolumes;
virStoragePoolObjRemove;
virStoragePoolObjSaveDef;
virStoragePoolObjSourceFindDuplicate;
......
......@@ -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);
......
......@@ -4808,7 +4808,8 @@ testStoragePoolNumOfVolumes(virStoragePoolPtr pool)
goto cleanup;
}
ret = privpool->volumes.count;
ret = virStoragePoolObjNumOfVolumes(&privpool->volumes, pool->conn,
privpool->def, NULL);
cleanup:
if (privpool)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册