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

[libvirt] [libvirt-glib 1/2] Wrap storage pool info API



From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>

---
 libvirt-gobject/libvirt-gobject-storage-pool.c |   44 ++++++++++++++++++++++++
 libvirt-gobject/libvirt-gobject-storage-pool.h |   21 +++++++++++
 libvirt-gobject/libvirt-gobject.sym            |    2 +
 3 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c
index da8ada5..3c30a3d 100644
--- a/libvirt-gobject/libvirt-gobject-storage-pool.c
+++ b/libvirt-gobject/libvirt-gobject-storage-pool.c
@@ -189,6 +189,21 @@ gvir_storage_pool_handle_free(GVirStoragePoolHandle *src)
 G_DEFINE_BOXED_TYPE(GVirStoragePoolHandle, gvir_storage_pool_handle,
                     gvir_storage_pool_handle_copy, gvir_storage_pool_handle_free)
 
+static GVirStoragePoolInfo *
+gvir_storage_pool_info_copy(GVirStoragePoolInfo *info)
+{
+    return g_slice_dup(GVirStoragePoolInfo, info);
+}
+
+static void
+gvir_storage_pool_info_free(GVirStoragePoolInfo *info)
+{
+    g_slice_free(GVirStoragePoolInfo, info);
+}
+
+G_DEFINE_BOXED_TYPE(GVirStoragePoolInfo, gvir_storage_pool_info,
+                    gvir_storage_pool_info_copy, gvir_storage_pool_info_free)
+
 const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool)
 {
     GVirStoragePoolPrivate *priv = pool->priv;
@@ -237,6 +252,35 @@ GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool,
     return conf;
 }
 
+/**
+ * gvir_storage_pool_get_info:
+ * @pool: the storage_pool
+ * Returns: (transfer full): the info
+ */
+GVirStoragePoolInfo *gvir_storage_pool_get_info(GVirStoragePool *pool,
+                                                GError **err)
+{
+    GVirStoragePoolPrivate *priv = pool->priv;
+    virStoragePoolInfo info;
+    GVirStoragePoolInfo *ret;
+
+    if (virStoragePoolGetInfo(priv->handle, &info) < 0) {
+        if (err)
+            *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR,
+                                          0,
+                                          "Unable to get storage pool info");
+        return NULL;
+    }
+
+    ret = g_slice_new(GVirStoragePoolInfo);
+    ret->state = info.state;
+    ret->capacity = info.capacity;
+    ret->allocation = info.allocation;
+    ret->available = info.available;
+
+    return ret;
+}
+
 typedef gint (* CountFunction) (virStoragePoolPtr vpool);
 typedef gint (* ListFunction) (virStoragePoolPtr vpool, gchar **lst, gint max);
 
diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.h b/libvirt-gobject/libvirt-gobject-storage-pool.h
index d95bb19..436238b 100644
--- a/libvirt-gobject/libvirt-gobject-storage-pool.h
+++ b/libvirt-gobject/libvirt-gobject-storage-pool.h
@@ -36,6 +36,7 @@ G_BEGIN_DECLS
 #define GVIR_IS_STORAGE_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_STORAGE_POOL))
 #define GVIR_STORAGE_POOL_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_STORAGE_POOL, GVirStoragePoolClass))
 
+#define GVIR_TYPE_STORAGE_POOL_INFO       (gvir_storage_pool_info_get_type())
 #define GVIR_TYPE_STORAGE_POOL_HANDLE     (gvir_storage_pool_handle_get_type())
 
 typedef struct _GVirStoragePool GVirStoragePool;
@@ -58,8 +59,25 @@ struct _GVirStoragePoolClass
     gpointer padding[20];
 };
 
+typedef enum {
+    GVIR_STORAGE_POOL_STATE_INACTIVE     = 0, /* Not running */
+    GVIR_STORAGE_POOL_STATE_BUILDING     = 1, /* Initializing pool, not available */
+    GVIR_STORAGE_POOL_STATE_RUNNING      = 2, /* Running normally */
+    GVIR_STORAGE_POOL_STATE_DEGRADED     = 3, /* Running degraded */
+    GVIR_STORAGE_POOL_STATE_INACCESSIBLE = 4, /* Running, but not accessible */
+} GVirStoragePoolState;
+
+typedef struct _GVirStoragePoolInfo GVirStoragePoolInfo;
+struct _GVirStoragePoolInfo
+{
+    GVirStoragePoolState state; /* the state */
+    guint64 capacity;           /* Logical size bytes */
+    guint64 allocation;         /* Current allocation bytes */
+    guint16 available;          /* Remaining free space bytes */
+};
 
 GType gvir_storage_pool_get_type(void);
+GType gvir_storage_pool_info_get_type(void);
 GType gvir_storage_pool_handle_get_type(void);
 
 const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool);
@@ -69,6 +87,9 @@ GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool,
                                                     guint flags,
                                                     GError **err);
 
+GVirStoragePoolInfo *gvir_storage_pool_get_info(GVirStoragePool *pool,
+                                                GError **err);
+
 gboolean gvir_storage_pool_refresh(GVirStoragePool *pool,
                                    GCancellable *cancellable,
                                    GError **err);
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index 61a3a31..55c515b 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -91,10 +91,12 @@ LIBVIRT_GOBJECT_0.0.1 {
 	gvir_secret_get_config;
 
 	gvir_storage_pool_get_type;
+	gvir_storage_pool_info_get_type;
 	gvir_storage_pool_handle_get_type;
 	gvir_storage_pool_get_name;
 	gvir_storage_pool_get_uuid;
 	gvir_storage_pool_get_config;
+	gvir_storage_pool_get_info;
 	gvir_storage_pool_refresh;
 	gvir_storage_pool_refresh_async;
 	gvir_storage_pool_refresh_finish;
-- 
1.7.7.3


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