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

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> API to create new storage pools. --- libvirt-gobject/libvirt-gobject-connection.c | 40 ++++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 6 ++++ libvirt-gobject/libvirt-gobject.sym | 1 + 3 files changed, 47 insertions(+), 0 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 30b7792..43a262a 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1201,3 +1201,43 @@ 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; + } + + 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

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> --- libvirt-gobject/libvirt-gobject-storage-pool.c | 44 ++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-storage-pool.h | 8 ++++ libvirt-gobject/libvirt-gobject.sym | 2 + 3 files changed, 54 insertions(+), 0 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c index bd3be94..a1c7c6b 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.c +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c @@ -518,3 +518,47 @@ GVirStorageVol *gvir_storage_pool_create_volume return g_object_ref(volume); } + +/** + * gvir_storage_pool_build: + * @pool: the storage pool to build + * @flags: the flags + * @err: return location for any #GError + * + * Return value: #True on success, #False otherwise. + */ +gboolean gvir_storage_pool_build (GVirStoragePool *pool, + guint64 flags G_GNUC_UNUSED, + GError **err) +{ + if (virStoragePoolBuild(pool->priv->handle, 0)) { + *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, + 0, + "Failed to build storage pool"); + return FALSE; + } + + return TRUE; +} + +/** + * gvir_storage_pool_start: + * @pool: the storage pool to start + * @flags: the flags + * @err: return location for any #GError + * + * Return value: #True on success, #False otherwise. + */ +gboolean gvir_storage_pool_start (GVirStoragePool *pool, + guint64 flags G_GNUC_UNUSED, + GError **err) +{ + if (virStoragePoolCreate(pool->priv->handle, 0)) { + *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, + 0, + "Failed to start storage pool"); + return FALSE; + } + + return TRUE; +} diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.h b/libvirt-gobject/libvirt-gobject-storage-pool.h index 620f888..2e9cca2 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.h +++ b/libvirt-gobject/libvirt-gobject-storage-pool.h @@ -88,6 +88,14 @@ GVirStorageVol *gvir_storage_pool_create_volume GVirConfigStorageVol *conf, GError **err); +gboolean gvir_storage_pool_build (GVirStoragePool *pool, + guint64 flags G_GNUC_UNUSED, + GError **err); + +gboolean gvir_storage_pool_start (GVirStoragePool *pool, + guint64 flags G_GNUC_UNUSED, + GError **err); + G_END_DECLS #endif /* __LIBVIRT_GOBJECT_STORAGE_POOL_H__ */ diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index f1fa78b..4b1b84c 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -89,6 +89,8 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_storage_pool_get_volumes; gvir_storage_pool_get_volume; gvir_storage_pool_create_volume; + gvir_storage_pool_build; + gvir_storage_pool_start; gvir_storage_vol_get_type; gvir_storage_vol_handle_get_type; -- 1.7.6.4

