Re: [PATCH 3/6] list: Implement virStoragePoolListAllVolumes for storage driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 09/04/12 17:32, Osier Yang wrote:
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 4f99eb9..4f83348 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1153,6 +1153,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 < nvols; i++) {
+            if (tmp_vols[i])
+                virStorageVolFree(tmp_vols[i]);
+        }
+    }
+
+    if (obj)
+        virStoragePoolObjUnlock(obj);
+
+    return ret;
+}

  static virStorageVolPtr
  storageVolumeLookupByName(virStoragePoolPtr obj,
@@ -2329,6 +2395,7 @@ static virStorageDriver storageDriver = {
      .poolSetAutostart = storagePoolSetAutostart, /* 0.4.0 */
      .poolNumOfVolumes = storagePoolNumVolumes, /* 0.4.0 */
      .poolListVolumes = storagePoolListVolumes, /* 0.4.0 */
+    .poolListAllVolumes = storagePoolListAllVolumes, /* 0.10.0 */

s/0.10.0/0.10.2/ ... Hm looks like that you've got that right in your github repo already.


      .volLookupByName = storageVolumeLookupByName, /* 0.4.0 */
      .volLookupByKey = storageVolumeLookupByKey, /* 0.4.0 */


Looks good. ACK

Peter

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]