提交 96155c69 编写于 作者: J John Ferlan

storage: Introduce virStoragePoolObjVolumeListExport

Essentially code motion to move the storage/test driver ListAllVolumes
logic into virstorageobj.c
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 7e94830f
......@@ -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
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
virStoragePoolDefPtr def)
......
......@@ -127,6 +127,13 @@ virStoragePoolObjVolumeGetNames(virStorageVolDefListPtr volumes,
char **const names,
int maxnames);
int
virStoragePoolObjVolumeListExport(virConnectPtr conn,
virStorageVolDefListPtr volumes,
virStoragePoolDefPtr pooldef,
virStorageVolPtr **vols,
virStoragePoolVolumeACLFilter aclfilter);
virStoragePoolObjPtr
virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
virStoragePoolDefPtr def);
......
......@@ -1011,6 +1011,7 @@ virStoragePoolObjSaveDef;
virStoragePoolObjSourceFindDuplicate;
virStoragePoolObjUnlock;
virStoragePoolObjVolumeGetNames;
virStoragePoolObjVolumeListExport;
# cpu/cpu.h
......
......@@ -1440,16 +1440,13 @@ storagePoolListVolumes(virStoragePoolPtr obj,
return n;
}
static int
storagePoolListAllVolumes(virStoragePoolPtr pool,
virStorageVolPtr **vols,
unsigned int flags)
{
virStoragePoolObjPtr obj;
size_t i;
virStorageVolPtr *tmp_vols = NULL;
virStorageVolPtr vol = NULL;
int nvols = 0;
int ret = -1;
virCheckFlags(0, -1);
......@@ -1466,38 +1463,12 @@ storagePoolListAllVolumes(virStoragePoolPtr pool,
goto cleanup;
}
/* Just returns the volumes count */
if (!vols) {
ret = obj->volumes.count;
goto cleanup;
}
ret = virStoragePoolObjVolumeListExport(pool->conn, &obj->volumes,
obj->def, vols,
virStoragePoolListAllVolumesCheckACL);
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:
if (tmp_vols) {
for (i = 0; i < nvols; i++)
virObjectUnref(tmp_vols[i]);
VIR_FREE(tmp_vols);
}
virStoragePoolObjUnlock(obj);
return ret;
......
......@@ -4852,16 +4852,12 @@ testStoragePoolListAllVolumes(virStoragePoolPtr obj,
{
testDriverPtr privconn = obj->conn->privateData;
virStoragePoolObjPtr pool;
size_t i;
virStorageVolPtr *tmp_vols = NULL;
virStorageVolPtr vol = NULL;
int nvols = 0;
int ret = -1;
virCheckFlags(0, -1);
if (!(pool = testStoragePoolObjFindByUUID(privconn, obj->uuid)))
goto cleanup;
return -1;
if (!virStoragePoolObjIsActive(pool)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
......@@ -4869,39 +4865,11 @@ testStoragePoolListAllVolumes(virStoragePoolPtr obj,
goto cleanup;
}
/* Just returns the volumes count */
if (!vols) {
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;
ret = virStoragePoolObjVolumeListExport(obj->conn, &pool->volumes,
pool->def, vols, NULL);
cleanup:
if (tmp_vols) {
for (i = 0; i < nvols; i++) {
if (tmp_vols[i])
virStorageVolFree(tmp_vols[i]);
}
VIR_FREE(tmp_vols);
}
if (pool)
virStoragePoolObjUnlock(pool);
virStoragePoolObjUnlock(pool);
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册