Ping? Christophe On Tue, Nov 06, 2012 at 01:41:01PM +0100, Christophe Fergeau wrote: > They are similar to g_warning/g_critical, but also log the last > libvirt error. They are meant to be called right after a libvirt > call failed, in other cases g_warning/g_critical are still to be > used. > --- > libvirt-glib/libvirt-glib-error.c | 34 +++++++++++++++++++++++ > libvirt-glib/libvirt-glib-error.h | 2 ++ > libvirt-glib/libvirt-glib.sym | 5 ++++ > libvirt-gobject/libvirt-gobject-connection.c | 4 +-- > libvirt-gobject/libvirt-gobject-domain-snapshot.c | 2 +- > libvirt-gobject/libvirt-gobject-domain.c | 14 ++-------- > libvirt-gobject/libvirt-gobject-interface.c | 2 +- > libvirt-gobject/libvirt-gobject-network-filter.c | 17 ++++-------- > libvirt-gobject/libvirt-gobject-network.c | 14 ++-------- > libvirt-gobject/libvirt-gobject-node-device.c | 4 +-- > libvirt-gobject/libvirt-gobject-secret.c | 11 ++------ > libvirt-gobject/libvirt-gobject-storage-pool.c | 17 +++--------- > libvirt-gobject/libvirt-gobject-storage-vol.c | 2 +- > libvirt-gobject/libvirt-gobject-stream.c | 2 +- > 14 files changed, 66 insertions(+), 64 deletions(-) > > diff --git a/libvirt-glib/libvirt-glib-error.c b/libvirt-glib/libvirt-glib-error.c > index 7356aed..5c97da4 100644 > --- a/libvirt-glib/libvirt-glib-error.c > +++ b/libvirt-glib/libvirt-glib-error.c > @@ -257,3 +257,37 @@ void gvir_set_error_valist(GError **error, > > g_free(message); > } > + > +static void > +gvir_log_valist(GLogLevelFlags level, const gchar *format, va_list args) > +{ > + gchar *message; > + virErrorPtr verr = virGetLastError(); > + > + message = g_strdup_vprintf(format, args); > + > + if (verr) > + g_log(G_LOG_DOMAIN, level, "%s: %s", message, verr->message); > + else > + g_log(G_LOG_DOMAIN, level, "%s", message); > + > + g_free(message); > +} > + > +void gvir_warning(const gchar *format, ...) > +{ > + va_list args; > + > + va_start(args, format); > + gvir_log_valist(G_LOG_LEVEL_WARNING, format, args); > + va_end(args); > +} > + > +void gvir_critical(const gchar *format, ...) > +{ > + va_list args; > + > + va_start(args, format); > + gvir_log_valist(G_LOG_LEVEL_CRITICAL, format, args); > + va_end(args); > +} > diff --git a/libvirt-glib/libvirt-glib-error.h b/libvirt-glib/libvirt-glib-error.h > index 9e44383..1421047 100644 > --- a/libvirt-glib/libvirt-glib-error.h > +++ b/libvirt-glib/libvirt-glib-error.h > @@ -59,6 +59,8 @@ void gvir_set_error_valist(GError **error, > const gchar *format, > va_list args); > > +void gvir_critical(const gchar *format, ...); > +void gvir_warning(const gchar *format, ...); > > G_END_DECLS > > diff --git a/libvirt-glib/libvirt-glib.sym b/libvirt-glib/libvirt-glib.sym > index 53b8907..d9ddb07 100644 > --- a/libvirt-glib/libvirt-glib.sym > +++ b/libvirt-glib/libvirt-glib.sym > @@ -15,4 +15,9 @@ LIBVIRT_GLIB_0.0.7 { > *; > }; > > +LIBVIRT_GLIB_0.1.4 { > + gvir_critical; > + gvir_warning; > +} LIBVIRT_GLIB_0.0.7; > + > # .... define new API here using predicted next version number .... > diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c > index 9628989..e6ccfd0 100644 > --- a/libvirt-gobject/libvirt-gobject-connection.c > +++ b/libvirt-gobject/libvirt-gobject-connection.c > @@ -273,7 +273,7 @@ static int domain_event_cb(virConnectPtr conn G_GNUC_UNUSED, > GVirConnectionPrivate *priv = gconn->priv; > > if (virDomainGetUUIDString(dom, uuid) < 0) { > - g_warning("Failed to get domain UUID on %p", dom); > + gvir_warning("Failed to get domain UUID on %p", dom); > return 0; > } > > @@ -463,7 +463,7 @@ gboolean gvir_connection_open(GVirConnection *conn, > } > > if (virConnectDomainEventRegister(priv->conn, domain_event_cb, conn, NULL) == -1) > - g_warning("Failed to register domain events, ignoring"); > + gvir_warning("Failed to register domain events, ignoring"); > > g_mutex_unlock(priv->lock); > > diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.c b/libvirt-gobject/libvirt-gobject-domain-snapshot.c > index 11a073c..ce60ea0 100644 > --- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c > +++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c > @@ -167,7 +167,7 @@ const gchar *gvir_domain_snapshot_get_name(GVirDomainSnapshot *snapshot) > const char *name; > > if (!(name = virDomainSnapshotGetName(priv->handle))) { > - g_warning("Failed to get domain_snapshot name on %p", priv->handle); > + gvir_warning("Failed to get domain_snapshot name on %p", priv->handle); > return NULL; > } > > diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c > index 8ade3ea..9d4e232 100644 > --- a/libvirt-gobject/libvirt-gobject-domain.c > +++ b/libvirt-gobject/libvirt-gobject-domain.c > @@ -135,16 +135,8 @@ static void gvir_domain_constructed(GObject *object) > G_OBJECT_CLASS(gvir_domain_parent_class)->constructed(object); > > /* xxx we may want to turn this into an initable */ > - if (virDomainGetUUIDString(priv->handle, priv->uuid) < 0) { > - virErrorPtr verr = virGetLastError(); > - if (verr) { > - g_warning("Failed to get domain UUID on %p: %s", > - priv->handle, verr->message); > - } else { > - g_warning("Failed to get domain UUID on %p", > - priv->handle); > - } > - } > + if (virDomainGetUUIDString(priv->handle, priv->uuid) < 0) > + gvir_warning("Failed to get domain UUID on %p", priv->handle); > } > > > @@ -292,7 +284,7 @@ const gchar *gvir_domain_get_name(GVirDomain *dom) > > priv = dom->priv; > if (!(name = virDomainGetName(priv->handle))) { > - g_warning("Failed to get domain name on %p", priv->handle); > + gvir_warning("Failed to get domain name on %p", priv->handle); > return NULL; > } > > diff --git a/libvirt-gobject/libvirt-gobject-interface.c b/libvirt-gobject/libvirt-gobject-interface.c > index ecabb41..4523100 100644 > --- a/libvirt-gobject/libvirt-gobject-interface.c > +++ b/libvirt-gobject/libvirt-gobject-interface.c > @@ -164,7 +164,7 @@ const gchar *gvir_interface_get_name(GVirInterface *iface) > g_return_val_if_fail(GVIR_IS_INTERFACE(iface), NULL); > > if (!(name = virInterfaceGetName(iface->priv->handle))) { > - g_warning("Failed to get interface name on %p", iface->priv->handle); > + gvir_warning("Failed to get interface name on %p", iface->priv->handle); > return NULL; > } > > diff --git a/libvirt-gobject/libvirt-gobject-network-filter.c b/libvirt-gobject/libvirt-gobject-network-filter.c > index 00b1ed2..54c1eeb 100644 > --- a/libvirt-gobject/libvirt-gobject-network-filter.c > +++ b/libvirt-gobject/libvirt-gobject-network-filter.c > @@ -118,16 +118,9 @@ static void gvir_network_filter_constructed(GObject *object) > G_OBJECT_CLASS(gvir_network_filter_parent_class)->constructed(object); > > /* xxx we may want to turn this into an initable */ > - if (virNWFilterGetUUIDString(priv->handle, priv->uuid) < 0) { > - virErrorPtr verr = virGetLastError(); > - if (verr) { > - g_warning("Failed to get network filter UUID on %p: %s", > - priv->handle, verr->message); > - } else { > - g_warning("Failed to get network filter UUID on %p", > - priv->handle); > - } > - } > + if (virNWFilterGetUUIDString(priv->handle, priv->uuid) < 0) > + gvir_warning("Failed to get network filter UUID on %p", > + priv->handle); > } > > > @@ -187,8 +180,8 @@ const gchar *gvir_network_filter_get_name(GVirNetworkFilter *filter) > g_return_val_if_fail(GVIR_IS_NETWORK_FILTER(filter), NULL); > > if (!(name = virNWFilterGetName(filter->priv->handle))) { > - g_warning("Failed to get network_filter name on %p", > - filter->priv->handle); > + gvir_warning("Failed to get network_filter name on %p", > + filter->priv->handle); > return NULL; > } > > diff --git a/libvirt-gobject/libvirt-gobject-network.c b/libvirt-gobject/libvirt-gobject-network.c > index 9625ece..0f17ecc 100644 > --- a/libvirt-gobject/libvirt-gobject-network.c > +++ b/libvirt-gobject/libvirt-gobject-network.c > @@ -117,16 +117,8 @@ static void gvir_network_constructed(GObject *object) > G_OBJECT_CLASS(gvir_network_parent_class)->constructed(object); > > /* xxx we may want to turn this into an initable */ > - if (virNetworkGetUUIDString(priv->handle, priv->uuid) < 0) { > - virErrorPtr verr = virGetLastError(); > - if (verr) { > - g_warning("Failed to get network UUID on %p: %s", > - priv->handle, verr->message); > - } else { > - g_warning("Failed to get network UUID on %p", > - priv->handle); > - } > - } > + if (virNetworkGetUUIDString(priv->handle, priv->uuid) < 0) > + gvir_warning("Failed to get network UUID on %p", priv->handle); > } > > static void gvir_network_class_init(GVirNetworkClass *klass) > @@ -185,7 +177,7 @@ const gchar *gvir_network_get_name(GVirNetwork *network) > g_return_val_if_fail(GVIR_IS_NETWORK(network), NULL); > > if (!(name = virNetworkGetName(network->priv->handle))) { > - g_warning("Failed to get network name on %p", network->priv->handle); > + gvir_warning("Failed to get network name on %p", network->priv->handle); > return NULL; > } > > diff --git a/libvirt-gobject/libvirt-gobject-node-device.c b/libvirt-gobject/libvirt-gobject-node-device.c > index eb314ed..781fc5d 100644 > --- a/libvirt-gobject/libvirt-gobject-node-device.c > +++ b/libvirt-gobject/libvirt-gobject-node-device.c > @@ -164,8 +164,8 @@ const gchar *gvir_node_device_get_name(GVirNodeDevice *device) > g_return_val_if_fail(GVIR_IS_NODE_DEVICE(device), NULL); > > if (!(name = virNodeDeviceGetName(device->priv->handle))) { > - g_warning("Failed to get node_device name on %p", > - device->priv->handle); > + gvir_warning("Failed to get node_device name on %p", > + device->priv->handle); > return NULL; > } > > diff --git a/libvirt-gobject/libvirt-gobject-secret.c b/libvirt-gobject/libvirt-gobject-secret.c > index 8bfee88..01b8ed1 100644 > --- a/libvirt-gobject/libvirt-gobject-secret.c > +++ b/libvirt-gobject/libvirt-gobject-secret.c > @@ -118,15 +118,8 @@ static void gvir_secret_constructed(GObject *object) > G_OBJECT_CLASS(gvir_secret_parent_class)->constructed(object); > > /* xxx we may want to turn this into an initable */ > - if (virSecretGetUUIDString(priv->handle, priv->uuid) < 0) { > - virErrorPtr verr = virGetLastError(); > - if (verr) { > - g_warning("Failed to get secret UUID on %p: %s", > - priv->handle, verr->message); > - } else { > - g_warning("Failed to get secret UUID on %p", priv->handle); > - } > - } > + if (virSecretGetUUIDString(priv->handle, priv->uuid) < 0) > + gvir_warning("Failed to get secret UUID on %p", priv->handle); > } > > > diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c > index a09e5a7..adcdda7 100644 > --- a/libvirt-gobject/libvirt-gobject-storage-pool.c > +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c > @@ -128,15 +128,8 @@ static void gvir_storage_pool_constructed(GObject *object) > G_OBJECT_CLASS(gvir_storage_pool_parent_class)->constructed(object); > > /* xxx we may want to turn this into an initable */ > - if (virStoragePoolGetUUIDString(priv->handle, priv->uuid) < 0) { > - virErrorPtr verr = virGetLastError(); > - if (verr) { > - g_warning("Failed to get storage pool UUID on %p: %s", > - priv->handle, verr->message); > - } else { > - g_warning("Failed to get storage pool UUID on %p", priv->handle); > - } > - } > + if (virStoragePoolGetUUIDString(priv->handle, priv->uuid) < 0) > + gvir_warning("Failed to get storage pool UUID on %p", priv->handle); > } > > > @@ -215,10 +208,8 @@ const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool) > > g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), NULL); > > - if (!(name = virStoragePoolGetName(pool->priv->handle))) { > - g_warning("Failed to get storage_pool name on %p", pool->priv->handle); > - return NULL; > - } > + if (!(name = virStoragePoolGetName(pool->priv->handle))) > + gvir_warning("Failed to get storage_pool name on %p", pool->priv->handle); > > return name; > } > diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c > index 9256445..c7ebb45 100644 > --- a/libvirt-gobject/libvirt-gobject-storage-vol.c > +++ b/libvirt-gobject/libvirt-gobject-storage-vol.c > @@ -200,7 +200,7 @@ const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol) > g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), NULL); > > if (!(name = virStorageVolGetName(vol->priv->handle))) { > - g_warning("Failed to get storage_vol name on %p", vol->priv->handle); > + gvir_warning("Failed to get storage_vol name on %p", vol->priv->handle); > return NULL; > } > > diff --git a/libvirt-gobject/libvirt-gobject-stream.c b/libvirt-gobject/libvirt-gobject-stream.c > index fa1a32c..f0e43d0 100644 > --- a/libvirt-gobject/libvirt-gobject-stream.c > +++ b/libvirt-gobject/libvirt-gobject-stream.c > @@ -218,7 +218,7 @@ static void gvir_stream_finalize(GObject *object) > gvir_stream_update_events(self); > > if (virStreamFinish(priv->handle) < 0) > - g_critical("cannot finish stream"); > + gvir_critical("cannot finish stream"); > > virStreamFree(priv->handle); > } > -- > 1.7.12.1 > > -- > libvir-list mailing list > libvir-list@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/libvir-list
Attachment:
pgp7TA4Wi8Acf.pgp
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list