[libvirt] [libosinfo 1/2] Set GError even if libvirt error is unknown

From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org> --- libvirt-glib/libvirt-glib-error.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/libvirt-glib/libvirt-glib-error.c b/libvirt-glib/libvirt-glib-error.c index f59b464..0319687 100644 --- a/libvirt-glib/libvirt-glib-error.c +++ b/libvirt-glib/libvirt-glib-error.c @@ -80,7 +80,10 @@ GError *gvir_error_new_literal(GQuark domain, virErrorPtr verr = virGetLastError(); if (!verr) - return NULL; + return g_error_new(domain, + code, + "%s", + message); if (message) return g_error_new(domain, -- 1.7.6.4

From: "Zeeshan Ali (Khattak)" <zeeshanak@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

On Tue, Oct 25, 2011 at 10:56:56PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@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; + }
IMHO you don't really want to tie invocation of these three methods together, since it is quite typical to need to run them indepedantly. For example if you have an existing LVM volume group, you don't want to run build. 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 Tue, Oct 25, 2011 at 11:51 PM, Daniel P. Berrange <berrange@redhat.com> wrote:
On Tue, Oct 25, 2011 at 10:56:56PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
API to create new storage pools. This function also activates and builds the storage pool for you.
IMHO you don't really want to tie invocation of these three methods together, since it is quite typical to need to run them indepedantly.
Correction patches sent! AFAIK we'd want async version of storage_pool_build()? What about the other two? -- Regards, Zeeshan Ali (Khattak) FSF member#5124

On Wed, Oct 26, 2011 at 01:21:35AM +0300, Zeeshan Ali (Khattak) wrote:
On Tue, Oct 25, 2011 at 11:51 PM, Daniel P. Berrange <berrange@redhat.com> wrote:
On Tue, Oct 25, 2011 at 10:56:56PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
API to create new storage pools. This function also activates and builds the storage pool for you.
IMHO you don't really want to tie invocation of these three methods together, since it is quite typical to need to run them indepedantly.
Correction patches sent! AFAIK we'd want async version of storage_pool_build()? What about the other two?
Define is fast, Build and Create are slow. So only the latter two need async versions 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 Tue, Oct 25, 2011 at 10:56:55PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
--- libvirt-glib/libvirt-glib-error.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/libvirt-glib/libvirt-glib-error.c b/libvirt-glib/libvirt-glib-error.c index f59b464..0319687 100644 --- a/libvirt-glib/libvirt-glib-error.c +++ b/libvirt-glib/libvirt-glib-error.c @@ -80,7 +80,10 @@ GError *gvir_error_new_literal(GQuark domain, virErrorPtr verr = virGetLastError();
if (!verr) - return NULL; + return g_error_new(domain, + code, + "%s", + message);
if (message) return g_error_new(domain,
ACK 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)