[libvirt] [PATCH 03/49] list: Define new API virStorageListALlStoragePools

Osier Yang jyang at redhat.com
Fri Jul 20 14:24:53 UTC 2012


This introduces a new API to list the storage pool objects,
4 groups of flags are provided to filter the returned pools:

  * Active or not

  * Autostarting or not

  * Persistent or not

  * And the pool type.

include/libvirt/libvirt.h.in: New enum virConnectListAllStoragePoolFlags;
                              Declare the API.
python/generator.py: Skip the generating
src/driver.h: (virDrvConnectListAllStoragePools)
src/libvirt.c: Implementation for the API.
src/libvirt_public.syms: Export the symbol.
---
 include/libvirt/libvirt.h.in |   32 ++++++++++++++
 python/generator.py          |    5 +-
 src/driver.h                 |    5 ++
 src/libvirt.c                |   93 +++++++++++++++++++++++++++++++++++++++---
 src/libvirt_public.syms      |    5 ++
 5 files changed, 132 insertions(+), 8 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index e34438c..c7e810e 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2471,6 +2471,38 @@ int                     virConnectListDefinedStoragePools(virConnectPtr conn,
                                                           int maxnames);
 
 /*
+ * virConnectListAllStoragePoolsFlags:
+ *
+ * Flags used to filter the returned pools. Flags in each group
+ * are exclusive attribute for a pool.
+ */
+typedef enum {
+    VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE      = 1 << 0,
+    VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE        = 1 << 1,
+
+    VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT    = 1 << 2,
+    VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT     = 1 << 3,
+
+    VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART     = 1 << 4,
+    VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART  = 1 << 5,
+
+    /* List pools by type */
+    VIR_CONNECT_LIST_STORAGE_POOLS_DIR           = 1 << 6,
+    VIR_CONNECT_LIST_STORAGE_POOLS_FS            = 1 << 7,
+    VIR_CONNECT_LIST_STORAGE_POOLS_NETFS         = 1 << 8,
+    VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL       = 1 << 9,
+    VIR_CONNECT_LIST_STORAGE_POOLS_DISK          = 1 << 10,
+    VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI         = 1 << 11,
+    VIR_CONNECT_LIST_STORAGE_POOLS_SCSI          = 1 << 12,
+    VIR_CONNECT_LIST_STORAGE_POOLS_MPATH         = 1 << 13,
+    VIR_CONNECT_LIST_STORAGE_POOLS_RBD           = 1 << 14,
+    VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG      = 1 << 15,
+} virConnectListAllStoragePoolsFlags;
+
+int                     virConnectListAllStoragePools(virConnectPtr conn,
+                                                      virStoragePoolPtr **pools,
+                                                      unsigned int flags);
+/*
  * Query a host for storage pools of a particular type
  */
 char *                  virConnectFindStoragePoolSources(virConnectPtr conn,
diff --git a/python/generator.py b/python/generator.py
index 2dada6e..5934040 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -337,7 +337,7 @@ foreign_encoding_args = (
 #
 #######################################################################
 
-# Class methods which are written by hand in libvir.c but the Python-level
+# Class methods which are written by hand in libvirt.c but the Python-level
 # code is still automatically generated (so they are not in skip_function()).
 skip_impl = (
     'virConnectGetVersion',
@@ -453,9 +453,10 @@ skip_function = (
     'virConnectDomainEventDeregisterAny', # overridden in virConnect.py
     'virSaveLastError', # We have our own python error wrapper
     'virFreeError', # Only needed if we use virSaveLastError
-    'virConnectListAllDomains', #overridden in virConnect.py
+    'virConnectListAllDomains', # overridden in virConnect.py
     'virDomainListAllSnapshots', # overridden in virDomain.py
     'virDomainSnapshotListAllChildren', # overridden in virDomainSnapshot.py
+    'virConnectListAllStoragePools', # overridden in virConnect.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 b3c1740..7e3e8a1 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1225,6 +1225,10 @@ typedef int
     (*virDrvConnectListDefinedStoragePools)  (virConnectPtr conn,
                                               char **const names,
                                               int maxnames);
+typedef int
+    (*virDrvConnectListAllStoragePools)      (virConnectPtr conn,
+                                              virStoragePoolPtr **pools,
+                                              unsigned int flags);
 typedef char *
     (*virDrvConnectFindStoragePoolSources)   (virConnectPtr conn,
                                               const char *type,
@@ -1369,6 +1373,7 @@ struct _virStorageDriver {
     virDrvConnectListStoragePools           listPools;
     virDrvConnectNumOfDefinedStoragePools   numOfDefinedPools;
     virDrvConnectListDefinedStoragePools    listDefinedPools;
+    virDrvConnectListAllStoragePools        listAllPools;
     virDrvConnectFindStoragePoolSources     findPoolSources;
     virDrvStoragePoolLookupByName           poolLookupByName;
     virDrvStoragePoolLookupByUUID           poolLookupByUUID;
diff --git a/src/libvirt.c b/src/libvirt.c
index df78e8a..541b1c3 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -11215,6 +11215,83 @@ virStoragePoolGetConnect (virStoragePoolPtr pool)
 }
 
 /**
+ * virConnectListAllStoragePools:
+ * @conn: Pointer to the hypervisor connection.
+ * @pools: Pointer to a variable to store the array containing storage pool
+ *         objects or NULL if the list is not required (just returns number
+ *         of pools).
+ * @flags: bitwise-OR of virConnectListAllStoragePoolsFlags.
+ *
+ * Collect the list of storage pools, and allocate an array to store those
+ * objects. This API solves the race inherent between virConnectListStoragePools
+ * and virConnectListDefinedStoragePools.
+ *
+ * By default, this API covers all storage pools; it is also possible
+ * to return the filtered objects with flags. Filters are provided in groups,
+ * where each group contains bits that describe mutually exclusive attributes
+ * of a storage pool.
+ *
+ * The first group of @flags is VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE and
+ * VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE to fitler the pools by state.
+ *
+ * The second group of @flags is VIR_CONNECT_LIST_STORAGE_POOLS_PERSITENT
+ * and VIR_CONNECT_LIST_STORAGE_POOLS_TRANSICIENT, to filter the pools by
+ * whether they have persistent config or not.
+ *
+ * The third group of @flags is VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART
+ * and VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART, to filter the pools by
+ * whether they are marked as autostart or not.
+ *
+ * The last group of @flags is provided to filter the pools by the types,
+ * the flags include:
+ * VIR_CONNECT_LIST_STORAGE_POOLS_DIR, VIR_CONNECT_LIST_STORAGE_POOLS_FS,
+ * VIR_CONNECT_LIST_STORAGE_POOLS_NETFS, VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL,
+ * VIR_CONNECT_LIST_STORAGE_POOLS_DISK, VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI,
+ * VIR_CONNECT_LIST_STORAGE_POOLS_SCSI, VIR_CONNECT_LIST_STORAGE_POOLS_MPATH,
+ * VIR_CONNECT_LIST_STORAGE_POOLS_RBD, and VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG.
+ *
+ * Returns the number of storage pools found or -1 and sets @pools to
+ * NULL in case of error.  On success, the array stored into @pools 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 virStoragePoolFree() on each array element, then calling
+ * free() on @pools.
+ */
+int
+virConnectListAllStoragePools(virConnectPtr conn,
+                              virStoragePoolPtr **pools,
+                              unsigned int flags)
+{
+    VIR_DEBUG("conn=%p, pools=%p, flags=%x", conn, pools, flags);
+
+    virResetLastError();
+
+    if (pools)
+        *pools = NULL;
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (conn->storageDriver &&
+        conn->storageDriver->listAllPools) {
+        int ret;
+        ret = conn->storageDriver->listAllPools(conn, pools, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
+
+/**
  * virConnectNumOfStoragePools:
  * @conn: pointer to hypervisor connection
  *
@@ -11256,9 +11333,11 @@ error:
  * @names: array of char * to fill with pool names (allocated by caller)
  * @maxnames: size of the names array
  *
- * Provides the list of names of active storage pools
- * upto maxnames. If there are more than maxnames, the
- * remaining names will be silently ignored.
+ * Provides the list of names of active storage pools upto maxnames.
+ * If there are more than maxnames, the remaining names will be silently
+ * ignored.
+ *
+ * For more control over the results, see virConnectListAllStoragePools().
  *
  * Returns 0 on success, -1 on error
  */
@@ -11339,9 +11418,11 @@ error:
  * @names: array of char * to fill with pool names (allocated by caller)
  * @maxnames: size of the names array
  *
- * Provides the list of names of inactive storage pools
- * upto maxnames. If there are more than maxnames, the
- * remaining names will be silently ignored.
+ * Provides the list of names of inactive storage pools upto maxnames.
+ * If there are more than maxnames, the remaining names will be silently
+ * ignored.
+ *
+ * For more control over the results, see virConnectListAllStoragePools().
  *
  * Returns 0 on success, -1 on error
  */
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 2913a81..693a390 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -544,4 +544,9 @@ LIBVIRT_0.9.13 {
         virDomainSnapshotRef;
 } LIBVIRT_0.9.11;
 
+LIBVIRT_0.9.14 {
+    global:
+        virConnectListAllStoragePools;
+} LIBVIRT_0.9.13;
+
 # .... define new API here using predicted next version number ....
-- 
1.7.7.3




More information about the libvir-list mailing list