On Wed, Oct 26, 2011 at 01:17:37AM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
--- libvirt-gobject/libvirt-gobject-storage-pool.c | 44 ++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-storage-pool.h | 8 ++++ libvirt-gobject/libvirt-gobject.sym | 2 + 3 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c index bd3be94..a1c7c6b 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.c +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c @@ -518,3 +518,47 @@ GVirStorageVol *gvir_storage_pool_create_volume
return g_object_ref(volume); } + +/** + * gvir_storage_pool_build: + * @pool: the storage pool to build + * @flags: the flags + * @err: return location for any #GError + * + * Return value: #True on success, #False otherwise. + */ +gboolean gvir_storage_pool_build (GVirStoragePool *pool, + guint64 flags G_GNUC_UNUSED, + GError **err) +{ + if (virStoragePoolBuild(pool->priv->handle, 0)) { + *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, + 0, + "Failed to build storage pool"); + return FALSE; + } + + return TRUE; +} + +/** + * gvir_storage_pool_start: + * @pool: the storage pool to start + * @flags: the flags + * @err: return location for any #GError + * + * Return value: #True on success, #False otherwise. + */ +gboolean gvir_storage_pool_start (GVirStoragePool *pool, + guint64 flags G_GNUC_UNUSED, + GError **err) +{ + if (virStoragePoolCreate(pool->priv->handle, 0)) { + *err = gvir_error_new_literal(GVIR_STORAGE_POOL_ERROR, + 0, + "Failed to start storage pool"); + return FALSE; + } + + return TRUE; +}
You've got the flags parameter here, but for some reason you've not passed it down to the libvirt API calls :-)
diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.h b/libvirt-gobject/libvirt-gobject-storage-pool.h index 620f888..2e9cca2 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.h +++ b/libvirt-gobject/libvirt-gobject-storage-pool.h @@ -88,6 +88,14 @@ GVirStorageVol *gvir_storage_pool_create_volume GVirConfigStorageVol *conf, GError **err);
+gboolean gvir_storage_pool_build (GVirStoragePool *pool, + guint64 flags G_GNUC_UNUSED, + GError **err); + +gboolean gvir_storage_pool_start (GVirStoragePool *pool, + guint64 flags G_GNUC_UNUSED, + GError **err);
The header files shouldn't have G_GNUC_UNUSED - only the method impl wants that. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Wed, Oct 26, 2011 at 01:17:36AM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
API to create new storage pools. --- libvirt-gobject/libvirt-gobject-connection.c | 40 ++++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 6 ++++ libvirt-gobject/libvirt-gobject.sym | 1 + 3 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 30b7792..43a262a 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1201,3 +1201,43 @@ 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; + } + + 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); +
ACK, but please add the 'unsigned int flags' parameter to this, rather than hardcoding 0. Through bitter experiance, all libvirt APIs now strive to have an 'unsigned int flags' parameter, because we invariably need to invent flags at some time or another. I wish GObject introspection supported default values, so we could annotate all the flags parameters as taking a '0' default value to avoid apps needing to set it all the time.... The annotations are all defined, but the girscanner ignores them :-( Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Wed, Oct 26, 2011 at 6:32 PM, Daniel P. Berrange <berrange@redhat.com> wrote:
On Wed, Oct 26, 2011 at 01:17:36AM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
API to create new storage pools.
ACK, but please add the 'unsigned int flags' parameter to this, rather than hardcoding 0. Through bitter experiance, all libvirt APIs now strive to have an 'unsigned int flags' parameter, because we invariably need to invent flags at some time or another.
Oh, I forgot to fix that. Thanks for reminding..
I wish GObject introspection supported default values, so we could annotate all the flags parameters as taking a '0' default value to avoid apps needing to set it all the time.... The annotations are all defined, but the girscanner ignores them :-(
Yeah, Vala has supported that for a long time and I intend to fix this for Vala bindings at least sometimes soon. -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Wed, Oct 26, 2011 at 07:21:57PM +0300, Zeeshan Ali (Khattak) wrote:
On Wed, Oct 26, 2011 at 6:32 PM, Daniel P. Berrange <berrange@redhat.com> wrote:
On Wed, Oct 26, 2011 at 01:17:36AM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
API to create new storage pools.
ACK, but please add the 'unsigned int flags' parameter to this, rather than hardcoding 0. Through bitter experiance, all libvirt APIs now strive to have an 'unsigned int flags' parameter, because we invariably need to invent flags at some time or another.
Oh, I forgot to fix that. Thanks for reminding..
I wish GObject introspection supported default values, so we could annotate all the flags parameters as taking a '0' default value to avoid apps needing to set it all the time.... The annotations are all defined, but the girscanner ignores them :-(
Yeah, Vala has supported that for a long time and I intend to fix this for Vala bindings at least sometimes soon.
I knew I had seen a BZ about it somewhre before, and finally found it again: https://bugzilla.gnome.org/show_bug.cgi?id=558620 Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (2)
-
Daniel P. Berrange
-
Zeeshan Ali (Khattak)