[PATCH 14/48] list: Define new API virStoragePoolListAllVolumes

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

 



Simply returns the storage volume objects. No supported filter
flags.

include/libvirt/libvirt.h.in: Declare the API
python/generator.py: Skip the function for generating. virStoragePool.py
                     will be added in later patch.
src/driver.h: virDrvStoragePoolListVolumesFlags
src/libvirt.c: Implementation for the API.
src/libvirt_public.syms: Export the symbol to public
---
 include/libvirt/libvirt.h.in |    3 ++
 python/generator.py          |    1 +
 src/driver.h                 |    6 ++++-
 src/libvirt.c                |   50 ++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |    1 +
 5 files changed, 60 insertions(+), 1 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index e8f38ab..2d28fc0 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2624,6 +2624,9 @@ int                     virStoragePoolNumOfVolumes      (virStoragePoolPtr pool)
 int                     virStoragePoolListVolumes       (virStoragePoolPtr pool,
                                                          char **const names,
                                                          int maxnames);
+int                     virStoragePoolListAllVolumes    (virStoragePoolPtr pool,
+                                                         virStorageVolPtr **vols,
+                                                         unsigned int flags);
 
 virConnectPtr           virStorageVolGetConnect         (virStorageVolPtr vol);
 
diff --git a/python/generator.py b/python/generator.py
index 6fab68c..554ce26 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -459,6 +459,7 @@ skip_function = (
     'virDomainListAllSnapshots', # overridden in virDomain.py
     'virDomainSnapshotListAllChildren', # overridden in virDomainSnapshot.py
     'virConnectListAllStoragePools', # overridden in virConnect.py
+    'virStoragePoolListAllVolumes', # overridden in virStoragePool.py
 
     'virStreamRecvAll', # Pure python libvirt-override-virStream.py
     'virStreamSendAll', # Pure python libvirt-override-virStream.py
diff --git a/src/driver.h b/src/driver.h
index 3c1ae3b..b4273c1 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1291,7 +1291,10 @@ typedef int
     (*virDrvStoragePoolListVolumes)          (virStoragePoolPtr pool,
                                               char **const names,
                                               int maxnames);
-
+typedef int
+    (*virDrvStoragePoolListAllVolumes)       (virStoragePoolPtr pool,
+                                              virStorageVolPtr **vols,
+                                              unsigned int flags);
 
 typedef virStorageVolPtr
     (*virDrvStorageVolLookupByName)          (virStoragePoolPtr pool,
@@ -1399,6 +1402,7 @@ struct _virStorageDriver {
     virDrvStoragePoolSetAutostart           poolSetAutostart;
     virDrvStoragePoolNumOfVolumes           poolNumOfVolumes;
     virDrvStoragePoolListVolumes            poolListVolumes;
+    virDrvStoragePoolListAllVolumes         poolListAllVolumes;
 
     virDrvStorageVolLookupByName            volLookupByName;
     virDrvStorageVolLookupByKey             volLookupByKey;
diff --git a/src/libvirt.c b/src/libvirt.c
index ad665e4..ce2cdb6 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -12419,6 +12419,54 @@ error:
     return -1;
 }
 
+/**
+ * virStoragePoolListAllVolumes:
+ * @pool: Pointer to storage pool
+ * @vols: Pointer to a variable to store the array containing storage volume
+ *        objects or NULL if the list is not required (just returns number
+ *        of volumes).
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Collect the list of storage volumes, and allocate an array to store those
+ * objects.
+ *
+ * Returns the number of storage volumes found or -1 and sets @vols to
+ * NULL in case of error.  On success, the array stored into @vols is
+ * guaranteed to have an extra allocated element set to NULL but not included
+ * in the return count, to make iteration easier.  The caller is responsible
+ * for calling virStorageVolFree() on each array element, then calling
+ * free() on @vols.
+ */
+int
+virStoragePoolListAllVolumes(virStoragePoolPtr pool,
+                             virStorageVolPtr **vols,
+                             unsigned int flags)
+{
+    VIR_DEBUG("pool=%p, vols=%p, flags=%x", pool, vols, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_STORAGE_POOL(pool)) {
+        virLibConnError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (pool->conn->storageDriver &&
+        pool->conn->storageDriver->poolListAllVolumes) {
+        int ret;
+        ret = pool->conn->storageDriver->poolListAllVolumes(pool, vols, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(pool->conn);
+    return -1;
+}
 
 /**
  * virStoragePoolNumOfVolumes:
@@ -12466,6 +12514,8 @@ error:
  * Fetch list of storage volume names, limiting to
  * at most maxnames.
  *
+ * To list the volume objects directly, see virStoragePoolListAllVolumes().
+ *
  * Returns the number of names fetched, or -1 on error
  */
 int
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index e9c9a31..fa6137a 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -550,6 +550,7 @@ LIBVIRT_0.10.0 {
         virConnectRegisterCloseCallback;
         virConnectUnregisterCloseCallback;
         virConnectListAllStoragePools;
+        virStoragePoolListAllVolumes;
 } LIBVIRT_0.9.13;
 
 # .... define new API here using predicted next version number ....
-- 
1.7.7.3

--
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]