[libvirt] [libosinfo 2/2] Add gvir_connection_create_storage_pool()

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Tue Oct 25 19:56:56 UTC 2011


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

API to create new storage pools. This function also activates and builds
the storage pool for you.
---
 libvirt-gobject/libvirt-gobject-connection.c |   54 ++++++++++++++++++++++++++
 libvirt-gobject/libvirt-gobject-connection.h |    6 +++
 libvirt-gobject/libvirt-gobject.sym          |    1 +
 3 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index 30b7792..921c53c 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -1201,3 +1201,57 @@ GVirDomain *gvir_connection_create_domain(GVirConnection *conn,
 
     return g_object_ref(domain);
 }
+
+/**
+ * gvir_connection_create_storage_pool:
+ * @conn: the connection on which to create the pool
+ * @conf: the configuration for the new storage pool
+ * Returns: (transfer full): the newly created storage pool
+ */
+GVirStoragePool *gvir_connection_create_storage_pool
+                                (GVirConnection *conn,
+                                 GVirConfigStoragePool *conf,
+                                 GError **err) {
+    const gchar *xml;
+    virStoragePoolPtr handle;
+    GVirConnectionPrivate *priv = conn->priv;
+
+    xml = gvir_config_object_get_doc(GVIR_CONFIG_OBJECT(conf));
+
+    g_return_val_if_fail(xml != NULL, NULL);
+
+    if (!(handle = virStoragePoolDefineXML(priv->conn, xml, 0))) {
+        *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR,
+                                      0,
+                                      "Failed to create storage pool");
+        return NULL;
+    }
+
+    if (virStoragePoolBuild(handle, 0)) {
+        *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR,
+                                      0,
+                                      "Failed to build storage pool");
+        return NULL;
+    }
+
+    if (virStoragePoolCreate(handle, 0)) {
+        *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR,
+                                      0,
+                                      "Failed to start storage pool");
+        return NULL;
+    }
+
+    GVirStoragePool *pool;
+
+    pool = GVIR_STORAGE_POOL(g_object_new(GVIR_TYPE_STORAGE_POOL,
+                                          "handle", handle,
+                                          NULL));
+
+    g_mutex_lock(priv->lock);
+    g_hash_table_insert(priv->pools,
+                        (gpointer)gvir_storage_pool_get_uuid(pool),
+                        pool);
+    g_mutex_unlock(priv->lock);
+
+    return g_object_ref(pool);
+}
diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h
index 8c1d1a4..3a8d888 100644
--- a/libvirt-gobject/libvirt-gobject-connection.h
+++ b/libvirt-gobject/libvirt-gobject-connection.h
@@ -160,6 +160,12 @@ GVirStoragePool *gvir_connection_get_storage_pool(GVirConnection *conn,
 GVirStoragePool *gvir_connection_find_storage_pool_by_name(GVirConnection *conn,
                                                            const gchar *name);
 
+GVirStoragePool *gvir_connection_create_storage_pool
+                                (GVirConnection *conn,
+                                 GVirConfigStoragePool *conf,
+                                 GError **err);
+
+
 GVirStream *gvir_connection_get_stream(GVirConnection *conn,
                                        gint flags);
 
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index e019e22..f1fa78b 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -27,6 +27,7 @@ LIBVIRT_GOBJECT_0.0.1 {
 	gvir_connection_find_domain_by_name;
 	gvir_connection_find_storage_pool_by_name;
 	gvir_connection_create_domain;
+	gvir_connection_create_storage_pool;
 
 	gvir_domain_get_type;
 	gvir_domain_handle_get_type;
-- 
1.7.6.4




More information about the libvir-list mailing list