[libvirt] [PATCH 1/6] list: Define new API virStoragePoolListAllVolumes

Osier Yang jyang at redhat.com
Tue Sep 4 15:32:53 UTC 2012


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 0c52271..58cd6ff 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2654,6 +2654,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 261efe0..276b4ff 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -461,6 +461,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 342f6b5..1bdfd29 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1311,7 +1311,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,
@@ -1419,6 +1422,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 4e4f96b..700dbef 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -12596,6 +12596,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:
@@ -12643,6 +12691,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 f6068b4..53db37f 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -557,6 +557,7 @@ LIBVIRT_0.10.0 {
 LIBVIRT_0.10.2 {
     global:
         virConnectListAllStoragePools;
+        virStoragePoolListAllVolumes;
 } LIBVIRT_0.10.0;
 
 # .... define new API here using predicted next version number ....
-- 
1.7.7.3




More information about the libvir-list mailing list