mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
storage: Introduce virStoragePoolObjVolumeListExport
Essentially code motion to move the storage/test driver ListAllVolumes logic into virstorageobj.c Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
7e94830f07
commit
96155c6994
@ -245,6 +245,53 @@ virStoragePoolObjVolumeGetNames(virStorageVolDefListPtr volumes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
virStoragePoolObjVolumeListExport(virConnectPtr conn,
|
||||||
|
virStorageVolDefListPtr volumes,
|
||||||
|
virStoragePoolDefPtr pooldef,
|
||||||
|
virStorageVolPtr **vols,
|
||||||
|
virStoragePoolVolumeACLFilter aclfilter)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
size_t i;
|
||||||
|
virStorageVolPtr *tmp_vols = NULL;
|
||||||
|
virStorageVolPtr vol = NULL;
|
||||||
|
int nvols = 0;
|
||||||
|
|
||||||
|
/* Just returns the volumes count */
|
||||||
|
if (!vols) {
|
||||||
|
ret = volumes->count;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIR_ALLOC_N(tmp_vols, volumes->count + 1) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
for (i = 0; i < volumes->count; i++) {
|
||||||
|
virStorageVolDefPtr def = volumes->objs[i];
|
||||||
|
if (aclfilter && !aclfilter(conn, pooldef, def))
|
||||||
|
continue;
|
||||||
|
if (!(vol = virGetStorageVol(conn, pooldef->name, def->name, def->key,
|
||||||
|
NULL, NULL)))
|
||||||
|
goto cleanup;
|
||||||
|
tmp_vols[nvols++] = vol;
|
||||||
|
}
|
||||||
|
|
||||||
|
*vols = tmp_vols;
|
||||||
|
tmp_vols = NULL;
|
||||||
|
ret = nvols;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (tmp_vols) {
|
||||||
|
for (i = 0; i < nvols; i++)
|
||||||
|
virObjectUnref(tmp_vols[i]);
|
||||||
|
VIR_FREE(tmp_vols);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
virStoragePoolObjPtr
|
virStoragePoolObjPtr
|
||||||
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
|
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
|
||||||
virStoragePoolDefPtr def)
|
virStoragePoolDefPtr def)
|
||||||
|
@ -127,6 +127,13 @@ virStoragePoolObjVolumeGetNames(virStorageVolDefListPtr volumes,
|
|||||||
char **const names,
|
char **const names,
|
||||||
int maxnames);
|
int maxnames);
|
||||||
|
|
||||||
|
int
|
||||||
|
virStoragePoolObjVolumeListExport(virConnectPtr conn,
|
||||||
|
virStorageVolDefListPtr volumes,
|
||||||
|
virStoragePoolDefPtr pooldef,
|
||||||
|
virStorageVolPtr **vols,
|
||||||
|
virStoragePoolVolumeACLFilter aclfilter);
|
||||||
|
|
||||||
virStoragePoolObjPtr
|
virStoragePoolObjPtr
|
||||||
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
|
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
|
||||||
virStoragePoolDefPtr def);
|
virStoragePoolDefPtr def);
|
||||||
|
@ -1011,6 +1011,7 @@ virStoragePoolObjSaveDef;
|
|||||||
virStoragePoolObjSourceFindDuplicate;
|
virStoragePoolObjSourceFindDuplicate;
|
||||||
virStoragePoolObjUnlock;
|
virStoragePoolObjUnlock;
|
||||||
virStoragePoolObjVolumeGetNames;
|
virStoragePoolObjVolumeGetNames;
|
||||||
|
virStoragePoolObjVolumeListExport;
|
||||||
|
|
||||||
|
|
||||||
# cpu/cpu.h
|
# cpu/cpu.h
|
||||||
|
@ -1440,16 +1440,13 @@ storagePoolListVolumes(virStoragePoolPtr obj,
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
storagePoolListAllVolumes(virStoragePoolPtr pool,
|
storagePoolListAllVolumes(virStoragePoolPtr pool,
|
||||||
virStorageVolPtr **vols,
|
virStorageVolPtr **vols,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virStoragePoolObjPtr obj;
|
virStoragePoolObjPtr obj;
|
||||||
size_t i;
|
|
||||||
virStorageVolPtr *tmp_vols = NULL;
|
|
||||||
virStorageVolPtr vol = NULL;
|
|
||||||
int nvols = 0;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
@ -1466,38 +1463,12 @@ storagePoolListAllVolumes(virStoragePoolPtr pool,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Just returns the volumes count */
|
ret = virStoragePoolObjVolumeListExport(pool->conn, &obj->volumes,
|
||||||
if (!vols) {
|
obj->def, vols,
|
||||||
ret = obj->volumes.count;
|
virStoragePoolListAllVolumesCheckACL);
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_ALLOC_N(tmp_vols, obj->volumes.count + 1) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
for (i = 0; i < obj->volumes.count; i++) {
|
|
||||||
if (!virStoragePoolListAllVolumesCheckACL(pool->conn, obj->def,
|
|
||||||
obj->volumes.objs[i]))
|
|
||||||
continue;
|
|
||||||
if (!(vol = virGetStorageVol(pool->conn, obj->def->name,
|
|
||||||
obj->volumes.objs[i]->name,
|
|
||||||
obj->volumes.objs[i]->key,
|
|
||||||
NULL, NULL)))
|
|
||||||
goto cleanup;
|
|
||||||
tmp_vols[nvols++] = vol;
|
|
||||||
}
|
|
||||||
|
|
||||||
*vols = tmp_vols;
|
|
||||||
tmp_vols = NULL;
|
|
||||||
ret = nvols;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (tmp_vols) {
|
|
||||||
for (i = 0; i < nvols; i++)
|
|
||||||
virObjectUnref(tmp_vols[i]);
|
|
||||||
VIR_FREE(tmp_vols);
|
|
||||||
}
|
|
||||||
|
|
||||||
virStoragePoolObjUnlock(obj);
|
virStoragePoolObjUnlock(obj);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -4852,16 +4852,12 @@ testStoragePoolListAllVolumes(virStoragePoolPtr obj,
|
|||||||
{
|
{
|
||||||
testDriverPtr privconn = obj->conn->privateData;
|
testDriverPtr privconn = obj->conn->privateData;
|
||||||
virStoragePoolObjPtr pool;
|
virStoragePoolObjPtr pool;
|
||||||
size_t i;
|
|
||||||
virStorageVolPtr *tmp_vols = NULL;
|
|
||||||
virStorageVolPtr vol = NULL;
|
|
||||||
int nvols = 0;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
if (!(pool = testStoragePoolObjFindByUUID(privconn, obj->uuid)))
|
if (!(pool = testStoragePoolObjFindByUUID(privconn, obj->uuid)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (!virStoragePoolObjIsActive(pool)) {
|
if (!virStoragePoolObjIsActive(pool)) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
@ -4869,39 +4865,11 @@ testStoragePoolListAllVolumes(virStoragePoolPtr obj,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Just returns the volumes count */
|
ret = virStoragePoolObjVolumeListExport(obj->conn, &pool->volumes,
|
||||||
if (!vols) {
|
pool->def, vols, NULL);
|
||||||
ret = pool->volumes.count;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (VIR_ALLOC_N(tmp_vols, pool->volumes.count + 1) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
for (i = 0; i < pool->volumes.count; i++) {
|
|
||||||
if (!(vol = virGetStorageVol(obj->conn, pool->def->name,
|
|
||||||
pool->volumes.objs[i]->name,
|
|
||||||
pool->volumes.objs[i]->key,
|
|
||||||
NULL, NULL)))
|
|
||||||
goto cleanup;
|
|
||||||
tmp_vols[nvols++] = vol;
|
|
||||||
}
|
|
||||||
|
|
||||||
*vols = tmp_vols;
|
|
||||||
tmp_vols = NULL;
|
|
||||||
ret = nvols;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (tmp_vols) {
|
virStoragePoolObjUnlock(pool);
|
||||||
for (i = 0; i < nvols; i++) {
|
|
||||||
if (tmp_vols[i])
|
|
||||||
virStorageVolFree(tmp_vols[i]);
|
|
||||||
}
|
|
||||||
VIR_FREE(tmp_vols);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pool)
|
|
||||||
virStoragePoolObjUnlock(pool);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user