[libvirt] [PATCH libvirt-glib 0/5] Misc fixes & enhancements

NB, this is an ABI changing series, to fix the bogus use of guint64 for flags parameters

From: "Daniel P. Berrange" <berrange@redhat.com> --- libvirt-gobject/Makefile.am | 8 +- libvirt-gobject/libvirt-gobject-output-stream.c | 240 +++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-output-stream.h | 68 +++++++ libvirt-gobject/libvirt-gobject-stream.c | 115 +++++++++++- libvirt-gobject/libvirt-gobject-stream.h | 27 ++- 5 files changed, 447 insertions(+), 11 deletions(-) create mode 100644 libvirt-gobject/libvirt-gobject-output-stream.c create mode 100644 libvirt-gobject/libvirt-gobject-output-stream.h diff --git a/libvirt-gobject/Makefile.am b/libvirt-gobject/Makefile.am index 0eef9c8..ec7b454 100644 --- a/libvirt-gobject/Makefile.am +++ b/libvirt-gobject/Makefile.am @@ -45,8 +45,7 @@ GOBJECT_GENERATED_FILES = \ libvirt_gobject_1_0_ladir = $(includedir)/libvirt-gobject-1.0/libvirt-gobject libvirt_gobject_1_0_la_HEADERS = \ - $(GOBJECT_HEADER_FILES) \ - libvirt-gobject-input-stream.h + $(GOBJECT_HEADER_FILES) nodist_libvirt_gobject_1_0_la_HEADERS = \ libvirt-gobject-enums.h libvirt_gobject_1_0_la_SOURCES = \ @@ -54,7 +53,10 @@ libvirt_gobject_1_0_la_SOURCES = \ $(GOBJECT_SOURCE_FILES) \ libvirt-gobject-domain-device-private.h \ libvirt-gobject-compat.h \ - libvirt-gobject-input-stream.c + libvirt-gobject-input-stream.h \ + libvirt-gobject-input-stream.c \ + libvirt-gobject-output-stream.h \ + libvirt-gobject-output-stream.c nodist_libvirt_gobject_1_0_la_SOURCES = \ $(GOBJECT_GENERATED_FILES) libvirt_gobject_1_0_la_CFLAGS = \ diff --git a/libvirt-gobject/libvirt-gobject-output-stream.c b/libvirt-gobject/libvirt-gobject-output-stream.c new file mode 100644 index 0000000..30ee519 --- /dev/null +++ b/libvirt-gobject/libvirt-gobject-output-stream.c @@ -0,0 +1,240 @@ +/* + * libvirt-gobject-output-stream.h: libvirt gobject integration + * + * Copyright (C) 2011 Red Hat + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Daniel P. Berrange <berrange@redhat.com> + * Marc-André Lureau <marcandre.lureau@redhat.com> + */ + +#include <config.h> + +#include <libvirt/virterror.h> +#include <string.h> + +#include "libvirt-glib/libvirt-glib.h" +#include "libvirt-gobject/libvirt-gobject.h" +#include "libvirt-gobject-output-stream.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define gvir_output_stream_get_type _gvir_output_stream_get_type +G_DEFINE_TYPE(GVirOutputStream, gvir_output_stream, G_TYPE_OUTPUT_STREAM); + +enum +{ + PROP_0, + PROP_STREAM +}; + +struct _GVirOutputStreamPrivate +{ + GVirStream *stream; + + /* pending operation metadata */ + GSimpleAsyncResult *result; + GCancellable *cancellable; + const void * buffer; + gsize count; +}; + +static void gvir_output_stream_get_property(GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GVirOutputStream *stream = GVIR_OUTPUT_STREAM(object); + + switch (prop_id) { + case PROP_STREAM: + g_value_set_object(value, stream->priv->stream); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static void gvir_output_stream_set_property(GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GVirOutputStream *stream = GVIR_OUTPUT_STREAM(object); + + switch (prop_id) { + case PROP_STREAM: + stream->priv->stream = g_value_get_object(value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static void gvir_output_stream_finalize(GObject *object) +{ + GVirOutputStream *stream = GVIR_OUTPUT_STREAM(object); + + DEBUG("Finalize output stream GVirStream=%p", stream->priv->stream); + stream->priv->stream = NULL; // unowned + + if (G_OBJECT_CLASS(gvir_output_stream_parent_class)->finalize) + (*G_OBJECT_CLASS(gvir_output_stream_parent_class)->finalize)(object); +} + +static void +gvir_output_stream_write_ready(virStreamPtr st G_GNUC_UNUSED, + int events, + void *opaque) +{ + GVirOutputStream *stream = GVIR_OUTPUT_STREAM(opaque); + GVirOutputStreamPrivate *priv = stream->priv; + GSimpleAsyncResult *simple; + GError *error = NULL; + gssize result; + + g_return_if_fail(events & VIR_STREAM_EVENT_WRITABLE); + + result = gvir_stream_send(priv->stream, priv->buffer, priv->count, + priv->cancellable, &error); + + if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) { + g_warn_if_reached(); + return; + } + + simple = stream->priv->result; + stream->priv->result = NULL; + + if (result >= 0) + g_simple_async_result_set_op_res_gssize(simple, result); + + if (error) + g_simple_async_result_take_error(simple, error); + + if (priv->cancellable) { + g_object_unref(stream->priv->cancellable); + priv->cancellable = NULL; + } + + g_simple_async_result_complete(simple); + g_object_unref(simple); + + return; +} + +static void gvir_output_stream_write_async(GOutputStream *stream, + const void *buffer, + gsize count, + int io_priority G_GNUC_UNUSED, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(stream); + virStreamPtr handle; + + g_return_if_fail(GVIR_IS_OUTPUT_STREAM(stream)); + g_return_if_fail(output_stream->priv->result == NULL); + + g_object_get(output_stream->priv->stream, "handle", &handle, NULL); + + if (virStreamEventAddCallback(handle, VIR_STREAM_EVENT_WRITABLE, + gvir_output_stream_write_ready, stream, NULL) < 0) { + g_simple_async_report_error_in_idle(G_OBJECT(stream), + callback, + user_data, + G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, + "Couldn't add event callback %s", + G_STRFUNC); + goto end; + } + + output_stream->priv->result = + g_simple_async_result_new(G_OBJECT(stream), callback, user_data, + gvir_output_stream_write_async); + if (cancellable) + g_object_ref(cancellable); + output_stream->priv->cancellable = cancellable; + output_stream->priv->buffer = buffer; + output_stream->priv->count = count; + +end: + virStreamFree(handle); +} + + +static gssize gvir_output_stream_write_finish(GOutputStream *stream, + GAsyncResult *result, + GError **error G_GNUC_UNUSED) +{ + GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(stream); + GSimpleAsyncResult *simple; + virStreamPtr handle; + gssize count; + + g_return_val_if_fail(GVIR_IS_OUTPUT_STREAM(stream), -1); + g_object_get(output_stream->priv->stream, "handle", &handle, NULL); + + simple = G_SIMPLE_ASYNC_RESULT(result); + + g_warn_if_fail(g_simple_async_result_get_source_tag(simple) == gvir_output_stream_write_async); + + count = g_simple_async_result_get_op_res_gssize(simple); + + virStreamEventRemoveCallback(handle); + virStreamFree(handle); + + return count; +} + + +static void gvir_output_stream_class_init(GVirOutputStreamClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS(klass); + GOutputStreamClass *goutputstream_class = G_OUTPUT_STREAM_CLASS(klass); + + g_type_class_add_private(klass, sizeof(GVirOutputStreamPrivate)); + + gobject_class->finalize = gvir_output_stream_finalize; + gobject_class->get_property = gvir_output_stream_get_property; + gobject_class->set_property = gvir_output_stream_set_property; + + goutputstream_class->write_fn = NULL; + goutputstream_class->write_async = gvir_output_stream_write_async; + goutputstream_class->write_finish = gvir_output_stream_write_finish; + + g_object_class_install_property(gobject_class, PROP_STREAM, + g_param_spec_object("stream", + "stream", + "GVirStream", + GVIR_TYPE_STREAM, G_PARAM_CONSTRUCT_ONLY | + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); +} + +static void gvir_output_stream_init(GVirOutputStream *stream) +{ + stream->priv = G_TYPE_INSTANCE_GET_PRIVATE(stream, GVIR_TYPE_OUTPUT_STREAM, GVirOutputStreamPrivate); +} + +GVirOutputStream* _gvir_output_stream_new(GVirStream *stream) +{ + return GVIR_OUTPUT_STREAM(g_object_new(GVIR_TYPE_OUTPUT_STREAM, "stream", stream, NULL)); +} diff --git a/libvirt-gobject/libvirt-gobject-output-stream.h b/libvirt-gobject/libvirt-gobject-output-stream.h new file mode 100644 index 0000000..0ca0053 --- /dev/null +++ b/libvirt-gobject/libvirt-gobject-output-stream.h @@ -0,0 +1,68 @@ +/* + * libvirt-gobject-output-stream.h: libvirt gobject integration + * + * Copyright (C) 2011 Red Hat + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: Daniel P. Berrange <berrange@redhat.com> + * Marc-André Lureau <marcandre.lureau@redhat.com> + */ + +#if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD) +#error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GOBJECT_OUTPUT_STREAM_H__ +#define __LIBVIRT_GOBJECT_OUTPUT_STREAM_H__ + +#include <gio/gio.h> +#include "libvirt-gobject-stream.h" + +G_BEGIN_DECLS + +#define GVIR_TYPE_OUTPUT_STREAM (_gvir_output_stream_get_type ()) +#define GVIR_OUTPUT_STREAM(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \ + GVIR_TYPE_OUTPUT_STREAM, GVirOutputStream)) +#define GVIR_OUTPUT_STREAM_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \ + GVIR_TYPE_OUTPUT_STREAM, GVirOutputStreamClass)) +#define GVIR_IS_OUTPUT_STREAM(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \ + GVIR_TYPE_OUTPUT_STREAM)) +#define GVIR_IS_OUTPUT_STREAM_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \ + GVIR_TYPE_OUTPUT_STREAM)) +#define GVIR_OUTPUT_STREAM_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \ + GVIR_TYPE_OUTPUT_STREAM, GVirOutputStreamClass)) + +typedef struct _GVirOutputStreamPrivate GVirOutputStreamPrivate; +typedef struct _GVirOutputStreamClass GVirOutputStreamClass; +typedef struct _GVirOutputStream GVirOutputStream; + +struct _GVirOutputStreamClass +{ + GOutputStreamClass parent_class; +}; + +struct _GVirOutputStream +{ + GOutputStream parent_instance; + GVirOutputStreamPrivate *priv; +}; + +GType _gvir_output_stream_get_type (void) G_GNUC_CONST; +GVirOutputStream * _gvir_output_stream_new (GVirStream *stream); + +G_END_DECLS + +#endif /* __LIBVIRT_GOBJECT_OUTPUT_STREAM_H__ */ diff --git a/libvirt-gobject/libvirt-gobject-stream.c b/libvirt-gobject/libvirt-gobject-stream.c index 30673aa..0d1c2d1 100644 --- a/libvirt-gobject/libvirt-gobject-stream.c +++ b/libvirt-gobject/libvirt-gobject-stream.c @@ -32,6 +32,7 @@ #include "libvirt-gobject-compat.h" #include "libvirt-gobject/libvirt-gobject-input-stream.h" +#include "libvirt-gobject/libvirt-gobject-output-stream.h" extern gboolean debugFlag; @@ -44,7 +45,7 @@ struct _GVirStreamPrivate { virStreamPtr handle; GInputStream *input_stream; - gboolean in_dispose; + GOutputStream *output_stream; }; G_DEFINE_TYPE(GVirStream, gvir_stream, G_TYPE_IO_STREAM); @@ -77,6 +78,17 @@ static GInputStream* gvir_stream_get_input_stream(GIOStream *io_stream) } +static GOutputStream* gvir_stream_get_output_stream(GIOStream *io_stream) +{ + GVirStream *self = GVIR_STREAM(io_stream); + + if (self->priv->output_stream == NULL) + self->priv->output_stream = (GOutputStream *)_gvir_output_stream_new(self); + + return self->priv->output_stream; +} + + static gboolean gvir_stream_close(GIOStream *io_stream, GCancellable *cancellable, G_GNUC_UNUSED GError **error) { @@ -85,8 +97,8 @@ static gboolean gvir_stream_close(GIOStream *io_stream, if (self->priv->input_stream) g_input_stream_close(self->priv->input_stream, cancellable, NULL); - if (self->priv->in_dispose) - return TRUE; + if (self->priv->output_stream) + g_output_stream_close(self->priv->output_stream, cancellable, NULL); return TRUE; /* FIXME: really close the stream? */ } @@ -201,6 +213,7 @@ static void gvir_stream_class_init(GVirStreamClass *klass) object_class->set_property = gvir_stream_set_property; stream_class->get_input_stream = gvir_stream_get_input_stream; + stream_class->get_output_stream = gvir_stream_get_output_stream; stream_class->close_fn = gvir_stream_close; stream_class->close_async = gvir_stream_close_async; stream_class->close_finish = gvir_stream_close_finish; @@ -339,3 +352,99 @@ gvir_stream_receive_all(GVirStream *self, GVirStreamSinkFunc func, gpointer user return r; } + + +/** + * gvir_stream_send: + * @stream: the stream + * @buffer: a buffer to write data from (which should be at least @size + * bytes long). + * @size: the number of bytes you want to write to the stream + * @cancellable: (allow-none): a %GCancellable or %NULL + * @error: #GError for error reporting, or %NULL to ignore. + * + * Send data (up to @size bytes) from a stream. + * On error -1 is returned and @error is set accordingly. + * + * gvir_stream_send() can return any number of bytes, up to + * @size. If more than @size bytes have been sendd, the additional + * data will be returned in future calls to gvir_stream_send(). + * + * If there is no data available, a %G_IO_ERROR_WOULD_BLOCK error will be + * returned. + * + * Returns: Number of bytes read, or 0 if the end of stream reached, + * or -1 on error. + */ +gssize gvir_stream_send(GVirStream *self, const gchar *buffer, gsize size, + GCancellable *cancellable, GError **error) +{ + int got; + + g_return_val_if_fail(GVIR_IS_STREAM(self), -1); + g_return_val_if_fail(buffer != NULL, -1); + + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return -1; + + got = virStreamSend(self->priv->handle, buffer, size); + + if (got == -2) { /* blocking */ + g_set_error(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK, NULL); + } else if (got < 0) { + g_set_error(error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, + "Got virStreamRecv error in %s", G_STRFUNC); + } + + return got; +} + +struct stream_source_helper { + GVirStream *self; + GVirStreamSourceFunc func; + gpointer user_data; +}; + +static int +stream_source(virStreamPtr st G_GNUC_UNUSED, + char *bytes, size_t nbytes, void *opaque) +{ + struct stream_source_helper *helper = opaque; + + return helper->func(helper->self, bytes, nbytes, helper->user_data); +} + +/** + * gvir_stream_send_all: + * @stream: the stream + * @func: (scope notified): the callback for writing data to application + * @user_data: (closure): data to be passed to @callback + * Returns: the number of bytes consumed or -1 upon error + * + * Send the entire data stream, sending the data to the + * requested data source. This is simply a convenient alternative + * to virStreamRecv, for apps that do blocking-I/o. + */ +gssize +gvir_stream_send_all(GVirStream *self, GVirStreamSourceFunc func, gpointer user_data, GError **err) +{ + struct stream_source_helper helper = { + .self = self, + .func = func, + .user_data = user_data + }; + int r; + + g_return_val_if_fail(GVIR_IS_STREAM(self), -1); + g_return_val_if_fail(func != NULL, -1); + + r = virStreamSendAll(self->priv->handle, stream_source, &helper); + if (r < 0) { + if (err != NULL) + *err = gvir_error_new_literal(GVIR_STREAM_ERROR, + 0, + "Unable to perform SendAll"); + } + + return r; +} diff --git a/libvirt-gobject/libvirt-gobject-stream.h b/libvirt-gobject/libvirt-gobject-stream.h index 35526db..5a1ee68 100644 --- a/libvirt-gobject/libvirt-gobject-stream.h +++ b/libvirt-gobject/libvirt-gobject-stream.h @@ -71,17 +71,34 @@ struct _GVirStreamClass * Returns: the number of bytes filled, 0 upon end * of file, or -1 upon error */ -typedef gint (* GVirStreamSinkFunc) (GVirStream *stream, - const gchar *buf, - gsize nbytes, - gpointer user_data); +typedef gint (* GVirStreamSinkFunc)(GVirStream *stream, + const gchar *buf, + gsize nbytes, + gpointer user_data); + +/** + * GVirStreamSourceFunc: + * @stream: a #GVirStream + * @buf: (out) (array length=nbytes) (transfer none): data pointer + * @nbytes: data size + * @user_data: user data passed to the function + * Returns: the number of bytes filled, 0 upon end + * of file, or -1 upon error + */ +typedef gint (* GVirStreamSourceFunc)(GVirStream *stream, + gchar *buf, + gsize nbytes, + gpointer user_data); GType gvir_stream_get_type(void); GType gvir_stream_handle_get_type(void); -gssize gvir_stream_receive_all(GVirStream *stream, GVirStreamSinkFunc func, gpointer user_data, GError **err); +gssize gvir_stream_receive_all(GVirStream *stream, GVirStreamSinkFunc func, gpointer user_data, GError **error); gssize gvir_stream_receive(GVirStream *stream, gchar *buffer, gsize size, GCancellable *cancellable, GError **error); +gssize gvir_stream_send_all(GVirStream *stream, GVirStreamSourceFunc func, gpointer user_data, GError **error); +gssize gvir_stream_send(GVirStream *stream, const gchar *buffer, gsize size, GCancellable *cancellable, GError **error); + G_END_DECLS #endif /* __LIBVIRT_GOBJECT_STREAM_H__ */ -- 1.7.6.4

