storage: Introduce virStoragePoolObjVolumeGetNames

Mostly code motion to move storagePoolListVolumes code into virstorageobj.c
and rename to virStoragePoolObjVolumeGetNames.

Also includes a couple of variable name adjustments to keep code consistent
with other drivers.

Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
John Ferlan 2017-03-20 12:16:26 -04:00
parent 4a440e4366
commit 7e94830f07
5 changed files with 53 additions and 39 deletions

View File

@ -215,6 +215,36 @@ virStoragePoolObjNumOfVolumes(virStorageVolDefListPtr volumes,
}
int
virStoragePoolObjVolumeGetNames(virStorageVolDefListPtr volumes,
virConnectPtr conn,
virStoragePoolDefPtr pooldef,
virStoragePoolVolumeACLFilter aclfilter,
char **const names,
int maxnames)
{
int nnames = 0;
size_t i;
for (i = 0; i < volumes->count && nnames < maxnames; i++) {
virStorageVolDefPtr def = volumes->objs[i];
if (aclfilter && !aclfilter(conn, pooldef, def))
continue;
if (VIR_STRDUP(names[nnames], def->name) < 0)
goto failure;
nnames++;
}
return nnames;
failure:
while (--nnames >= 0)
VIR_FREE(names[nnames]);
return -1;
}
virStoragePoolObjPtr
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
virStoragePoolDefPtr def)

View File

@ -119,6 +119,14 @@ virStoragePoolObjNumOfVolumes(virStorageVolDefListPtr volumes,
virStoragePoolDefPtr pooldef,
virStoragePoolVolumeACLFilter aclfilter);
int
virStoragePoolObjVolumeGetNames(virStorageVolDefListPtr volumes,
virConnectPtr conn,
virStoragePoolDefPtr pooldef,
virStoragePoolVolumeACLFilter aclfilter,
char **const names,
int maxnames);
virStoragePoolObjPtr
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
virStoragePoolDefPtr def);

View File

@ -1010,6 +1010,7 @@ virStoragePoolObjRemove;
virStoragePoolObjSaveDef;
virStoragePoolObjSourceFindDuplicate;
virStoragePoolObjUnlock;
virStoragePoolObjVolumeGetNames;
# cpu/cpu.h

View File

@ -1411,16 +1411,14 @@ storagePoolNumOfVolumes(virStoragePoolPtr obj)
return ret;
}
static int
storagePoolListVolumes(virStoragePoolPtr obj,
char **const names,
int maxnames)
{
virStoragePoolObjPtr pool;
size_t i;
int n = 0;
memset(names, 0, maxnames * sizeof(*names));
int n = -1;
if (!(pool = virStoragePoolObjFromStoragePool(obj)))
return -1;
@ -1434,24 +1432,12 @@ storagePoolListVolumes(virStoragePoolPtr obj,
goto cleanup;
}
for (i = 0; i < pool->volumes.count && n < maxnames; i++) {
if (!virStoragePoolListVolumesCheckACL(obj->conn, pool->def,
pool->volumes.objs[i]))
continue;
if (VIR_STRDUP(names[n++], pool->volumes.objs[i]->name) < 0)
goto cleanup;
}
virStoragePoolObjUnlock(pool);
return n;
n = virStoragePoolObjVolumeGetNames(&pool->volumes, obj->conn, pool->def,
virStoragePoolListVolumesCheckACL,
names, maxnames);
cleanup:
virStoragePoolObjUnlock(pool);
for (n = 0; n < maxnames; n++)
VIR_FREE(names[n]);
memset(names, 0, maxnames * sizeof(*names));
return -1;
return n;
}
static int

View File

@ -4817,6 +4817,7 @@ testStoragePoolNumOfVolumes(virStoragePoolPtr pool)
return ret;
}
static int
testStoragePoolListVolumes(virStoragePoolPtr pool,
char **const names,
@ -4824,13 +4825,10 @@ testStoragePoolListVolumes(virStoragePoolPtr pool,
{
testDriverPtr privconn = pool->conn->privateData;
virStoragePoolObjPtr privpool;
size_t i = 0;
int n = 0;
memset(names, 0, maxnames * sizeof(*names));
int n = -1;
if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name)))
goto cleanup;
return -1;
if (!virStoragePoolObjIsActive(privpool)) {
virReportError(VIR_ERR_OPERATION_INVALID,
@ -4838,24 +4836,15 @@ testStoragePoolListVolumes(virStoragePoolPtr pool,
goto cleanup;
}
for (i = 0; i < privpool->volumes.count && n < maxnames; i++) {
if (VIR_STRDUP(names[n++], privpool->volumes.objs[i]->name) < 0)
goto cleanup;
}
virStoragePoolObjUnlock(privpool);
return n;
n = virStoragePoolObjVolumeGetNames(&privpool->volumes, pool->conn,
privpool->def, NULL, names, maxnames);
cleanup:
for (n = 0; n < maxnames; n++)
VIR_FREE(names[i]);
memset(names, 0, maxnames * sizeof(*names));
if (privpool)
virStoragePoolObjUnlock(privpool);
return -1;
virStoragePoolObjUnlock(privpool);
return n;
}
static int
testStoragePoolListAllVolumes(virStoragePoolPtr obj,
virStorageVolPtr **vols,