mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
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:
parent
4a440e4366
commit
7e94830f07
@ -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
|
virStoragePoolObjPtr
|
||||||
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
|
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
|
||||||
virStoragePoolDefPtr def)
|
virStoragePoolDefPtr def)
|
||||||
|
@ -119,6 +119,14 @@ virStoragePoolObjNumOfVolumes(virStorageVolDefListPtr volumes,
|
|||||||
virStoragePoolDefPtr pooldef,
|
virStoragePoolDefPtr pooldef,
|
||||||
virStoragePoolVolumeACLFilter aclfilter);
|
virStoragePoolVolumeACLFilter aclfilter);
|
||||||
|
|
||||||
|
int
|
||||||
|
virStoragePoolObjVolumeGetNames(virStorageVolDefListPtr volumes,
|
||||||
|
virConnectPtr conn,
|
||||||
|
virStoragePoolDefPtr pooldef,
|
||||||
|
virStoragePoolVolumeACLFilter aclfilter,
|
||||||
|
char **const names,
|
||||||
|
int maxnames);
|
||||||
|
|
||||||
virStoragePoolObjPtr
|
virStoragePoolObjPtr
|
||||||
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
|
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
|
||||||
virStoragePoolDefPtr def);
|
virStoragePoolDefPtr def);
|
||||||
|
@ -1010,6 +1010,7 @@ virStoragePoolObjRemove;
|
|||||||
virStoragePoolObjSaveDef;
|
virStoragePoolObjSaveDef;
|
||||||
virStoragePoolObjSourceFindDuplicate;
|
virStoragePoolObjSourceFindDuplicate;
|
||||||
virStoragePoolObjUnlock;
|
virStoragePoolObjUnlock;
|
||||||
|
virStoragePoolObjVolumeGetNames;
|
||||||
|
|
||||||
|
|
||||||
# cpu/cpu.h
|
# cpu/cpu.h
|
||||||
|
@ -1411,16 +1411,14 @@ storagePoolNumOfVolumes(virStoragePoolPtr obj)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
storagePoolListVolumes(virStoragePoolPtr obj,
|
storagePoolListVolumes(virStoragePoolPtr obj,
|
||||||
char **const names,
|
char **const names,
|
||||||
int maxnames)
|
int maxnames)
|
||||||
{
|
{
|
||||||
virStoragePoolObjPtr pool;
|
virStoragePoolObjPtr pool;
|
||||||
size_t i;
|
int n = -1;
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
memset(names, 0, maxnames * sizeof(*names));
|
|
||||||
|
|
||||||
if (!(pool = virStoragePoolObjFromStoragePool(obj)))
|
if (!(pool = virStoragePoolObjFromStoragePool(obj)))
|
||||||
return -1;
|
return -1;
|
||||||
@ -1434,24 +1432,12 @@ storagePoolListVolumes(virStoragePoolPtr obj,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < pool->volumes.count && n < maxnames; i++) {
|
n = virStoragePoolObjVolumeGetNames(&pool->volumes, obj->conn, pool->def,
|
||||||
if (!virStoragePoolListVolumesCheckACL(obj->conn, pool->def,
|
virStoragePoolListVolumesCheckACL,
|
||||||
pool->volumes.objs[i]))
|
names, maxnames);
|
||||||
continue;
|
|
||||||
if (VIR_STRDUP(names[n++], pool->volumes.objs[i]->name) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
virStoragePoolObjUnlock(pool);
|
|
||||||
return n;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virStoragePoolObjUnlock(pool);
|
virStoragePoolObjUnlock(pool);
|
||||||
for (n = 0; n < maxnames; n++)
|
return n;
|
||||||
VIR_FREE(names[n]);
|
|
||||||
|
|
||||||
memset(names, 0, maxnames * sizeof(*names));
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -4817,6 +4817,7 @@ testStoragePoolNumOfVolumes(virStoragePoolPtr pool)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
testStoragePoolListVolumes(virStoragePoolPtr pool,
|
testStoragePoolListVolumes(virStoragePoolPtr pool,
|
||||||
char **const names,
|
char **const names,
|
||||||
@ -4824,13 +4825,10 @@ testStoragePoolListVolumes(virStoragePoolPtr pool,
|
|||||||
{
|
{
|
||||||
testDriverPtr privconn = pool->conn->privateData;
|
testDriverPtr privconn = pool->conn->privateData;
|
||||||
virStoragePoolObjPtr privpool;
|
virStoragePoolObjPtr privpool;
|
||||||
size_t i = 0;
|
int n = -1;
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
memset(names, 0, maxnames * sizeof(*names));
|
|
||||||
|
|
||||||
if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name)))
|
if (!(privpool = testStoragePoolObjFindByName(privconn, pool->name)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (!virStoragePoolObjIsActive(privpool)) {
|
if (!virStoragePoolObjIsActive(privpool)) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
@ -4838,24 +4836,15 @@ testStoragePoolListVolumes(virStoragePoolPtr pool,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < privpool->volumes.count && n < maxnames; i++) {
|
n = virStoragePoolObjVolumeGetNames(&privpool->volumes, pool->conn,
|
||||||
if (VIR_STRDUP(names[n++], privpool->volumes.objs[i]->name) < 0)
|
privpool->def, NULL, names, maxnames);
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
virStoragePoolObjUnlock(privpool);
|
|
||||||
return n;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
for (n = 0; n < maxnames; n++)
|
virStoragePoolObjUnlock(privpool);
|
||||||
VIR_FREE(names[i]);
|
return n;
|
||||||
|
|
||||||
memset(names, 0, maxnames * sizeof(*names));
|
|
||||||
if (privpool)
|
|
||||||
virStoragePoolObjUnlock(privpool);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
testStoragePoolListAllVolumes(virStoragePoolPtr obj,
|
testStoragePoolListAllVolumes(virStoragePoolPtr obj,
|
||||||
virStorageVolPtr **vols,
|
virStorageVolPtr **vols,
|
||||||
|
Loading…
Reference in New Issue
Block a user