On Tue, Nov 22, 2011 at 12:39:28PM +0000, Daniel P. Berrange wrote:
+ +GType _gvir_output_stream_get_type (void) G_GNUC_CONST; +GVirOutputStream * _gvir_output_stream_new (GVirStream *stream);
This brings the question of how to mark functions that are internal to the library. Marc-André is in favour of using G_GNUC_INTERNAL in the function definition, you seem to prefer a _ prefix. I like the latter best, but I'd be fine with either. Christophe

On Tue, Nov 22, 2011 at 02:50:26PM +0100, Christophe Fergeau wrote:
On Tue, Nov 22, 2011 at 12:39:28PM +0000, Daniel P. Berrange wrote:
+ +GType _gvir_output_stream_get_type (void) G_GNUC_CONST; +GVirOutputStream * _gvir_output_stream_new (GVirStream *stream);
This brings the question of how to mark functions that are internal to the library. Marc-André is in favour of using G_GNUC_INTERNAL in the function definition, you seem to prefer a _ prefix. I like the latter best, but I'd be fine with either.
On the contrary. I would gladly get rid of the '_' prefix. I only have it because the existing gvir_input_stream* functions have it, and when I tried to remove it, then GTK-DOC tried to generate pages for this type. 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 :|

From: "Daniel P. Berrange" <berrange@redhat.com> --- libvirt-gobject/libvirt-gobject-connection.c | 6 ++-- libvirt-gobject/libvirt-gobject-connection.h | 4 +- libvirt-gobject/libvirt-gobject-domain-snapshot.c | 2 +- libvirt-gobject/libvirt-gobject-domain-snapshot.h | 2 +- libvirt-gobject/libvirt-gobject-domain.c | 37 ++++++++++++++------ libvirt-gobject/libvirt-gobject-domain.h | 16 ++++---- libvirt-gobject/libvirt-gobject-interface.c | 2 +- libvirt-gobject/libvirt-gobject-interface.h | 2 +- libvirt-gobject/libvirt-gobject-network-filter.c | 2 +- libvirt-gobject/libvirt-gobject-network-filter.h | 2 +- libvirt-gobject/libvirt-gobject-network.c | 2 +- libvirt-gobject/libvirt-gobject-network.h | 2 +- libvirt-gobject/libvirt-gobject-node-device.c | 2 +- libvirt-gobject/libvirt-gobject-node-device.h | 2 +- libvirt-gobject/libvirt-gobject-secret.c | 2 +- libvirt-gobject/libvirt-gobject-secret.h | 2 +- libvirt-gobject/libvirt-gobject-storage-pool.c | 12 +++--- libvirt-gobject/libvirt-gobject-storage-pool.h | 10 +++--- libvirt-gobject/libvirt-gobject-storage-vol.c | 2 +- libvirt-gobject/libvirt-gobject-storage-vol.h | 2 +- 20 files changed, 64 insertions(+), 49 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 6c8de11..f52b825 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1145,7 +1145,7 @@ G_DEFINE_BOXED_TYPE(GVirConnectionHandle, gvir_connection_handle, * Return value: (transfer full): a #GVirStream stream, or NULL */ GVirStream *gvir_connection_get_stream(GVirConnection *self, - gint flags) + guint flags) { GVirConnectionClass *klass; @@ -1212,7 +1212,7 @@ GVirDomain *gvir_connection_create_domain(GVirConnection *conn, GVirStoragePool *gvir_connection_create_storage_pool (GVirConnection *conn, GVirConfigStoragePool *conf, - guint64 flags G_GNUC_UNUSED, + guint flags, GError **err) { const gchar *xml; virStoragePoolPtr handle; @@ -1222,7 +1222,7 @@ GVirStoragePool *gvir_connection_create_storage_pool g_return_val_if_fail(xml != NULL, NULL); - if (!(handle = virStoragePoolDefineXML(priv->conn, xml, 0))) { + if (!(handle = virStoragePoolDefineXML(priv->conn, xml, flags))) { *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR, flags, "Failed to create storage pool"); diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h index 9f4bdc3..92a15ab 100644 --- a/libvirt-gobject/libvirt-gobject-connection.h +++ b/libvirt-gobject/libvirt-gobject-connection.h @@ -163,12 +163,12 @@ GVirStoragePool *gvir_connection_find_storage_pool_by_name(GVirConnection *conn, GVirStoragePool *gvir_connection_create_storage_pool (GVirConnection *conn, GVirConfigStoragePool *conf, - guint64 flags, + guint flags, GError **err); GVirStream *gvir_connection_get_stream(GVirConnection *conn, - gint flags); + guint flags); G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.c b/libvirt-gobject/libvirt-gobject-domain-snapshot.c index 96be997..e536d72 100644 --- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c +++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c @@ -197,7 +197,7 @@ const gchar *gvir_domain_snapshot_get_name(GVirDomainSnapshot *snapshot) */ GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config (GVirDomainSnapshot *snapshot, - guint64 flags, + guint flags, GError **err) { GVirDomainSnapshotPrivate *priv = snapshot->priv; diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.h b/libvirt-gobject/libvirt-gobject-domain-snapshot.h index 457c9dd..fc2eb7b 100644 --- a/libvirt-gobject/libvirt-gobject-domain-snapshot.h +++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.h @@ -66,7 +66,7 @@ const gchar *gvir_domain_snapshot_get_name(GVirDomainSnapshot *snapshot); GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config (GVirDomainSnapshot *snapshot, - guint64 flags, + guint flags, GError **err); G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 7ff820b..4a7a534 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -301,12 +301,17 @@ gint gvir_domain_get_id(GVirDomain *dom, * @flags: the flags */ gboolean gvir_domain_start(GVirDomain *dom, - guint64 flags G_GNUC_UNUSED, + guint flags, GError **err) { GVirDomainPrivate *priv = dom->priv; + int ret; - if (virDomainCreate(priv->handle) < 0) { + if (flags) + ret = virDomainCreateWithFlags(priv->handle, flags); + else + ret = virDomainCreate(priv->handle); + if (ret < 0) { *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, 0, "Unable to start domain"); @@ -343,12 +348,17 @@ gboolean gvir_domain_resume(GVirDomain *dom, * @flags: the flags */ gboolean gvir_domain_stop(GVirDomain *dom, - guint64 flags G_GNUC_UNUSED, + guint flags, GError **err) { GVirDomainPrivate *priv = dom->priv; + int ret; - if (virDomainDestroy(priv->handle) < 0) { + if (flags) + ret = virDomainDestroyFlags(priv->handle, flags); + else + ret = virDomainDestroy(priv->handle); + if (ret < 0) { *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, 0, "Unable to stop domain"); @@ -364,12 +374,17 @@ gboolean gvir_domain_stop(GVirDomain *dom, * @flags: the flags */ gboolean gvir_domain_delete(GVirDomain *dom, - guint64 flags G_GNUC_UNUSED, + guint flags, GError **err) { GVirDomainPrivate *priv = dom->priv; + int ret; - if (virDomainUndefine(priv->handle) < 0) { + if (flags) + ret = virDomainUndefineFlags(priv->handle, flags); + else + ret = virDomainUndefine(priv->handle); + if (ret < 0) { *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, 0, "Unable to delete domain"); @@ -385,7 +400,7 @@ gboolean gvir_domain_delete(GVirDomain *dom, * @flags: the flags */ gboolean gvir_domain_shutdown(GVirDomain *dom, - guint64 flags G_GNUC_UNUSED, + guint flags G_GNUC_UNUSED, GError **err) { GVirDomainPrivate *priv = dom->priv; @@ -406,7 +421,7 @@ gboolean gvir_domain_shutdown(GVirDomain *dom, * @flags: the flags */ gboolean gvir_domain_reboot(GVirDomain *dom, - guint64 flags, + guint flags, GError **err) { GVirDomainPrivate *priv = dom->priv; @@ -428,7 +443,7 @@ gboolean gvir_domain_reboot(GVirDomain *dom, * Returns: (transfer full): the config */ GVirConfigDomain *gvir_domain_get_config(GVirDomain *dom, - guint64 flags, + guint flags, GError **err) { GVirDomainPrivate *priv = dom->priv; @@ -557,8 +572,8 @@ GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom, */ gchar *gvir_domain_screenshot(GVirDomain *dom, GVirStream *stream, - guint64 monitor_id, - guint64 flags, + guint monitor_id, + guint flags, GError **err) { GVirDomainPrivate *priv; diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h index 0479de8..b67e8df 100644 --- a/libvirt-gobject/libvirt-gobject-domain.h +++ b/libvirt-gobject/libvirt-gobject-domain.h @@ -100,28 +100,28 @@ gint gvir_domain_get_id(GVirDomain *dom, GError **err); gboolean gvir_domain_start(GVirDomain *dom, - guint64 flags, + guint flags, GError **err); gboolean gvir_domain_resume(GVirDomain *dom, GError **err); gboolean gvir_domain_stop(GVirDomain *dom, - guint64 flags, + guint flags, GError **err); gboolean gvir_domain_delete(GVirDomain *dom, - guint64 flags, + guint flags, GError **err); gboolean gvir_domain_shutdown(GVirDomain *dom, - guint64 flags, + guint flags, GError **err); gboolean gvir_domain_reboot(GVirDomain *dom, - guint64 flags, + guint flags, GError **err); GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom, GError **err); GVirConfigDomain *gvir_domain_get_config(GVirDomain *dom, - guint64 flags, + guint flags, GError **err); gboolean gvir_domain_set_config(GVirDomain *domain, GVirConfigDomain *conf, @@ -129,8 +129,8 @@ gboolean gvir_domain_set_config(GVirDomain *domain, gchar *gvir_domain_screenshot(GVirDomain *dom, GVirStream *stream, - guint64 monitor_id, - guint64 flags, + guint monitor_id, + guint flags, GError **err); G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-interface.c b/libvirt-gobject/libvirt-gobject-interface.c index f74b47c..d35cdc2 100644 --- a/libvirt-gobject/libvirt-gobject-interface.c +++ b/libvirt-gobject/libvirt-gobject-interface.c @@ -186,7 +186,7 @@ const gchar *gvir_interface_get_name(GVirInterface *iface) * Returns: (transfer full): the config */ GVirConfigInterface *gvir_interface_get_config(GVirInterface *iface, - guint64 flags, + guint flags, GError **err) { GVirInterfacePrivate *priv = iface->priv; diff --git a/libvirt-gobject/libvirt-gobject-interface.h b/libvirt-gobject/libvirt-gobject-interface.h index 2fa76a8..c98dbc4 100644 --- a/libvirt-gobject/libvirt-gobject-interface.h +++ b/libvirt-gobject/libvirt-gobject-interface.h @@ -65,7 +65,7 @@ GType gvir_interface_handle_get_type(void); const gchar *gvir_interface_get_name(GVirInterface *iface); GVirConfigInterface *gvir_interface_get_config(GVirInterface *iface, - guint64 flags, + guint flags, GError **err); G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-network-filter.c b/libvirt-gobject/libvirt-gobject-network-filter.c index b5ffbe7..6ce0f7c 100644 --- a/libvirt-gobject/libvirt-gobject-network-filter.c +++ b/libvirt-gobject/libvirt-gobject-network-filter.c @@ -212,7 +212,7 @@ const gchar *gvir_network_filter_get_uuid(GVirNetworkFilter *filter) */ GVirConfigNetworkFilter *gvir_network_filter_get_config (GVirNetworkFilter *filter, - guint64 flags, + guint flags, GError **err) { GVirNetworkFilterPrivate *priv = filter->priv; diff --git a/libvirt-gobject/libvirt-gobject-network-filter.h b/libvirt-gobject/libvirt-gobject-network-filter.h index f2c63cf..2c03c10 100644 --- a/libvirt-gobject/libvirt-gobject-network-filter.h +++ b/libvirt-gobject/libvirt-gobject-network-filter.h @@ -66,7 +66,7 @@ const gchar *gvir_network_filter_get_uuid(GVirNetworkFilter *filter); GVirConfigNetworkFilter *gvir_network_filter_get_config (GVirNetworkFilter *filter, - guint64 flags, + guint flags, GError **err); G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-network.c b/libvirt-gobject/libvirt-gobject-network.c index 20b8012..237f788 100644 --- a/libvirt-gobject/libvirt-gobject-network.c +++ b/libvirt-gobject/libvirt-gobject-network.c @@ -208,7 +208,7 @@ const gchar *gvir_network_get_uuid(GVirNetwork *network) * Returns: (transfer full): the config */ GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network, - guint64 flags, + guint flags, GError **err) { GVirNetworkPrivate *priv = network->priv; diff --git a/libvirt-gobject/libvirt-gobject-network.h b/libvirt-gobject/libvirt-gobject-network.h index 7b3d2dc..12ee917 100644 --- a/libvirt-gobject/libvirt-gobject-network.h +++ b/libvirt-gobject/libvirt-gobject-network.h @@ -69,7 +69,7 @@ const gchar *gvir_network_get_name(GVirNetwork *network); const gchar *gvir_network_get_uuid(GVirNetwork *network); GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network, - guint64 flags, + guint flags, GError **err); G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-node-device.c b/libvirt-gobject/libvirt-gobject-node-device.c index 784c594..162f930 100644 --- a/libvirt-gobject/libvirt-gobject-node-device.c +++ b/libvirt-gobject/libvirt-gobject-node-device.c @@ -187,7 +187,7 @@ const gchar *gvir_node_device_get_name(GVirNodeDevice *device) * Returns: (transfer full): the config */ GVirConfigNodeDevice *gvir_node_device_get_config(GVirNodeDevice *device, - guint64 flags, + guint flags, GError **err) { GVirNodeDevicePrivate *priv = device->priv; diff --git a/libvirt-gobject/libvirt-gobject-node-device.h b/libvirt-gobject/libvirt-gobject-node-device.h index 2b51b5d..250001b 100644 --- a/libvirt-gobject/libvirt-gobject-node-device.h +++ b/libvirt-gobject/libvirt-gobject-node-device.h @@ -64,7 +64,7 @@ GType gvir_node_device_handle_get_type(void); const gchar *gvir_node_device_get_name(GVirNodeDevice *device); GVirConfigNodeDevice *gvir_node_device_get_config(GVirNodeDevice *device, - guint64 flags, + guint flags, GError **err); G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-secret.c b/libvirt-gobject/libvirt-gobject-secret.c index 0f885a1..5bde345 100644 --- a/libvirt-gobject/libvirt-gobject-secret.c +++ b/libvirt-gobject/libvirt-gobject-secret.c @@ -198,7 +198,7 @@ const gchar *gvir_secret_get_uuid(GVirSecret *secret) * Returns: (transfer full): the config */ GVirConfigSecret *gvir_secret_get_config(GVirSecret *secret, - guint64 flags, + guint flags, GError **err) { GVirSecretPrivate *priv = secret->priv; diff --git a/libvirt-gobject/libvirt-gobject-secret.h b/libvirt-gobject/libvirt-gobject-secret.h index 443ffde..e4d385e 100644 --- a/libvirt-gobject/libvirt-gobject-secret.h +++ b/libvirt-gobject/libvirt-gobject-secret.h @@ -66,7 +66,7 @@ const gchar *gvir_secret_get_name(GVirSecret *secret); const gchar *gvir_secret_get_uuid(GVirSecret *secret); GVirConfigSecret *gvir_secret_get_config(GVirSecret *secret, - guint64 flags, + guint flags, GError **err); G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c index ccc8e8a..915e0a1 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.c +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c @@ -223,7 +223,7 @@ const gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool) * Returns: (transfer full): the config */ GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool, - guint64 flags, + guint flags, GError **err) { GVirStoragePoolPrivate *priv = pool->priv; @@ -528,7 +528,7 @@ GVirStorageVol *gvir_storage_pool_create_volume * Return value: #True on success, #False otherwise. */ gboolean gvir_storage_pool_build (GVirStoragePool *pool, - guint64 flags, + guint flags, GError **err) { if (virStoragePoolBuild(pool->priv->handle, flags)) { @@ -542,7 +542,7 @@ gboolean gvir_storage_pool_build (GVirStoragePool *pool, } typedef struct { - guint64 flags; + guint flags; } StoragePoolBuildData; static void @@ -574,7 +574,7 @@ gvir_storage_pool_build_helper(GSimpleAsyncResult *res, * @user_data: (closure): opaque data for callback */ void gvir_storage_pool_build_async (GVirStoragePool *pool, - guint64 flags, + guint flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -632,7 +632,7 @@ gboolean gvir_storage_pool_build_finish(GVirStoragePool *pool, * Return value: #True on success, #False otherwise. */ gboolean gvir_storage_pool_start (GVirStoragePool *pool, - guint64 flags, + guint flags, GError **err) { if (virStoragePoolCreate(pool->priv->handle, flags)) { @@ -674,7 +674,7 @@ gvir_storage_pool_start_helper(GSimpleAsyncResult *res, * @user_data: (closure): opaque data for callback */ void gvir_storage_pool_start_async (GVirStoragePool *pool, - guint64 flags, + guint flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.h b/libvirt-gobject/libvirt-gobject-storage-pool.h index 25df1b1..d95bb19 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.h +++ b/libvirt-gobject/libvirt-gobject-storage-pool.h @@ -66,7 +66,7 @@ const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool); const gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool); GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool, - guint64 flags, + guint flags, GError **err); gboolean gvir_storage_pool_refresh(GVirStoragePool *pool, @@ -89,10 +89,10 @@ GVirStorageVol *gvir_storage_pool_create_volume GError **err); gboolean gvir_storage_pool_build (GVirStoragePool *pool, - guint64 flags, + guint flags, GError **err); void gvir_storage_pool_build_async (GVirStoragePool *pool, - guint64 flags, + guint flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -101,10 +101,10 @@ gboolean gvir_storage_pool_build_finish(GVirStoragePool *pool, GError **err); gboolean gvir_storage_pool_start (GVirStoragePool *pool, - guint64 flags, + guint flags, GError **err); void gvir_storage_pool_start_async (GVirStoragePool *pool, - guint64 flags, + guint flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c index ed48de8..a8aec60 100644 --- a/libvirt-gobject/libvirt-gobject-storage-vol.c +++ b/libvirt-gobject/libvirt-gobject-storage-vol.c @@ -198,7 +198,7 @@ const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol) * Returns: (transfer full): the config */ GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol, - guint64 flags, + guint flags, GError **err) { GVirStorageVolPrivate *priv = vol->priv; diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.h b/libvirt-gobject/libvirt-gobject-storage-vol.h index 3c6189b..8acdcf9 100644 --- a/libvirt-gobject/libvirt-gobject-storage-vol.h +++ b/libvirt-gobject/libvirt-gobject-storage-vol.h @@ -65,7 +65,7 @@ const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol); const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol); GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol, - guint64 flags, + guint flags, GError **err); G_END_DECLS -- 1.7.6.4

ack On Tue, Nov 22, 2011 at 12:39:29PM +0000, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
--- libvirt-gobject/libvirt-gobject-connection.c | 6 ++-- libvirt-gobject/libvirt-gobject-connection.h | 4 +- libvirt-gobject/libvirt-gobject-domain-snapshot.c | 2 +- libvirt-gobject/libvirt-gobject-domain-snapshot.h | 2 +- libvirt-gobject/libvirt-gobject-domain.c | 37 ++++++++++++++------ libvirt-gobject/libvirt-gobject-domain.h | 16 ++++---- libvirt-gobject/libvirt-gobject-interface.c | 2 +- libvirt-gobject/libvirt-gobject-interface.h | 2 +- libvirt-gobject/libvirt-gobject-network-filter.c | 2 +- libvirt-gobject/libvirt-gobject-network-filter.h | 2 +- libvirt-gobject/libvirt-gobject-network.c | 2 +- libvirt-gobject/libvirt-gobject-network.h | 2 +- libvirt-gobject/libvirt-gobject-node-device.c | 2 +- libvirt-gobject/libvirt-gobject-node-device.h | 2 +- libvirt-gobject/libvirt-gobject-secret.c | 2 +- libvirt-gobject/libvirt-gobject-secret.h | 2 +- libvirt-gobject/libvirt-gobject-storage-pool.c | 12 +++--- libvirt-gobject/libvirt-gobject-storage-pool.h | 10 +++--- libvirt-gobject/libvirt-gobject-storage-vol.c | 2 +- libvirt-gobject/libvirt-gobject-storage-vol.h | 2 +- 20 files changed, 64 insertions(+), 49 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 6c8de11..f52b825 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1145,7 +1145,7 @@ G_DEFINE_BOXED_TYPE(GVirConnectionHandle, gvir_connection_handle, * Return value: (transfer full): a #GVirStream stream, or NULL */ GVirStream *gvir_connection_get_stream(GVirConnection *self, - gint flags) + guint flags) { GVirConnectionClass *klass;
@@ -1212,7 +1212,7 @@ GVirDomain *gvir_connection_create_domain(GVirConnection *conn, GVirStoragePool *gvir_connection_create_storage_pool (GVirConnection *conn, GVirConfigStoragePool *conf, - guint64 flags G_GNUC_UNUSED, + guint flags, GError **err) { const gchar *xml; virStoragePoolPtr handle; @@ -1222,7 +1222,7 @@ GVirStoragePool *gvir_connection_create_storage_pool
g_return_val_if_fail(xml != NULL, NULL);
- if (!(handle = virStoragePoolDefineXML(priv->conn, xml, 0))) { + if (!(handle = virStoragePoolDefineXML(priv->conn, xml, flags))) { *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR, flags, "Failed to create storage pool"); diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h index 9f4bdc3..92a15ab 100644 --- a/libvirt-gobject/libvirt-gobject-connection.h +++ b/libvirt-gobject/libvirt-gobject-connection.h @@ -163,12 +163,12 @@ GVirStoragePool *gvir_connection_find_storage_pool_by_name(GVirConnection *conn, GVirStoragePool *gvir_connection_create_storage_pool (GVirConnection *conn, GVirConfigStoragePool *conf, - guint64 flags, + guint flags, GError **err);
GVirStream *gvir_connection_get_stream(GVirConnection *conn, - gint flags); + guint flags);
G_END_DECLS
diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.c b/libvirt-gobject/libvirt-gobject-domain-snapshot.c index 96be997..e536d72 100644 --- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c +++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c @@ -197,7 +197,7 @@ const gchar *gvir_domain_snapshot_get_name(GVirDomainSnapshot *snapshot) */ GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config (GVirDomainSnapshot *snapshot, - guint64 flags, + guint flags, GError **err) { GVirDomainSnapshotPrivate *priv = snapshot->priv; diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.h b/libvirt-gobject/libvirt-gobject-domain-snapshot.h index 457c9dd..fc2eb7b 100644 --- a/libvirt-gobject/libvirt-gobject-domain-snapshot.h +++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.h @@ -66,7 +66,7 @@ const gchar *gvir_domain_snapshot_get_name(GVirDomainSnapshot *snapshot);
GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config (GVirDomainSnapshot *snapshot, - guint64 flags, + guint flags, GError **err);
G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 7ff820b..4a7a534 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -301,12 +301,17 @@ gint gvir_domain_get_id(GVirDomain *dom, * @flags: the flags */ gboolean gvir_domain_start(GVirDomain *dom, - guint64 flags G_GNUC_UNUSED, + guint flags, GError **err) { GVirDomainPrivate *priv = dom->priv; + int ret;
- if (virDomainCreate(priv->handle) < 0) { + if (flags) + ret = virDomainCreateWithFlags(priv->handle, flags); + else + ret = virDomainCreate(priv->handle); + if (ret < 0) { *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, 0, "Unable to start domain"); @@ -343,12 +348,17 @@ gboolean gvir_domain_resume(GVirDomain *dom, * @flags: the flags */ gboolean gvir_domain_stop(GVirDomain *dom, - guint64 flags G_GNUC_UNUSED, + guint flags, GError **err) { GVirDomainPrivate *priv = dom->priv; + int ret;
- if (virDomainDestroy(priv->handle) < 0) { + if (flags) + ret = virDomainDestroyFlags(priv->handle, flags); + else + ret = virDomainDestroy(priv->handle); + if (ret < 0) { *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, 0, "Unable to stop domain"); @@ -364,12 +374,17 @@ gboolean gvir_domain_stop(GVirDomain *dom, * @flags: the flags */ gboolean gvir_domain_delete(GVirDomain *dom, - guint64 flags G_GNUC_UNUSED, + guint flags, GError **err) { GVirDomainPrivate *priv = dom->priv; + int ret;
- if (virDomainUndefine(priv->handle) < 0) { + if (flags) + ret = virDomainUndefineFlags(priv->handle, flags); + else + ret = virDomainUndefine(priv->handle); + if (ret < 0) { *err = gvir_error_new_literal(GVIR_DOMAIN_ERROR, 0, "Unable to delete domain"); @@ -385,7 +400,7 @@ gboolean gvir_domain_delete(GVirDomain *dom, * @flags: the flags */ gboolean gvir_domain_shutdown(GVirDomain *dom, - guint64 flags G_GNUC_UNUSED, + guint flags G_GNUC_UNUSED, GError **err) { GVirDomainPrivate *priv = dom->priv; @@ -406,7 +421,7 @@ gboolean gvir_domain_shutdown(GVirDomain *dom, * @flags: the flags */ gboolean gvir_domain_reboot(GVirDomain *dom, - guint64 flags, + guint flags, GError **err) { GVirDomainPrivate *priv = dom->priv; @@ -428,7 +443,7 @@ gboolean gvir_domain_reboot(GVirDomain *dom, * Returns: (transfer full): the config */ GVirConfigDomain *gvir_domain_get_config(GVirDomain *dom, - guint64 flags, + guint flags, GError **err) { GVirDomainPrivate *priv = dom->priv; @@ -557,8 +572,8 @@ GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom, */ gchar *gvir_domain_screenshot(GVirDomain *dom, GVirStream *stream, - guint64 monitor_id, - guint64 flags, + guint monitor_id, + guint flags, GError **err) { GVirDomainPrivate *priv; diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h index 0479de8..b67e8df 100644 --- a/libvirt-gobject/libvirt-gobject-domain.h +++ b/libvirt-gobject/libvirt-gobject-domain.h @@ -100,28 +100,28 @@ gint gvir_domain_get_id(GVirDomain *dom, GError **err);
gboolean gvir_domain_start(GVirDomain *dom, - guint64 flags, + guint flags, GError **err); gboolean gvir_domain_resume(GVirDomain *dom, GError **err); gboolean gvir_domain_stop(GVirDomain *dom, - guint64 flags, + guint flags, GError **err); gboolean gvir_domain_delete(GVirDomain *dom, - guint64 flags, + guint flags, GError **err); gboolean gvir_domain_shutdown(GVirDomain *dom, - guint64 flags, + guint flags, GError **err); gboolean gvir_domain_reboot(GVirDomain *dom, - guint64 flags, + guint flags, GError **err);
GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom, GError **err);
GVirConfigDomain *gvir_domain_get_config(GVirDomain *dom, - guint64 flags, + guint flags, GError **err); gboolean gvir_domain_set_config(GVirDomain *domain, GVirConfigDomain *conf, @@ -129,8 +129,8 @@ gboolean gvir_domain_set_config(GVirDomain *domain,
gchar *gvir_domain_screenshot(GVirDomain *dom, GVirStream *stream, - guint64 monitor_id, - guint64 flags, + guint monitor_id, + guint flags, GError **err);
G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-interface.c b/libvirt-gobject/libvirt-gobject-interface.c index f74b47c..d35cdc2 100644 --- a/libvirt-gobject/libvirt-gobject-interface.c +++ b/libvirt-gobject/libvirt-gobject-interface.c @@ -186,7 +186,7 @@ const gchar *gvir_interface_get_name(GVirInterface *iface) * Returns: (transfer full): the config */ GVirConfigInterface *gvir_interface_get_config(GVirInterface *iface, - guint64 flags, + guint flags, GError **err) { GVirInterfacePrivate *priv = iface->priv; diff --git a/libvirt-gobject/libvirt-gobject-interface.h b/libvirt-gobject/libvirt-gobject-interface.h index 2fa76a8..c98dbc4 100644 --- a/libvirt-gobject/libvirt-gobject-interface.h +++ b/libvirt-gobject/libvirt-gobject-interface.h @@ -65,7 +65,7 @@ GType gvir_interface_handle_get_type(void); const gchar *gvir_interface_get_name(GVirInterface *iface);
GVirConfigInterface *gvir_interface_get_config(GVirInterface *iface, - guint64 flags, + guint flags, GError **err);
G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-network-filter.c b/libvirt-gobject/libvirt-gobject-network-filter.c index b5ffbe7..6ce0f7c 100644 --- a/libvirt-gobject/libvirt-gobject-network-filter.c +++ b/libvirt-gobject/libvirt-gobject-network-filter.c @@ -212,7 +212,7 @@ const gchar *gvir_network_filter_get_uuid(GVirNetworkFilter *filter) */ GVirConfigNetworkFilter *gvir_network_filter_get_config (GVirNetworkFilter *filter, - guint64 flags, + guint flags, GError **err) { GVirNetworkFilterPrivate *priv = filter->priv; diff --git a/libvirt-gobject/libvirt-gobject-network-filter.h b/libvirt-gobject/libvirt-gobject-network-filter.h index f2c63cf..2c03c10 100644 --- a/libvirt-gobject/libvirt-gobject-network-filter.h +++ b/libvirt-gobject/libvirt-gobject-network-filter.h @@ -66,7 +66,7 @@ const gchar *gvir_network_filter_get_uuid(GVirNetworkFilter *filter);
GVirConfigNetworkFilter *gvir_network_filter_get_config (GVirNetworkFilter *filter, - guint64 flags, + guint flags, GError **err);
G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-network.c b/libvirt-gobject/libvirt-gobject-network.c index 20b8012..237f788 100644 --- a/libvirt-gobject/libvirt-gobject-network.c +++ b/libvirt-gobject/libvirt-gobject-network.c @@ -208,7 +208,7 @@ const gchar *gvir_network_get_uuid(GVirNetwork *network) * Returns: (transfer full): the config */ GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network, - guint64 flags, + guint flags, GError **err) { GVirNetworkPrivate *priv = network->priv; diff --git a/libvirt-gobject/libvirt-gobject-network.h b/libvirt-gobject/libvirt-gobject-network.h index 7b3d2dc..12ee917 100644 --- a/libvirt-gobject/libvirt-gobject-network.h +++ b/libvirt-gobject/libvirt-gobject-network.h @@ -69,7 +69,7 @@ const gchar *gvir_network_get_name(GVirNetwork *network); const gchar *gvir_network_get_uuid(GVirNetwork *network);
GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network, - guint64 flags, + guint flags, GError **err);
G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-node-device.c b/libvirt-gobject/libvirt-gobject-node-device.c index 784c594..162f930 100644 --- a/libvirt-gobject/libvirt-gobject-node-device.c +++ b/libvirt-gobject/libvirt-gobject-node-device.c @@ -187,7 +187,7 @@ const gchar *gvir_node_device_get_name(GVirNodeDevice *device) * Returns: (transfer full): the config */ GVirConfigNodeDevice *gvir_node_device_get_config(GVirNodeDevice *device, - guint64 flags, + guint flags, GError **err) { GVirNodeDevicePrivate *priv = device->priv; diff --git a/libvirt-gobject/libvirt-gobject-node-device.h b/libvirt-gobject/libvirt-gobject-node-device.h index 2b51b5d..250001b 100644 --- a/libvirt-gobject/libvirt-gobject-node-device.h +++ b/libvirt-gobject/libvirt-gobject-node-device.h @@ -64,7 +64,7 @@ GType gvir_node_device_handle_get_type(void); const gchar *gvir_node_device_get_name(GVirNodeDevice *device);
GVirConfigNodeDevice *gvir_node_device_get_config(GVirNodeDevice *device, - guint64 flags, + guint flags, GError **err);
G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-secret.c b/libvirt-gobject/libvirt-gobject-secret.c index 0f885a1..5bde345 100644 --- a/libvirt-gobject/libvirt-gobject-secret.c +++ b/libvirt-gobject/libvirt-gobject-secret.c @@ -198,7 +198,7 @@ const gchar *gvir_secret_get_uuid(GVirSecret *secret) * Returns: (transfer full): the config */ GVirConfigSecret *gvir_secret_get_config(GVirSecret *secret, - guint64 flags, + guint flags, GError **err) { GVirSecretPrivate *priv = secret->priv; diff --git a/libvirt-gobject/libvirt-gobject-secret.h b/libvirt-gobject/libvirt-gobject-secret.h index 443ffde..e4d385e 100644 --- a/libvirt-gobject/libvirt-gobject-secret.h +++ b/libvirt-gobject/libvirt-gobject-secret.h @@ -66,7 +66,7 @@ const gchar *gvir_secret_get_name(GVirSecret *secret); const gchar *gvir_secret_get_uuid(GVirSecret *secret);
GVirConfigSecret *gvir_secret_get_config(GVirSecret *secret, - guint64 flags, + guint flags, GError **err);
G_END_DECLS diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c index ccc8e8a..915e0a1 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.c +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c @@ -223,7 +223,7 @@ const gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool) * Returns: (transfer full): the config */ GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool, - guint64 flags, + guint flags, GError **err) { GVirStoragePoolPrivate *priv = pool->priv; @@ -528,7 +528,7 @@ GVirStorageVol *gvir_storage_pool_create_volume * Return value: #True on success, #False otherwise. */ gboolean gvir_storage_pool_build (GVirStoragePool *pool, - guint64 flags, + guint flags, GError **err) { if (virStoragePoolBuild(pool->priv->handle, flags)) { @@ -542,7 +542,7 @@ gboolean gvir_storage_pool_build (GVirStoragePool *pool, }
typedef struct { - guint64 flags; + guint flags; } StoragePoolBuildData;
static void @@ -574,7 +574,7 @@ gvir_storage_pool_build_helper(GSimpleAsyncResult *res, * @user_data: (closure): opaque data for callback */ void gvir_storage_pool_build_async (GVirStoragePool *pool, - guint64 flags, + guint flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) @@ -632,7 +632,7 @@ gboolean gvir_storage_pool_build_finish(GVirStoragePool *pool, * Return value: #True on success, #False otherwise. */ gboolean gvir_storage_pool_start (GVirStoragePool *pool, - guint64 flags, + guint flags, GError **err) { if (virStoragePoolCreate(pool->priv->handle, flags)) { @@ -674,7 +674,7 @@ gvir_storage_pool_start_helper(GSimpleAsyncResult *res, * @user_data: (closure): opaque data for callback */ void gvir_storage_pool_start_async (GVirStoragePool *pool, - guint64 flags, + guint flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.h b/libvirt-gobject/libvirt-gobject-storage-pool.h index 25df1b1..d95bb19 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.h +++ b/libvirt-gobject/libvirt-gobject-storage-pool.h @@ -66,7 +66,7 @@ const gchar *gvir_storage_pool_get_name(GVirStoragePool *pool); const gchar *gvir_storage_pool_get_uuid(GVirStoragePool *pool);
GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool, - guint64 flags, + guint flags, GError **err);
gboolean gvir_storage_pool_refresh(GVirStoragePool *pool, @@ -89,10 +89,10 @@ GVirStorageVol *gvir_storage_pool_create_volume GError **err);
gboolean gvir_storage_pool_build (GVirStoragePool *pool, - guint64 flags, + guint flags, GError **err); void gvir_storage_pool_build_async (GVirStoragePool *pool, - guint64 flags, + guint flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); @@ -101,10 +101,10 @@ gboolean gvir_storage_pool_build_finish(GVirStoragePool *pool, GError **err);
gboolean gvir_storage_pool_start (GVirStoragePool *pool, - guint64 flags, + guint flags, GError **err); void gvir_storage_pool_start_async (GVirStoragePool *pool, - guint64 flags, + guint flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c index ed48de8..a8aec60 100644 --- a/libvirt-gobject/libvirt-gobject-storage-vol.c +++ b/libvirt-gobject/libvirt-gobject-storage-vol.c @@ -198,7 +198,7 @@ const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol) * Returns: (transfer full): the config */ GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol, - guint64 flags, + guint flags, GError **err) { GVirStorageVolPrivate *priv = vol->priv; diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.h b/libvirt-gobject/libvirt-gobject-storage-vol.h index 3c6189b..8acdcf9 100644 --- a/libvirt-gobject/libvirt-gobject-storage-vol.h +++ b/libvirt-gobject/libvirt-gobject-storage-vol.h @@ -65,7 +65,7 @@ const gchar *gvir_storage_vol_get_name(GVirStorageVol *vol); const gchar *gvir_storage_vol_get_path(GVirStorageVol *vol);
GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol, - guint64 flags, + guint flags, GError **err);
G_END_DECLS -- 1.7.6.4
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

From: "Daniel P. Berrange" <berrange@redhat.com> --- libvirt-gobject/libvirt-gobject-domain-snapshot.c | 5 +---- libvirt-gobject/libvirt-gobject-interface.c | 5 +---- libvirt-gobject/libvirt-gobject-network-filter.c | 5 +---- libvirt-gobject/libvirt-gobject-network.c | 5 +---- libvirt-gobject/libvirt-gobject-node-device.c | 6 +----- libvirt-gobject/libvirt-gobject-secret.c | 6 +----- libvirt-gobject/libvirt-gobject-storage-pool.c | 5 +---- libvirt-gobject/libvirt-gobject-storage-vol.c | 5 +---- 8 files changed, 8 insertions(+), 34 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.c b/libvirt-gobject/libvirt-gobject-domain-snapshot.c index e536d72..c65a183 100644 --- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c +++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c @@ -210,11 +210,8 @@ GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config return NULL; } -#if 0 - GVirConfigDomainSnapshot *conf = gvir_config_domain_snapshot_new(xml); + GVirConfigDomainSnapshot *conf = gvir_config_domain_snapshot_new_from_xml(xml, err); g_free(xml); return conf; -#endif - return NULL; } diff --git a/libvirt-gobject/libvirt-gobject-interface.c b/libvirt-gobject/libvirt-gobject-interface.c index d35cdc2..e47395c 100644 --- a/libvirt-gobject/libvirt-gobject-interface.c +++ b/libvirt-gobject/libvirt-gobject-interface.c @@ -199,11 +199,8 @@ GVirConfigInterface *gvir_interface_get_config(GVirInterface *iface, return NULL; } -#if 0 - GVirConfigInterface *conf = gvir_config_interface_new(xml); + GVirConfigInterface *conf = gvir_config_interface_new_from_xml(xml, err); g_free(xml); return conf; -#endif - return NULL; } diff --git a/libvirt-gobject/libvirt-gobject-network-filter.c b/libvirt-gobject/libvirt-gobject-network-filter.c index 6ce0f7c..bdb0e3a 100644 --- a/libvirt-gobject/libvirt-gobject-network-filter.c +++ b/libvirt-gobject/libvirt-gobject-network-filter.c @@ -225,11 +225,8 @@ GVirConfigNetworkFilter *gvir_network_filter_get_config return NULL; } -#if 0 - GVirConfigNetworkFilter *conf = gvir_config_network_filter_new(xml); + GVirConfigNetworkFilter *conf = gvir_config_network_filter_new_from_xml(xml, err); g_free(xml); return conf; -#endif - return NULL; } diff --git a/libvirt-gobject/libvirt-gobject-network.c b/libvirt-gobject/libvirt-gobject-network.c index 237f788..c486561 100644 --- a/libvirt-gobject/libvirt-gobject-network.c +++ b/libvirt-gobject/libvirt-gobject-network.c @@ -221,11 +221,8 @@ GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network, return NULL; } -#if 0 - GVirConfigNetwork *conf = gvir_config_network_new(xml); + GVirConfigNetwork *conf = gvir_config_network_new_from_xml(xml, err); g_free(xml); return conf; -#endif - return NULL; } diff --git a/libvirt-gobject/libvirt-gobject-node-device.c b/libvirt-gobject/libvirt-gobject-node-device.c index 162f930..43564b6 100644 --- a/libvirt-gobject/libvirt-gobject-node-device.c +++ b/libvirt-gobject/libvirt-gobject-node-device.c @@ -200,12 +200,8 @@ GVirConfigNodeDevice *gvir_node_device_get_config(GVirNodeDevice *device, return NULL; } -#if 0 - GVirConfigNodeDevice *conf = gvir_config_node_device_new(xml); + GVirConfigNodeDevice *conf = gvir_config_node_device_new_from_xml(xml, err); g_free(xml); return conf; -#endif - - return NULL; } diff --git a/libvirt-gobject/libvirt-gobject-secret.c b/libvirt-gobject/libvirt-gobject-secret.c index 5bde345..418e5aa 100644 --- a/libvirt-gobject/libvirt-gobject-secret.c +++ b/libvirt-gobject/libvirt-gobject-secret.c @@ -211,12 +211,8 @@ GVirConfigSecret *gvir_secret_get_config(GVirSecret *secret, return NULL; } -#if 0 - GVirConfigSecret *conf = gvir_config_secret_new(xml); + GVirConfigSecret *conf = gvir_config_secret_new_from_xml(xml, err); g_free(xml); return conf; -#endif - - return NULL; } diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c index 915e0a1..92be539 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.c +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c @@ -236,13 +236,10 @@ GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool, return NULL; } -#if 0 - GVirConfigStoragePool *conf = gvir_config_storage_pool_new(xml); + GVirConfigStoragePool *conf = gvir_config_storage_pool_new_from_xml(xml, err); g_free(xml); return conf; -#endif - return NULL; } typedef gint (* CountFunction) (virStoragePoolPtr vpool); diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c index a8aec60..17aac36 100644 --- a/libvirt-gobject/libvirt-gobject-storage-vol.c +++ b/libvirt-gobject/libvirt-gobject-storage-vol.c @@ -211,11 +211,8 @@ GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol, return NULL; } -#if 0 - GVirConfigStorageVol *conf = gvir_config_storage_vol_new(xml); + GVirConfigStorageVol *conf = gvir_config_storage_vol_new_from_xml(xml, err); g_free(xml); return conf; -#endif - return NULL; } -- 1.7.6.4

Hi, On Tue, Nov 22, 2011 at 12:39:30PM +0000, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
--- libvirt-gobject/libvirt-gobject-domain-snapshot.c | 5 +---- libvirt-gobject/libvirt-gobject-interface.c | 5 +---- libvirt-gobject/libvirt-gobject-network-filter.c | 5 +---- libvirt-gobject/libvirt-gobject-network.c | 5 +---- libvirt-gobject/libvirt-gobject-node-device.c | 6 +----- libvirt-gobject/libvirt-gobject-secret.c | 6 +----- libvirt-gobject/libvirt-gobject-storage-pool.c | 5 +---- libvirt-gobject/libvirt-gobject-storage-vol.c | 5 +---- 8 files changed, 8 insertions(+), 34 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.c b/libvirt-gobject/libvirt-gobject-domain-snapshot.c index e536d72..c65a183 100644 --- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c +++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c @@ -210,11 +210,8 @@ GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config return NULL; }
-#if 0 - GVirConfigDomainSnapshot *conf = gvir_config_domain_snapshot_new(xml); + GVirConfigDomainSnapshot *conf = gvir_config_domain_snapshot_new_from_xml(xml, err);
g_free(xml); return conf;
The xml data comes from libvirt, so it should be freed with free(), not g_free. The same comment applies to all the other hunks. Christophe
-#endif - return NULL; } diff --git a/libvirt-gobject/libvirt-gobject-interface.c b/libvirt-gobject/libvirt-gobject-interface.c index d35cdc2..e47395c 100644 --- a/libvirt-gobject/libvirt-gobject-interface.c +++ b/libvirt-gobject/libvirt-gobject-interface.c @@ -199,11 +199,8 @@ GVirConfigInterface *gvir_interface_get_config(GVirInterface *iface, return NULL; }
-#if 0 - GVirConfigInterface *conf = gvir_config_interface_new(xml); + GVirConfigInterface *conf = gvir_config_interface_new_from_xml(xml, err);
g_free(xml); return conf; -#endif - return NULL; } diff --git a/libvirt-gobject/libvirt-gobject-network-filter.c b/libvirt-gobject/libvirt-gobject-network-filter.c index 6ce0f7c..bdb0e3a 100644 --- a/libvirt-gobject/libvirt-gobject-network-filter.c +++ b/libvirt-gobject/libvirt-gobject-network-filter.c @@ -225,11 +225,8 @@ GVirConfigNetworkFilter *gvir_network_filter_get_config return NULL; }
-#if 0 - GVirConfigNetworkFilter *conf = gvir_config_network_filter_new(xml); + GVirConfigNetworkFilter *conf = gvir_config_network_filter_new_from_xml(xml, err);
g_free(xml); return conf; -#endif - return NULL; } diff --git a/libvirt-gobject/libvirt-gobject-network.c b/libvirt-gobject/libvirt-gobject-network.c index 237f788..c486561 100644 --- a/libvirt-gobject/libvirt-gobject-network.c +++ b/libvirt-gobject/libvirt-gobject-network.c @@ -221,11 +221,8 @@ GVirConfigNetwork *gvir_network_get_config(GVirNetwork *network, return NULL; }
-#if 0 - GVirConfigNetwork *conf = gvir_config_network_new(xml); + GVirConfigNetwork *conf = gvir_config_network_new_from_xml(xml, err);
g_free(xml); return conf; -#endif - return NULL; } diff --git a/libvirt-gobject/libvirt-gobject-node-device.c b/libvirt-gobject/libvirt-gobject-node-device.c index 162f930..43564b6 100644 --- a/libvirt-gobject/libvirt-gobject-node-device.c +++ b/libvirt-gobject/libvirt-gobject-node-device.c @@ -200,12 +200,8 @@ GVirConfigNodeDevice *gvir_node_device_get_config(GVirNodeDevice *device, return NULL; }
-#if 0 - GVirConfigNodeDevice *conf = gvir_config_node_device_new(xml); + GVirConfigNodeDevice *conf = gvir_config_node_device_new_from_xml(xml, err);
g_free(xml); return conf; -#endif - - return NULL; } diff --git a/libvirt-gobject/libvirt-gobject-secret.c b/libvirt-gobject/libvirt-gobject-secret.c index 5bde345..418e5aa 100644 --- a/libvirt-gobject/libvirt-gobject-secret.c +++ b/libvirt-gobject/libvirt-gobject-secret.c @@ -211,12 +211,8 @@ GVirConfigSecret *gvir_secret_get_config(GVirSecret *secret, return NULL; }
-#if 0 - GVirConfigSecret *conf = gvir_config_secret_new(xml); + GVirConfigSecret *conf = gvir_config_secret_new_from_xml(xml, err);
g_free(xml); return conf; -#endif - - return NULL; } diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c index 915e0a1..92be539 100644 --- a/libvirt-gobject/libvirt-gobject-storage-pool.c +++ b/libvirt-gobject/libvirt-gobject-storage-pool.c @@ -236,13 +236,10 @@ GVirConfigStoragePool *gvir_storage_pool_get_config(GVirStoragePool *pool, return NULL; }
-#if 0 - GVirConfigStoragePool *conf = gvir_config_storage_pool_new(xml); + GVirConfigStoragePool *conf = gvir_config_storage_pool_new_from_xml(xml, err);
g_free(xml); return conf; -#endif - return NULL; }
typedef gint (* CountFunction) (virStoragePoolPtr vpool); diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c b/libvirt-gobject/libvirt-gobject-storage-vol.c index a8aec60..17aac36 100644 --- a/libvirt-gobject/libvirt-gobject-storage-vol.c +++ b/libvirt-gobject/libvirt-gobject-storage-vol.c @@ -211,11 +211,8 @@ GVirConfigStorageVol *gvir_storage_vol_get_config(GVirStorageVol *vol, return NULL; }
-#if 0 - GVirConfigStorageVol *conf = gvir_config_storage_vol_new(xml); + GVirConfigStorageVol *conf = gvir_config_storage_vol_new_from_xml(xml, err);
g_free(xml); return conf; -#endif - return NULL; } -- 1.7.6.4
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Tue, Nov 22, 2011 at 02:19:44PM +0100, Christophe Fergeau wrote:
Hi,
On Tue, Nov 22, 2011 at 12:39:30PM +0000, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
--- libvirt-gobject/libvirt-gobject-domain-snapshot.c | 5 +---- libvirt-gobject/libvirt-gobject-interface.c | 5 +---- libvirt-gobject/libvirt-gobject-network-filter.c | 5 +---- libvirt-gobject/libvirt-gobject-network.c | 5 +---- libvirt-gobject/libvirt-gobject-node-device.c | 6 +----- libvirt-gobject/libvirt-gobject-secret.c | 6 +----- libvirt-gobject/libvirt-gobject-storage-pool.c | 5 +---- libvirt-gobject/libvirt-gobject-storage-vol.c | 5 +---- 8 files changed, 8 insertions(+), 34 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain-snapshot.c b/libvirt-gobject/libvirt-gobject-domain-snapshot.c index e536d72..c65a183 100644 --- a/libvirt-gobject/libvirt-gobject-domain-snapshot.c +++ b/libvirt-gobject/libvirt-gobject-domain-snapshot.c @@ -210,11 +210,8 @@ GVirConfigDomainSnapshot *gvir_domain_snapshot_get_config return NULL; }
-#if 0 - GVirConfigDomainSnapshot *conf = gvir_config_domain_snapshot_new(xml); + GVirConfigDomainSnapshot *conf = gvir_config_domain_snapshot_new_from_xml(xml, err);
g_free(xml); return conf;
The xml data comes from libvirt, so it should be freed with free(), not g_free. The same comment applies to all the other hunks.
Good point, I'll fix 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 :|

From: "Daniel P. Berrange" <berrange@redhat.com> --- libvirt-gobject/libvirt-gobject-connection.c | 49 ++++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 4 ++ 2 files changed, 53 insertions(+), 0 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index f52b825..b6e7f3b 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1164,6 +1164,10 @@ GVirStream *gvir_connection_get_stream(GVirConnection *self, * gvir_connection_create_domain: * @conn: the connection on which to create the dmain * @conf: the configuration for the new domain + * + * Create the configuration file for a new persistent domain. + * The returned domain will initially be in the shutoff state. + * * Returns: (transfer full): the newly created domain */ GVirDomain *gvir_connection_create_domain(GVirConnection *conn, @@ -1201,6 +1205,51 @@ GVirDomain *gvir_connection_create_domain(GVirConnection *conn, } /** + * gvir_connection_start_domain: + * @conn: the connection on which to create the dmain + * @conf: the configuration for the new domain + * + * Start a new transient domain without persistent configuration. + * The returned domain will initially be running. + * + * Returns: (transfer full): the newly created domain + */ +GVirDomain *gvir_connection_start_domain(GVirConnection *conn, + GVirConfigDomain *conf, + guint flags, + GError **err) +{ + const gchar *xml; + virDomainPtr handle; + GVirConnectionPrivate *priv = conn->priv; + + xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf)); + + g_return_val_if_fail(xml != NULL, NULL); + + if (!(handle = virDomainCreateXML(priv->conn, xml, flags))) { + *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR, + 0, + "Failed to create domain"); + return NULL; + } + + GVirDomain *domain; + + domain = GVIR_DOMAIN(g_object_new(GVIR_TYPE_DOMAIN, + "handle", handle, + NULL)); + + g_mutex_lock(priv->lock); + g_hash_table_insert(priv->domains, + (gpointer)gvir_domain_get_uuid(domain), + domain); + g_mutex_unlock(priv->lock); + + 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 diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h index 92a15ab..298009a 100644 --- a/libvirt-gobject/libvirt-gobject-connection.h +++ b/libvirt-gobject/libvirt-gobject-connection.h @@ -110,6 +110,10 @@ GVirDomain *gvir_connection_find_domain_by_name(GVirConnection *conn, GVirDomain *gvir_connection_create_domain(GVirConnection *conn, GVirConfigDomain *conf, GError **err); +GVirDomain *gvir_connection_start_domain(GVirConnection *conn, + GVirConfigDomain *conf, + guint flags, + GError **err); #if 0 GList *gvir_connection_get_interfaces(GVirConnection *conn); -- 1.7.6.4

Hey, On Tue, Nov 22, 2011 at 12:39:31PM +0000, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
--- libvirt-gobject/libvirt-gobject-connection.c | 49 ++++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 4 ++
No addition of the new function in libvirt-gobject.sym?
2 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index f52b825..b6e7f3b 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1164,6 +1164,10 @@ GVirStream *gvir_connection_get_stream(GVirConnection *self, * gvir_connection_create_domain: * @conn: the connection on which to create the dmain
domain
* @conf: the configuration for the new domain + * + * Create the configuration file for a new persistent domain. + * The returned domain will initially be in the shutoff state. + * * Returns: (transfer full): the newly created domain */ GVirDomain *gvir_connection_create_domain(GVirConnection *conn, @@ -1201,6 +1205,51 @@ GVirDomain *gvir_connection_create_domain(GVirConnection *conn, }
/** + * gvir_connection_start_domain: + * @conn: the connection on which to create the dmain
Same here, domain
+ * @conf: the configuration for the new domain + * + * Start a new transient domain without persistent configuration. + * The returned domain will initially be running. + * + * Returns: (transfer full): the newly created domain + */ +GVirDomain *gvir_connection_start_domain(GVirConnection *conn, + GVirConfigDomain *conf, + guint flags, + GError **err) +{ + const gchar *xml; + virDomainPtr handle; + GVirConnectionPrivate *priv = conn->priv; + + xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
xml shouldn't be const and need to be g_freed when it's no longer needed.
+ + g_return_val_if_fail(xml != NULL, NULL); + + if (!(handle = virDomainCreateXML(priv->conn, xml, flags))) { + *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR, + 0, + "Failed to create domain"); + return NULL; + } + + GVirDomain *domain; + + domain = GVIR_DOMAIN(g_object_new(GVIR_TYPE_DOMAIN, + "handle", handle, + NULL)); + + g_mutex_lock(priv->lock); + g_hash_table_insert(priv->domains, + (gpointer)gvir_domain_get_uuid(domain), + domain); + g_mutex_unlock(priv->lock); + + return g_object_ref(domain);
Here I'd do g_mutex_lock(priv->lock); g_hash_table_insert(priv->domains, (gpointer)gvir_domain_get_uuid(domain), g_object_ref(domain)); g_mutex_unlock(priv->lock); return domain; to make it clearer that the hash table needs a ref on the object. The way it's written, I had to check how priv->domains is declared to make sure that wasn't an extra _ref. Christophe
+} + +/** * gvir_connection_create_storage_pool: * @conn: the connection on which to create the pool * @conf: the configuration for the new storage pool diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h index 92a15ab..298009a 100644 --- a/libvirt-gobject/libvirt-gobject-connection.h +++ b/libvirt-gobject/libvirt-gobject-connection.h @@ -110,6 +110,10 @@ GVirDomain *gvir_connection_find_domain_by_name(GVirConnection *conn, GVirDomain *gvir_connection_create_domain(GVirConnection *conn, GVirConfigDomain *conf, GError **err); +GVirDomain *gvir_connection_start_domain(GVirConnection *conn, + GVirConfigDomain *conf, + guint flags, + GError **err);
#if 0 GList *gvir_connection_get_interfaces(GVirConnection *conn); -- 1.7.6.4
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Tue, Nov 22, 2011 at 02:07:23PM +0100, Christophe Fergeau wrote:
Hey,
On Tue, Nov 22, 2011 at 12:39:31PM +0000, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
--- libvirt-gobject/libvirt-gobject-connection.c | 49 ++++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 4 ++
No addition of the new function in libvirt-gobject.sym?
2 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index f52b825..b6e7f3b 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1164,6 +1164,10 @@ GVirStream *gvir_connection_get_stream(GVirConnection *self, * gvir_connection_create_domain: * @conn: the connection on which to create the dmain
domain
* @conf: the configuration for the new domain + * + * Create the configuration file for a new persistent domain. + * The returned domain will initially be in the shutoff state. + * * Returns: (transfer full): the newly created domain */ GVirDomain *gvir_connection_create_domain(GVirConnection *conn, @@ -1201,6 +1205,51 @@ GVirDomain *gvir_connection_create_domain(GVirConnection *conn, }
/** + * gvir_connection_start_domain: + * @conn: the connection on which to create the dmain
Same here, domain
Cut + paste typos :-)
+ * @conf: the configuration for the new domain + * + * Start a new transient domain without persistent configuration. + * The returned domain will initially be running. + * + * Returns: (transfer full): the newly created domain + */ +GVirDomain *gvir_connection_start_domain(GVirConnection *conn, + GVirConfigDomain *conf, + guint flags, + GError **err) +{ + const gchar *xml; + virDomainPtr handle; + GVirConnectionPrivate *priv = conn->priv; + + xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
xml shouldn't be const and need to be g_freed when it's no longer needed.
Oooh, gvir_connection_create_domain has the same flaw. I'll fix both.
+ + g_return_val_if_fail(xml != NULL, NULL); + + if (!(handle = virDomainCreateXML(priv->conn, xml, flags))) { + *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR, + 0, + "Failed to create domain"); + return NULL; + } + + GVirDomain *domain; + + domain = GVIR_DOMAIN(g_object_new(GVIR_TYPE_DOMAIN, + "handle", handle, + NULL)); + + g_mutex_lock(priv->lock); + g_hash_table_insert(priv->domains, + (gpointer)gvir_domain_get_uuid(domain), + domain); + g_mutex_unlock(priv->lock); + + return g_object_ref(domain);
Here I'd do g_mutex_lock(priv->lock); g_hash_table_insert(priv->domains, (gpointer)gvir_domain_get_uuid(domain), g_object_ref(domain)); g_mutex_unlock(priv->lock);
return domain;
to make it clearer that the hash table needs a ref on the object. The way it's written, I had to check how priv->domains is declared to make sure that wasn't an extra _ref.
Again this was a cut+past from gvir_connection_start_domain, so I'll change both to the style you describe. 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 :|

From: "Daniel P. Berrange" <berrange@redhat.com> --- libvirt-gobject/libvirt-gobject-connection.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index b6e7f3b..affb496 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -234,9 +234,15 @@ static void gvir_connection_init(GVirConnection *conn) priv = conn->priv = GVIR_CONNECTION_GET_PRIVATE(conn); - memset(priv, 0, sizeof(*priv)); - priv->lock = g_mutex_new(); + priv->domains = g_hash_table_new_full(g_str_hash, + g_str_equal, + NULL, + g_object_unref); + priv->pools = g_hash_table_new_full(g_str_hash, + g_str_equal, + NULL, + g_object_unref); } -- 1.7.6.4

Hi, I assume without this, it's easy to try to add data to NULL hash tables when using the transient domain API you added in this patch series? ACK patch, just curious... Christophe On Tue, Nov 22, 2011 at 12:39:32PM +0000, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
--- libvirt-gobject/libvirt-gobject-connection.c | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index b6e7f3b..affb496 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -234,9 +234,15 @@ static void gvir_connection_init(GVirConnection *conn)
priv = conn->priv = GVIR_CONNECTION_GET_PRIVATE(conn);
- memset(priv, 0, sizeof(*priv)); - priv->lock = g_mutex_new(); + priv->domains = g_hash_table_new_full(g_str_hash, + g_str_equal, + NULL, + g_object_unref); + priv->pools = g_hash_table_new_full(g_str_hash, + g_str_equal, + NULL, + g_object_unref); }
-- 1.7.6.4
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Tue, Nov 22, 2011 at 02:22:40PM +0100, Christophe Fergeau wrote:
Hi,
I assume without this, it's easy to try to add data to NULL hash tables when using the transient domain API you added in this patch series? ACK patch, just curious...
Actually the scenario was with persistent domains too conn = LibvirtGObject.Connection.new("qemu:///session") conn.open(None) conn.create_domain(domcfg) which would SEGV unless you had called conn.fetch_domains before conn.create_domain. 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)
-
Christophe Fergeau
-
Daniel P. Berrange