mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 09:53:10 +00:00
storage: Introduce virStoragePoolObjNumOfStoragePools
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@redhat.com>
This commit is contained in:
parent
96155c6994
commit
2fae7c7fb2
@ -557,6 +557,29 @@ 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))
|
||||||
|
npools++;
|
||||||
|
}
|
||||||
|
virStoragePoolObjUnlock(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
return npools;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* virStoragePoolObjIsDuplicate:
|
* virStoragePoolObjIsDuplicate:
|
||||||
* @doms : virStoragePoolObjListPtr to search
|
* @doms : virStoragePoolObjListPtr to search
|
||||||
|
@ -146,6 +146,15 @@ virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
|
|||||||
int
|
int
|
||||||
virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool);
|
virStoragePoolObjDeleteDef(virStoragePoolObjPtr pool);
|
||||||
|
|
||||||
|
typedef bool (*virStoragePoolObjListACLFilter)(virConnectPtr conn,
|
||||||
|
virStoragePoolDefPtr def);
|
||||||
|
|
||||||
|
int
|
||||||
|
virStoragePoolObjNumOfStoragePools(virStoragePoolObjListPtr pools,
|
||||||
|
virConnectPtr conn,
|
||||||
|
bool wantActive,
|
||||||
|
virStoragePoolObjListACLFilter aclfilter);
|
||||||
|
|
||||||
void
|
void
|
||||||
virStoragePoolObjFree(virStoragePoolObjPtr pool);
|
virStoragePoolObjFree(virStoragePoolObjPtr pool);
|
||||||
|
|
||||||
|
@ -1005,6 +1005,7 @@ virStoragePoolObjListFree;
|
|||||||
virStoragePoolObjLoadAllConfigs;
|
virStoragePoolObjLoadAllConfigs;
|
||||||
virStoragePoolObjLoadAllState;
|
virStoragePoolObjLoadAllState;
|
||||||
virStoragePoolObjLock;
|
virStoragePoolObjLock;
|
||||||
|
virStoragePoolObjNumOfStoragePools;
|
||||||
virStoragePoolObjNumOfVolumes;
|
virStoragePoolObjNumOfVolumes;
|
||||||
virStoragePoolObjRemove;
|
virStoragePoolObjRemove;
|
||||||
virStoragePoolObjSaveDef;
|
virStoragePoolObjSaveDef;
|
||||||
|
@ -477,21 +477,14 @@ storagePoolLookupByVolume(virStorageVolPtr vol)
|
|||||||
static int
|
static int
|
||||||
storageConnectNumOfStoragePools(virConnectPtr conn)
|
storageConnectNumOfStoragePools(virConnectPtr conn)
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
int nactive = 0;
|
int nactive = 0;
|
||||||
|
|
||||||
if (virConnectNumOfStoragePoolsEnsureACL(conn) < 0)
|
if (virConnectNumOfStoragePoolsEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
storageDriverLock();
|
storageDriverLock();
|
||||||
for (i = 0; i < driver->pools.count; i++) {
|
nactive = virStoragePoolObjNumOfStoragePools(&driver->pools, conn, true,
|
||||||
virStoragePoolObjPtr obj = driver->pools.objs[i];
|
virConnectNumOfStoragePoolsCheckACL);
|
||||||
virStoragePoolObjLock(obj);
|
|
||||||
if (virConnectNumOfStoragePoolsCheckACL(conn, obj->def) &&
|
|
||||||
virStoragePoolObjIsActive(obj))
|
|
||||||
nactive++;
|
|
||||||
virStoragePoolObjUnlock(obj);
|
|
||||||
}
|
|
||||||
storageDriverUnlock();
|
storageDriverUnlock();
|
||||||
|
|
||||||
return nactive;
|
return nactive;
|
||||||
@ -536,21 +529,14 @@ storageConnectListStoragePools(virConnectPtr conn,
|
|||||||
static int
|
static int
|
||||||
storageConnectNumOfDefinedStoragePools(virConnectPtr conn)
|
storageConnectNumOfDefinedStoragePools(virConnectPtr conn)
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
int nactive = 0;
|
int nactive = 0;
|
||||||
|
|
||||||
if (virConnectNumOfDefinedStoragePoolsEnsureACL(conn) < 0)
|
if (virConnectNumOfDefinedStoragePoolsEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
storageDriverLock();
|
storageDriverLock();
|
||||||
for (i = 0; i < driver->pools.count; i++) {
|
nactive = virStoragePoolObjNumOfStoragePools(&driver->pools, conn, false,
|
||||||
virStoragePoolObjPtr obj = driver->pools.objs[i];
|
virConnectNumOfDefinedStoragePoolsCheckACL);
|
||||||
virStoragePoolObjLock(obj);
|
|
||||||
if (virConnectNumOfDefinedStoragePoolsCheckACL(conn, obj->def) &&
|
|
||||||
!virStoragePoolObjIsActive(obj))
|
|
||||||
nactive++;
|
|
||||||
virStoragePoolObjUnlock(obj);
|
|
||||||
}
|
|
||||||
storageDriverUnlock();
|
storageDriverUnlock();
|
||||||
|
|
||||||
return nactive;
|
return nactive;
|
||||||
|
@ -4102,17 +4102,16 @@ testStoragePoolLookupByVolume(virStorageVolPtr vol)
|
|||||||
return testStoragePoolLookupByName(vol->conn, vol->pool);
|
return testStoragePoolLookupByName(vol->conn, vol->pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
testConnectNumOfStoragePools(virConnectPtr conn)
|
testConnectNumOfStoragePools(virConnectPtr conn)
|
||||||
{
|
{
|
||||||
testDriverPtr privconn = conn->privateData;
|
testDriverPtr privconn = conn->privateData;
|
||||||
int numActive = 0;
|
int numActive = 0;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
testDriverLock(privconn);
|
testDriverLock(privconn);
|
||||||
for (i = 0; i < privconn->pools.count; i++)
|
numActive = virStoragePoolObjNumOfStoragePools(&privconn->pools, conn,
|
||||||
if (virStoragePoolObjIsActive(privconn->pools.objs[i]))
|
true, NULL);
|
||||||
numActive++;
|
|
||||||
testDriverUnlock(privconn);
|
testDriverUnlock(privconn);
|
||||||
|
|
||||||
return numActive;
|
return numActive;
|
||||||
@ -4149,20 +4148,16 @@ testConnectListStoragePools(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
testConnectNumOfDefinedStoragePools(virConnectPtr conn)
|
testConnectNumOfDefinedStoragePools(virConnectPtr conn)
|
||||||
{
|
{
|
||||||
testDriverPtr privconn = conn->privateData;
|
testDriverPtr privconn = conn->privateData;
|
||||||
int numInactive = 0;
|
int numInactive = 0;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
testDriverLock(privconn);
|
testDriverLock(privconn);
|
||||||
for (i = 0; i < privconn->pools.count; i++) {
|
numInactive = virStoragePoolObjNumOfStoragePools(&privconn->pools, conn,
|
||||||
virStoragePoolObjLock(privconn->pools.objs[i]);
|
false, NULL);
|
||||||
if (!virStoragePoolObjIsActive(privconn->pools.objs[i]))
|
|
||||||
numInactive++;
|
|
||||||
virStoragePoolObjUnlock(privconn->pools.objs[i]);
|
|
||||||
}
|
|
||||||
testDriverUnlock(privconn);
|
testDriverUnlock(privconn);
|
||||||
|
|
||||||
return numInactive;
|
return numInactive;
|
||||||
|
Loading…
Reference in New Issue
Block a user