Unify the NumOf[Defined]StoragePools 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(a)redhat.com>
---
src/conf/virstorageobj.c | 24 ++++++++++++++++++++++++
src/conf/virstorageobj.h | 9 +++++++++
src/libvirt_private.syms | 1 +
src/storage/storage_driver.c | 22 ++++------------------
src/test/test_driver.c | 17 ++++++-----------
5 files changed, 44 insertions(+), 29 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 2484517..f0201aa 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -556,6 +556,30 @@ virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool)
}
+int
+virStoragePoolObjNumOfStoragePools(virStoragePoolObjListPtr pools,
+ virConnectPtr conn,
+ bool wantActive,
+ virStoragePoolObjListACLFilter aclfilter)
+{
+ int npools = 0;
+ size_t i;
+
+ for (i = 0; i < pools->count; i++) {
+ virStoragePoolObjPtr obj = pools->objs[i];
+ virStoragePoolObjLock(obj);
+ if (!aclfilter || aclfilter(conn, obj->def)) {
+ if ((wantActive && virStoragePoolObjIsActive(obj)) ||
+ (!wantActive && !virStoragePoolObjIsActive(obj)))
+ npools++;
+ }
+ virStoragePoolObjUnlock(obj);
+ }
+
+ return npools;
+}
+
+
/*
* virStoragePoolObjIsDuplicate:
* @doms : virStoragePoolObjListPtr to search
diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h
index 72daa5a..5eeda1e 100644
--- a/src/conf/virstorageobj.h
+++ b/src/conf/virstorageobj.h
@@ -146,6 +146,15 @@ virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
int
virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool);
+typedef bool (*virStoragePoolObjListACLFilter)(virConnectPtr conn,
+ virStoragePoolDefPtr def);
+
+int
+virStoragePoolObjNumOfStoragePools(virStoragePoolObjListPtr pools,
+ virConnectPtr conn,
+ bool wantActive,
+ virStoragePoolObjListACLFilter aclfilter);
+
void
virStoragePoolObjFree(virStoragePoolObjPtr pool);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6298019..7bc3bc4 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1002,6 +1002,7 @@ virStoragePoolObjListFree;
virStoragePoolObjLoadAllConfigs;
virStoragePoolObjLoadAllState;
virStoragePoolObjLock;
+virStoragePoolObjNumOfStoragePools;
virStoragePoolObjNumOfVolumes;
virStoragePoolObjRemove;
virStoragePoolObjSaveDef;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 475e332..065380b 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -477,21 +477,14 @@ storagePoolLookupByVolume(virStorageVolPtr vol)
static int
storageConnectNumOfStoragePools(virConnectPtr conn)
{
- size_t i;
int nactive = 0;
if (virConnectNumOfStoragePoolsEnsureACL(conn) < 0)
return -1;
storageDriverLock();
- for (i = 0; i < driver->pools.count; i++) {
- virStoragePoolObjPtr obj = driver->pools.objs[i];
- virStoragePoolObjLock(obj);
- if (virConnectNumOfStoragePoolsCheckACL(conn, obj->def) &&
- virStoragePoolObjIsActive(obj))
- nactive++;
- virStoragePoolObjUnlock(obj);
- }
+ nactive = virStoragePoolObjNumOfStoragePools(&driver->pools, conn, true,
+ virConnectNumOfStoragePoolsCheckACL);
storageDriverUnlock();
return nactive;
@@ -536,21 +529,14 @@ storageConnectListStoragePools(virConnectPtr conn,
static int
storageConnectNumOfDefinedStoragePools(virConnectPtr conn)
{
- size_t i;
int nactive = 0;
if (virConnectNumOfDefinedStoragePoolsEnsureACL(conn) < 0)
return -1;
storageDriverLock();
- for (i = 0; i < driver->pools.count; i++) {
- virStoragePoolObjPtr obj = driver->pools.objs[i];
- virStoragePoolObjLock(obj);
- if (virConnectNumOfDefinedStoragePoolsCheckACL(conn, obj->def) &&
- !virStoragePoolObjIsActive(obj))
- nactive++;
- virStoragePoolObjUnlock(obj);
- }
+ nactive = virStoragePoolObjNumOfStoragePools(&driver->pools, conn, false,
+
virConnectNumOfDefinedStoragePoolsCheckACL);
storageDriverUnlock();
return nactive;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 44bd47c..4fb9915 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -4115,17 +4115,16 @@ testStoragePoolLookupByVolume(virStorageVolPtr vol)
return testStoragePoolLookupByName(vol->conn, vol->pool);
}
+
static int
testConnectNumOfStoragePools(virConnectPtr conn)
{
testDriverPtr privconn = conn->privateData;
int numActive = 0;
- size_t i;
testDriverLock(privconn);
- for (i = 0; i < privconn->pools.count; i++)
- if (virStoragePoolObjIsActive(privconn->pools.objs[i]))
- numActive++;
+ numActive = virStoragePoolObjNumOfStoragePools(&privconn->pools, conn,
+ true, NULL);
testDriverUnlock(privconn);
return numActive;
@@ -4162,20 +4161,16 @@ testConnectListStoragePools(virConnectPtr conn,
return -1;
}
+
static int
testConnectNumOfDefinedStoragePools(virConnectPtr conn)
{
testDriverPtr privconn = conn->privateData;
int numInactive = 0;
- size_t i;
testDriverLock(privconn);
- for (i = 0; i < privconn->pools.count; i++) {
- virStoragePoolObjLock(privconn->pools.objs[i]);
- if (!virStoragePoolObjIsActive(privconn->pools.objs[i]))
- numInactive++;
- virStoragePoolObjUnlock(privconn->pools.objs[i]);
- }
+ numInactive = virStoragePoolObjNumOfStoragePools(&privconn->pools, conn,
+ false, NULL);
testDriverUnlock(privconn);
return numInactive;
--
2.9.3