Essentially code motion to move the storage/test driver ListAllVolumes logic into virstorageobj.c Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/conf/virstorageobj.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ src/conf/virstorageobj.h | 7 +++++++ src/libvirt_private.syms | 1 + src/storage/storage_driver.c | 37 ++++------------------------------ src/test/test_driver.c | 40 ++++--------------------------------- 5 files changed, 63 insertions(+), 69 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 5933618..2484517 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -244,6 +244,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) diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h index bf88094..72daa5a 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -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); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a635cac..6298019 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1008,6 +1008,7 @@ virStoragePoolObjSaveDef; virStoragePoolObjSourceFindDuplicate; virStoragePoolObjUnlock; virStoragePoolObjVolumeGetNames; +virStoragePoolObjVolumeListExport; # cpu/cpu.h diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index ce77fe1..475e332 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1442,16 +1442,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); @@ -1468,38 +1465,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; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index b2840fa..44bd47c 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4867,16 +4867,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", @@ -4884,39 +4880,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; } -- 2.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list