src/storage/storage_driver.c: Implement poolListAllVolumes. --- src/storage/storage_driver.c | 67 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 0974879..c630c2e 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1154,6 +1154,72 @@ storagePoolListVolumes(virStoragePoolPtr obj, return -1; } +static int +storagePoolListAllVolumes(virStoragePoolPtr pool, + virStorageVolPtr **vols, + unsigned int flags) { + virStorageDriverStatePtr driver = pool->conn->storagePrivateData; + virStoragePoolObjPtr obj; + int i; + virStorageVolPtr *tmp_vols = NULL; + virStorageVolPtr vol = NULL; + int nvols = 0; + int ret = -1; + + virCheckFlags(0, -1); + + storageDriverLock(driver); + obj = virStoragePoolObjFindByUUID(&driver->pools, pool->uuid); + storageDriverUnlock(driver); + + if (!obj) { + virReportError(VIR_ERR_NO_STORAGE_POOL, "%s", + _("no storage pool with matching uuid")); + goto cleanup; + } + + if (!virStoragePoolObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("storage pool is not active")); + goto cleanup; + } + + /* Just returns the volumes count */ + if (!vols) { + ret = obj->volumes.count; + goto cleanup; + } + + if (VIR_ALLOC_N(tmp_vols, obj->volumes.count + 1) < 0) { + virReportOOMError(); + goto cleanup; + } + + for (i = 0 ; i < obj->volumes.count; i++) { + if (!(vol = virGetStorageVol(pool->conn, obj->def->name, + obj->volumes.objs[i]->name, + obj->volumes.objs[i]->key))) + goto cleanup; + tmp_vols[nvols++] = vol; + } + + *vols = tmp_vols; + tmp_vols = NULL; + ret = nvols; + + cleanup: + if (tmp_vols) { + for (i = 0; i < obj->volumes.count; i++) { + if (tmp_vols[i]) + virStorageVolFree(tmp_vols[i]); + } + } + + if (obj) + virStoragePoolObjUnlock(obj); + + return ret; +} static virStorageVolPtr storageVolumeLookupByName(virStoragePoolPtr obj, @@ -2332,6 +2398,7 @@ static virStorageDriver storageDriver = { .poolSetAutostart = storagePoolSetAutostart, /* 0.4.0 */ .poolNumOfVolumes = storagePoolNumVolumes, /* 0.4.0 */ .poolListVolumes = storagePoolListVolumes, /* 0.4.0 */ + .poolListAllVolumes = storagePoolListAllVolumes, /* 0.9.14 */ .volLookupByName = storageVolumeLookupByName, /* 0.4.0 */ .volLookupByKey = storageVolumeLookupByKey, /* 0.4.0 */ -- 1.7.7.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list