[libvirt] [libvirt-glib v3] gobject: Port to GTask API
by Zeeshan Ali (Khattak)
Drop usage of deprecated GSimpleAsyncResult API.
---
libvirt-gobject/libvirt-gobject-domain.c | 290 +++++++++---------------
libvirt-gobject/libvirt-gobject-input-stream.c | 77 +++----
libvirt-gobject/libvirt-gobject-output-stream.c | 75 +++---
libvirt-gobject/libvirt-gobject-storage-pool.c | 281 ++++++++++-------------
libvirt-gobject/libvirt-gobject-stream.c | 52 +++--
5 files changed, 322 insertions(+), 453 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
index 5509ce3..c768cd3 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -370,28 +370,20 @@ gboolean gvir_domain_start(GVirDomain *dom,
return TRUE;
}
-typedef struct {
- guint flags;
-} DomainStartData;
-
-static void domain_start_data_free(DomainStartData *data)
-{
- g_slice_free(DomainStartData, data);
-}
-
static void
-gvir_domain_start_helper(GSimpleAsyncResult *res,
- GObject *object,
+gvir_domain_start_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable G_GNUC_UNUSED)
{
- GVirDomain *dom = GVIR_DOMAIN(object);
- DomainStartData *data;
+ GVirDomain *dom = GVIR_DOMAIN(source_object);
+ guint flags = GPOINTER_TO_UINT(task_data);
GError *err = NULL;
- data = g_simple_async_result_get_op_res_gpointer(res);
-
- if (!gvir_domain_start(dom, data->flags, &err))
- g_simple_async_result_take_error(res, err);
+ if (!gvir_domain_start(dom, flags, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -410,25 +402,18 @@ void gvir_domain_start_async(GVirDomain *dom,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
- DomainStartData *data;
+ GTask *task;
g_return_if_fail(GVIR_IS_DOMAIN(dom));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
- data = g_slice_new0(DomainStartData);
- data->flags = flags;
-
- res = g_simple_async_result_new(G_OBJECT(dom),
- callback,
- user_data,
- gvir_domain_start_async);
- g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify)domain_start_data_free);
- g_simple_async_result_run_in_thread(res,
- gvir_domain_start_helper,
- G_PRIORITY_DEFAULT,
- cancellable);
- g_object_unref(res);
+ task = g_task_new(G_OBJECT(dom),
+ cancellable,
+ callback,
+ user_data);
+ g_task_set_task_data(task, GUINT_TO_POINTER(flags), NULL);
+ g_task_run_in_thread(task, gvir_domain_start_helper);
+ g_object_unref(task);
}
gboolean gvir_domain_start_finish(GVirDomain *dom,
@@ -436,13 +421,10 @@ gboolean gvir_domain_start_finish(GVirDomain *dom,
GError **err)
{
g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
- g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_start_async), FALSE);
+ g_return_val_if_fail(g_task_is_valid(result, dom), FALSE);
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
- if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
- return FALSE;
-
- return TRUE;
+ return g_task_propagate_boolean(G_TASK(result), err);
}
/**
@@ -472,15 +454,18 @@ gboolean gvir_domain_resume(GVirDomain *dom,
}
static void
-gvir_domain_resume_helper(GSimpleAsyncResult *res,
- GObject *object,
+gvir_domain_resume_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data G_GNUC_UNUSED,
GCancellable *cancellable G_GNUC_UNUSED)
{
- GVirDomain *dom = GVIR_DOMAIN(object);
+ GVirDomain *dom = GVIR_DOMAIN(source_object);
GError *err = NULL;
if (!gvir_domain_resume(dom, &err))
- g_simple_async_result_take_error(res, err);
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -497,20 +482,17 @@ void gvir_domain_resume_async(GVirDomain *dom,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
+ GTask *task;
g_return_if_fail(GVIR_IS_DOMAIN(dom));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
- res = g_simple_async_result_new(G_OBJECT(dom),
- callback,
- user_data,
- gvir_domain_resume_async);
- g_simple_async_result_run_in_thread(res,
- gvir_domain_resume_helper,
- G_PRIORITY_DEFAULT,
- cancellable);
- g_object_unref(res);
+ task = g_task_new(G_OBJECT(dom),
+ cancellable,
+ callback,
+ user_data);
+ g_task_run_in_thread(task, gvir_domain_resume_helper);
+ g_object_unref(task);
}
gboolean gvir_domain_resume_finish(GVirDomain *dom,
@@ -518,13 +500,10 @@ gboolean gvir_domain_resume_finish(GVirDomain *dom,
GError **err)
{
g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
- g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_resume_async), FALSE);
+ g_return_val_if_fail(g_task_is_valid(result, dom), FALSE);
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
- if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
- return FALSE;
-
- return TRUE;
+ return g_task_propagate_boolean(G_TASK(result), err);
}
/**
@@ -556,15 +535,19 @@ gboolean gvir_domain_wakeup(GVirDomain *dom,
}
static void
-gvir_domain_wakeup_helper(GSimpleAsyncResult *res,
- GObject *object,
+gvir_domain_wakeup_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable G_GNUC_UNUSED)
{
- GVirDomain *dom = GVIR_DOMAIN(object);
+ GVirDomain *dom = GVIR_DOMAIN(source_object);
+ guint flags = GPOINTER_TO_UINT(task_data);
GError *err = NULL;
- if (!gvir_domain_wakeup(dom, (guint)g_simple_async_result_get_op_res_gssize(res), &err))
- g_simple_async_result_take_error(res, err);
+ if (!gvir_domain_wakeup(dom, flags, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -583,21 +566,18 @@ void gvir_domain_wakeup_async(GVirDomain *dom,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
+ GTask *task;
g_return_if_fail(GVIR_IS_DOMAIN(dom));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
- res = g_simple_async_result_new(G_OBJECT(dom),
- callback,
- user_data,
- gvir_domain_wakeup_async);
- g_simple_async_result_set_op_res_gssize (res, (gssize)flags);
- g_simple_async_result_run_in_thread(res,
- gvir_domain_wakeup_helper,
- G_PRIORITY_DEFAULT,
- cancellable);
- g_object_unref(res);
+ task = g_task_new(G_OBJECT(dom),
+ cancellable,
+ callback,
+ user_data);
+ g_task_set_task_data(task, GUINT_TO_POINTER(flags), NULL);
+ g_task_run_in_thread(task, gvir_domain_wakeup_helper);
+ g_object_unref(task);
}
gboolean gvir_domain_wakeup_finish(GVirDomain *dom,
@@ -605,13 +585,10 @@ gboolean gvir_domain_wakeup_finish(GVirDomain *dom,
GError **err)
{
g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
- g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom), gvir_domain_wakeup_async), FALSE);
+ g_return_val_if_fail(g_task_is_valid(result, dom), FALSE);
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
- if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
- return FALSE;
-
- return TRUE;
+ return g_task_propagate_boolean(G_TASK(result), err);
}
/**
@@ -785,18 +762,19 @@ static void domain_save_to_file_data_free(DomainSaveToFileData *data)
}
static void
-gvir_domain_save_to_file_helper(GSimpleAsyncResult *res,
- GObject *object,
+gvir_domain_save_to_file_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable G_GNUC_UNUSED)
{
- GVirDomain *dom = GVIR_DOMAIN(object);
- DomainSaveToFileData *data;
+ GVirDomain *dom = GVIR_DOMAIN(source_object);
+ DomainSaveToFileData *data = (DomainSaveToFileData *) task_data;
GError *err = NULL;
- data = g_simple_async_result_get_op_res_gpointer(res);
-
if (!gvir_domain_save_to_file(dom, data->filename, data->custom_conf, data->flags, &err))
- g_simple_async_result_take_error(res, err);
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -819,7 +797,7 @@ void gvir_domain_save_to_file_async(GVirDomain *dom,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
+ GTask *task;
DomainSaveToFileData *data;
g_return_if_fail(GVIR_IS_DOMAIN(dom));
@@ -832,19 +810,15 @@ void gvir_domain_save_to_file_async(GVirDomain *dom,
data->custom_conf = g_object_ref(custom_conf);
data->flags = flags;
- res = g_simple_async_result_new(G_OBJECT(dom),
- callback,
- user_data,
- gvir_domain_save_to_file_async);
- g_simple_async_result_set_op_res_gpointer(res, data, (GDestroyNotify)
- domain_save_to_file_data_free);
-
- g_simple_async_result_run_in_thread(res,
- gvir_domain_save_to_file_helper,
- G_PRIORITY_DEFAULT,
- cancellable);
-
- g_object_unref(res);
+ task = g_task_new(G_OBJECT(dom),
+ cancellable,
+ callback,
+ user_data);
+ g_task_set_task_data(task,
+ data,
+ (GDestroyNotify) domain_save_to_file_data_free);
+ g_task_run_in_thread(task, gvir_domain_save_to_file_helper);
+ g_object_unref(task);
}
/**
@@ -862,16 +836,10 @@ gboolean gvir_domain_save_to_file_finish(GVirDomain *dom,
GError **err)
{
g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
- g_return_val_if_fail(g_simple_async_result_is_valid
- (result,
- G_OBJECT(dom),
- gvir_domain_save_to_file_async), FALSE);
+ g_return_val_if_fail(g_task_is_valid(result, dom), FALSE);
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
- if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
- return FALSE;
-
- return TRUE;
+ return g_task_propagate_boolean(G_TASK(result), err);
}
/**
@@ -1012,22 +980,22 @@ GVirDomainInfo *gvir_domain_get_info(GVirDomain *dom,
}
static void
-gvir_domain_get_info_helper(GSimpleAsyncResult *res,
- GObject *object,
+gvir_domain_get_info_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data G_GNUC_UNUSED,
GCancellable *cancellable G_GNUC_UNUSED)
{
- GVirDomain *dom = GVIR_DOMAIN(object);
+ GVirDomain *dom = GVIR_DOMAIN(source_object);
GVirDomainInfo *info;
GError *err = NULL;
info = gvir_domain_get_info(dom, &err);
if (err)
- g_simple_async_result_take_error(res, err);
+ g_task_return_error(task, err);
else
- g_simple_async_result_set_op_res_gpointer
- (res,
- info,
- (GDestroyNotify) gvir_domain_info_free);
+ g_task_return_pointer(task,
+ info,
+ (GDestroyNotify) gvir_domain_info_free);
}
/**
@@ -1044,20 +1012,17 @@ void gvir_domain_get_info_async(GVirDomain *dom,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
+ GTask *task;
g_return_if_fail(GVIR_IS_DOMAIN(dom));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
- res = g_simple_async_result_new(G_OBJECT(dom),
- callback,
- user_data,
- gvir_domain_get_info_async);
- g_simple_async_result_run_in_thread(res,
- gvir_domain_get_info_helper,
- G_PRIORITY_DEFAULT,
- cancellable);
- g_object_unref(res);
+ task = g_task_new(G_OBJECT(dom),
+ cancellable,
+ callback,
+ user_data);
+ g_task_run_in_thread(task, gvir_domain_get_info_helper);
+ g_object_unref(task);
}
/**
@@ -1075,22 +1040,11 @@ GVirDomainInfo *gvir_domain_get_info_finish(GVirDomain *dom,
GAsyncResult *result,
GError **err)
{
- GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT(result);
- GVirDomainInfo *ret;
-
g_return_val_if_fail(GVIR_IS_DOMAIN(dom), NULL);
- g_return_val_if_fail
- (g_simple_async_result_is_valid(result,
- G_OBJECT(dom),
- gvir_domain_get_info_async),
- NULL);
-
- if (g_simple_async_result_propagate_error(res, err))
- return NULL;
-
- ret = g_simple_async_result_get_op_res_gpointer(res);
+ g_return_val_if_fail(g_task_is_valid(result, dom), NULL);
+ g_return_val_if_fail(err == NULL || *err == NULL, NULL);
- return gvir_domain_info_copy (ret);
+ return g_task_propagate_pointer(G_TASK(result), err);
}
/**
@@ -1365,28 +1319,20 @@ gboolean gvir_domain_save (GVirDomain *dom,
return TRUE;
}
-typedef struct {
- guint flags;
-} DomainSaveData;
-
-static void domain_save_data_free(DomainSaveData *data)
-{
- g_slice_free (DomainSaveData, data);
-}
-
static void
-gvir_domain_save_helper(GSimpleAsyncResult *res,
- GObject *object,
+gvir_domain_save_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable G_GNUC_UNUSED)
{
- GVirDomain *dom = GVIR_DOMAIN(object);
- DomainSaveData *data;
+ GVirDomain *dom = GVIR_DOMAIN(source_object);
+ guint flags = GPOINTER_TO_UINT(task_data);
GError *err = NULL;
- data = g_simple_async_result_get_op_res_gpointer (res);
-
- if (!gvir_domain_save(dom, data->flags, &err))
- g_simple_async_result_take_error(res, err);
+ if (!gvir_domain_save(dom, flags, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -1405,25 +1351,18 @@ void gvir_domain_save_async (GVirDomain *dom,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
- DomainSaveData *data;
+ GTask *task;
g_return_if_fail(GVIR_IS_DOMAIN(dom));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
- data = g_slice_new0(DomainSaveData);
- data->flags = flags;
-
- res = g_simple_async_result_new(G_OBJECT(dom),
- callback,
- user_data,
- gvir_domain_save_async);
- g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify) domain_save_data_free);
- g_simple_async_result_run_in_thread(res,
- gvir_domain_save_helper,
- G_PRIORITY_DEFAULT,
- cancellable);
- g_object_unref(res);
+ task = g_task_new(G_OBJECT(dom),
+ cancellable,
+ callback,
+ user_data);
+ g_task_set_task_data(task, GUINT_TO_POINTER(flags), NULL);
+ g_task_run_in_thread(task, gvir_domain_save_helper);
+ g_object_unref(task);
}
/**
@@ -1441,15 +1380,10 @@ gboolean gvir_domain_save_finish (GVirDomain *dom,
GError **err)
{
g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
- g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(dom),
- gvir_domain_save_async),
- FALSE);
+ g_return_val_if_fail(g_task_is_valid(result, dom), FALSE);
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
- if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
- return FALSE;
-
- return TRUE;
+ return g_task_propagate_boolean(G_TASK(result), err);
}
/**
@@ -1682,6 +1616,7 @@ GVirDomainSnapshot *gvir_domain_create_snapshot_finish(GVirDomain *domain,
GError **error)
{
g_return_val_if_fail(g_task_is_valid(result, domain), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
return g_task_propagate_pointer(G_TASK(result), error);
}
@@ -1847,6 +1782,7 @@ gboolean gvir_domain_fetch_snapshots_finish(GVirDomain *dom,
{
g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
g_return_val_if_fail(g_task_is_valid(res, dom), FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
return g_task_propagate_boolean(G_TASK(res), error);
}
diff --git a/libvirt-gobject/libvirt-gobject-input-stream.c b/libvirt-gobject/libvirt-gobject-input-stream.c
index ff1a70c..cd107e1 100644
--- a/libvirt-gobject/libvirt-gobject-input-stream.c
+++ b/libvirt-gobject/libvirt-gobject-input-stream.c
@@ -45,8 +45,7 @@ struct _GVirInputStreamPrivate
GVirStream *stream;
/* pending operation metadata */
- GSimpleAsyncResult *result;
- GCancellable *cancellable;
+ GTask *task;
gpointer buffer;
gsize count;
};
@@ -103,48 +102,44 @@ gvir_input_stream_read_ready(GVirStream *stream,
{
GVirInputStream *input_stream = GVIR_INPUT_STREAM(opaque);
GVirInputStreamPrivate *priv = input_stream->priv;
- GSimpleAsyncResult *simple = priv->result;
+ GTask *task = priv->task;
+ GCancellable *cancellable = g_task_get_cancellable(task);
GError *error = NULL;
gssize result;
+ priv->task = NULL;
+
if (!(cond & GVIR_STREAM_IO_CONDITION_READABLE)) {
g_warn_if_reached();
- g_simple_async_result_set_error(simple,
- G_IO_ERROR,
- G_IO_ERROR_INVALID_ARGUMENT,
- "%s",
- "Expected stream to be readable");
+ g_task_return_new_error(task,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ "%s",
+ "Expected stream to be readable");
goto cleanup;
}
- result = gvir_stream_receive(stream, priv->buffer, priv->count,
- priv->cancellable, &error);
+ result = gvir_stream_receive(stream, priv->buffer, priv->count,
+ cancellable, &error);
+ if (error != NULL) {
+ if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
+ g_warn_if_reached();
+ g_task_return_new_error(task,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ "%s",
+ "Expected stream to be readable");
+ } else {
+ g_task_return_error(task, error);
+ }
- if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
- g_warn_if_reached();
- g_simple_async_result_set_error(simple,
- G_IO_ERROR,
- G_IO_ERROR_INVALID_ARGUMENT,
- "%s",
- "Expected stream to be readable");
goto cleanup;
}
- 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(priv->cancellable);
- priv->cancellable = NULL;
- }
+ g_task_return_int(task, result);
cleanup:
- priv->result = NULL;
- g_simple_async_result_complete(simple);
- g_object_unref(simple);
+ g_object_unref(task);
return FALSE;
}
@@ -159,7 +154,7 @@ static void gvir_input_stream_read_async(GInputStream *stream,
GVirInputStream *input_stream = GVIR_INPUT_STREAM(stream);
g_return_if_fail(GVIR_IS_INPUT_STREAM(stream));
- g_return_if_fail(input_stream->priv->result == NULL);
+ g_return_if_fail(input_stream->priv->task == NULL);
gvir_stream_add_watch_full(input_stream->priv->stream,
G_PRIORITY_DEFAULT,
@@ -168,12 +163,8 @@ static void gvir_input_stream_read_async(GInputStream *stream,
g_object_ref(stream),
(GDestroyNotify)g_object_unref);
- input_stream->priv->result =
- g_simple_async_result_new(G_OBJECT(stream), callback, user_data,
- gvir_input_stream_read_async);
- if (cancellable)
- g_object_ref(cancellable);
- input_stream->priv->cancellable = cancellable;
+ input_stream->priv->task =
+ g_task_new(stream, cancellable, callback, user_data);
input_stream->priv->buffer = buffer;
input_stream->priv->count = count;
}
@@ -181,22 +172,18 @@ static void gvir_input_stream_read_async(GInputStream *stream,
static gssize gvir_input_stream_read_finish(GInputStream *stream,
GAsyncResult *result,
- GError **error G_GNUC_UNUSED)
+ GError **error)
{
GVirInputStream *input_stream = GVIR_INPUT_STREAM(stream);
- GSimpleAsyncResult *simple;
virStreamPtr handle;
gssize count;
g_return_val_if_fail(GVIR_IS_INPUT_STREAM(stream), -1);
- g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(stream),
- gvir_input_stream_read_async),
- -1);
+ g_return_val_if_fail(g_task_is_valid(result, stream), -1);
+ g_return_val_if_fail(error == NULL || *error == NULL, -1);
g_object_get(input_stream->priv->stream, "handle", &handle, NULL);
- simple = G_SIMPLE_ASYNC_RESULT(result);
-
- count = g_simple_async_result_get_op_res_gssize(simple);
+ count = g_task_propagate_int(G_TASK(result), error);
virStreamFree(handle);
diff --git a/libvirt-gobject/libvirt-gobject-output-stream.c b/libvirt-gobject/libvirt-gobject-output-stream.c
index f39328b..a9c1236 100644
--- a/libvirt-gobject/libvirt-gobject-output-stream.c
+++ b/libvirt-gobject/libvirt-gobject-output-stream.c
@@ -45,8 +45,7 @@ struct _GVirOutputStreamPrivate
GVirStream *stream;
/* pending operation metadata */
- GSimpleAsyncResult *result;
- GCancellable *cancellable;
+ GTask *task;
const void * buffer;
gsize count;
};
@@ -103,48 +102,44 @@ gvir_output_stream_write_ready(GVirStream *stream,
{
GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(opaque);
GVirOutputStreamPrivate *priv = output_stream->priv;
- GSimpleAsyncResult *simple = priv->result;
+ GTask *task = priv->task;
+ GCancellable *cancellable = g_task_get_cancellable(task);
GError *error = NULL;
gssize result;
if (!(cond & GVIR_STREAM_IO_CONDITION_WRITABLE)) {
g_warn_if_reached();
- g_simple_async_result_set_error(simple,
- G_IO_ERROR,
- G_IO_ERROR_INVALID_ARGUMENT,
- "%s",
- "Expected stream to be writable");
+ g_task_return_new_error(task,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ "%s",
+ "Expected stream to be readable");
goto cleanup;
}
result = gvir_stream_send(stream, priv->buffer, priv->count,
- priv->cancellable, &error);
+ cancellable, &error);
+
+ if (error != NULL) {
+ if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
+ g_warn_if_reached();
+ g_task_return_new_error(task,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_ARGUMENT,
+ "%s",
+ "Expected stream to be writable");
+ } else {
+ g_task_return_error(task, error);
+ }
- if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
- g_warn_if_reached();
- g_simple_async_result_set_error(simple,
- G_IO_ERROR,
- G_IO_ERROR_INVALID_ARGUMENT,
- "%s",
- "Expected stream to be writable");
goto cleanup;
}
- 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(priv->cancellable);
- priv->cancellable = NULL;
- }
+ g_task_return_int(task, result);
cleanup:
- priv->result = NULL;
- g_simple_async_result_complete(simple);
- g_object_unref(simple);
+ priv->task = NULL;
+ g_object_unref(task);
return FALSE;
}
@@ -159,7 +154,7 @@ static void gvir_output_stream_write_async(GOutputStream *stream,
GVirOutputStream *output_stream = GVIR_OUTPUT_STREAM(stream);
g_return_if_fail(GVIR_IS_OUTPUT_STREAM(stream));
- g_return_if_fail(output_stream->priv->result == NULL);
+ g_return_if_fail(output_stream->priv->task == NULL);
gvir_stream_add_watch_full(output_stream->priv->stream,
G_PRIORITY_DEFAULT,
@@ -168,12 +163,8 @@ static void gvir_output_stream_write_async(GOutputStream *stream,
g_object_ref(stream),
(GDestroyNotify)g_object_unref);
- 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->task =
+ g_task_new(stream, cancellable, callback, user_data);
output_stream->priv->buffer = buffer;
output_stream->priv->count = count;
}
@@ -181,22 +172,18 @@ static void gvir_output_stream_write_async(GOutputStream *stream,
static gssize gvir_output_stream_write_finish(GOutputStream *stream,
GAsyncResult *result,
- GError **error G_GNUC_UNUSED)
+ GError **error)
{
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_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(stream),
- gvir_output_stream_write_async),
- -1);
+ g_return_val_if_fail(g_task_is_valid(result, stream), -1);
+ g_return_val_if_fail(error == NULL || *error == NULL, -1);
g_object_get(output_stream->priv->stream, "handle", &handle, NULL);
- simple = G_SIMPLE_ASYNC_RESULT(result);
-
- count = g_simple_async_result_get_op_res_gssize(simple);
+ count = g_task_propagate_int(G_TASK(result), error);
virStreamFree(handle);
diff --git a/libvirt-gobject/libvirt-gobject-storage-pool.c b/libvirt-gobject/libvirt-gobject-storage-pool.c
index a0dcebc..6290fcb 100644
--- a/libvirt-gobject/libvirt-gobject-storage-pool.c
+++ b/libvirt-gobject/libvirt-gobject-storage-pool.c
@@ -439,17 +439,18 @@ cleanup:
}
static void
-gvir_storage_pool_refresh_helper(GSimpleAsyncResult *res,
- GObject *object,
+gvir_storage_pool_refresh_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data G_GNUC_UNUSED,
GCancellable *cancellable)
{
- GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
+ GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
GError *err = NULL;
- if (!gvir_storage_pool_refresh(pool, cancellable, &err)) {
- g_simple_async_result_set_from_error(res, err);
- g_error_free(err);
- }
+ if (!gvir_storage_pool_refresh(pool, cancellable, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -464,20 +465,17 @@ void gvir_storage_pool_refresh_async(GVirStoragePool *pool,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
+ GTask *task;
g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
- res = g_simple_async_result_new(G_OBJECT(pool),
- callback,
- user_data,
- gvir_storage_pool_refresh_async);
- g_simple_async_result_run_in_thread(res,
- gvir_storage_pool_refresh_helper,
- G_PRIORITY_DEFAULT,
- cancellable);
- g_object_unref(res);
+ task = g_task_new(G_OBJECT(pool),
+ cancellable,
+ callback,
+ user_data);
+ g_task_run_in_thread(task, gvir_storage_pool_refresh_helper);
+ g_object_unref(task);
}
/**
@@ -490,15 +488,10 @@ gboolean gvir_storage_pool_refresh_finish(GVirStoragePool *pool,
GError **err)
{
g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
- g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
- gvir_storage_pool_refresh_async),
- FALSE);
-
- if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
- err))
- return FALSE;
+ g_return_val_if_fail(g_task_is_valid(result, pool), FALSE);
+ g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
- return TRUE;
+ return g_task_propagate_boolean(G_TASK(result), err);
}
static void gvir_storage_vol_ref(gpointer obj, gpointer ignore G_GNUC_UNUSED)
@@ -658,24 +651,25 @@ typedef struct {
guint flags;
} StoragePoolBuildData;
+static void storage_pool_build_data_free(StoragePoolBuildData *data)
+{
+ g_slice_free(StoragePoolBuildData, data);
+}
+
static void
-gvir_storage_pool_build_helper(GSimpleAsyncResult *res,
- GObject *object,
+gvir_storage_pool_build_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable G_GNUC_UNUSED)
{
- GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
- StoragePoolBuildData *data;
+ GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
+ StoragePoolBuildData *data = (StoragePoolBuildData *) task_data;
GError *err = NULL;
- data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res),
- "StoragePoolBuildData");
-
- if (!gvir_storage_pool_build(pool, data->flags, &err)) {
- g_simple_async_result_set_from_error(res, err);
- g_error_free(err);
- }
-
- g_slice_free (StoragePoolBuildData, data);
+ if (!gvir_storage_pool_build(pool, data->flags, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -692,7 +686,7 @@ void gvir_storage_pool_build_async (GVirStoragePool *pool,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
+ GTask *task;
StoragePoolBuildData *data;
g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
@@ -701,16 +695,13 @@ void gvir_storage_pool_build_async (GVirStoragePool *pool,
data = g_slice_new0(StoragePoolBuildData);
data->flags = flags;
- res = g_simple_async_result_new(G_OBJECT(pool),
- callback,
- user_data,
- gvir_storage_pool_build_async);
- g_object_set_data(G_OBJECT(res), "StoragePoolBuildData", data);
- g_simple_async_result_run_in_thread(res,
- gvir_storage_pool_build_helper,
- G_PRIORITY_DEFAULT,
- cancellable);
- g_object_unref(res);
+ task = g_task_new(G_OBJECT(pool),
+ cancellable,
+ callback,
+ user_data);
+ g_task_set_task_data(task, data, (GDestroyNotify)storage_pool_build_data_free);
+ g_task_run_in_thread(task, gvir_storage_pool_build_helper);
+ g_object_unref(task);
}
/**
@@ -726,16 +717,10 @@ gboolean gvir_storage_pool_build_finish(GVirStoragePool *pool,
GError **err)
{
g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
- g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
- gvir_storage_pool_build_async),
- FALSE);
+ g_return_val_if_fail(g_task_is_valid(result, pool), FALSE);
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
- if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
- err))
- return FALSE;
-
- return TRUE;
+ return g_task_propagate_boolean(G_TASK(result), err);
}
/**
@@ -762,17 +747,18 @@ gboolean gvir_storage_pool_undefine (GVirStoragePool *pool,
}
static void
-gvir_storage_pool_undefine_helper(GSimpleAsyncResult *res,
- GObject *object,
+gvir_storage_pool_undefine_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data G_GNUC_UNUSED,
GCancellable *cancellable G_GNUC_UNUSED)
{
- GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
+ GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
GError *err = NULL;
- if (!gvir_storage_pool_undefine(pool, &err)) {
- g_simple_async_result_set_from_error(res, err);
- g_error_free(err);
- }
+ if (!gvir_storage_pool_undefine(pool, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -787,20 +773,17 @@ void gvir_storage_pool_undefine_async (GVirStoragePool *pool,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
+ GTask *task;
g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
- res = g_simple_async_result_new(G_OBJECT(pool),
- callback,
- user_data,
- gvir_storage_pool_undefine_async);
- g_simple_async_result_run_in_thread(res,
- gvir_storage_pool_undefine_helper,
- G_PRIORITY_DEFAULT,
- cancellable);
- g_object_unref(res);
+ task = g_task_new(G_OBJECT(pool),
+ cancellable,
+ callback,
+ user_data);
+ g_task_run_in_thread(task, gvir_storage_pool_undefine_helper);
+ g_object_unref(task);
}
/**
@@ -816,16 +799,10 @@ gboolean gvir_storage_pool_undefine_finish(GVirStoragePool *pool,
GError **err)
{
g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
- g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
- gvir_storage_pool_undefine_async),
- FALSE);
+ g_return_val_if_fail(g_task_is_valid(result, pool), FALSE);
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
- if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
- err))
- return FALSE;
-
- return TRUE;
+ return g_task_propagate_boolean(G_TASK(result), err);
}
/**
@@ -854,23 +831,21 @@ gboolean gvir_storage_pool_start (GVirStoragePool *pool,
}
static void
-gvir_storage_pool_start_helper(GSimpleAsyncResult *res,
- GObject *object,
+gvir_storage_pool_start_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable G_GNUC_UNUSED)
{
- GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
+ GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
StoragePoolBuildData *data;
GError *err = NULL;
- data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res),
- "StoragePoolBuildData");
+ data = (StoragePoolBuildData *) task_data;
- if (!gvir_storage_pool_start(pool, data->flags, &err)) {
- g_simple_async_result_set_from_error(res, err);
- g_error_free(err);
- }
-
- g_slice_free (StoragePoolBuildData, data);
+ if (!gvir_storage_pool_start(pool, data->flags, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -887,7 +862,7 @@ void gvir_storage_pool_start_async (GVirStoragePool *pool,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
+ GTask *task;
StoragePoolBuildData *data;
g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
@@ -896,16 +871,13 @@ void gvir_storage_pool_start_async (GVirStoragePool *pool,
data = g_slice_new0(StoragePoolBuildData);
data->flags = flags;
- res = g_simple_async_result_new(G_OBJECT(pool),
- callback,
- user_data,
- gvir_storage_pool_start_async);
- g_object_set_data(G_OBJECT(res), "StoragePoolBuildData", data);
- g_simple_async_result_run_in_thread(res,
- gvir_storage_pool_start_helper,
- G_PRIORITY_DEFAULT,
- cancellable);
- g_object_unref(res);
+ task = g_task_new(G_OBJECT(pool),
+ cancellable,
+ callback,
+ user_data);
+ g_task_set_task_data(task, data, (GDestroyNotify)storage_pool_build_data_free);
+ g_task_run_in_thread(task, gvir_storage_pool_start_helper);
+ g_object_unref(task);
}
/**
@@ -921,16 +893,10 @@ gboolean gvir_storage_pool_start_finish(GVirStoragePool *pool,
GError **err)
{
g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
- g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
- gvir_storage_pool_start_async),
- FALSE);
+ g_return_val_if_fail(g_task_is_valid(result, pool), FALSE);
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
- if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
- err))
- return FALSE;
-
- return TRUE;
+ return g_task_propagate_boolean(G_TASK(result), err);
}
/**
@@ -957,17 +923,18 @@ gboolean gvir_storage_pool_stop (GVirStoragePool *pool,
}
static void
-gvir_storage_pool_stop_helper(GSimpleAsyncResult *res,
- GObject *object,
+gvir_storage_pool_stop_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data G_GNUC_UNUSED,
GCancellable *cancellable G_GNUC_UNUSED)
{
- GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
+ GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
GError *err = NULL;
- if (!gvir_storage_pool_stop(pool, &err)) {
- g_simple_async_result_set_from_error(res, err);
- g_error_free(err);
- }
+ if (!gvir_storage_pool_stop(pool, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -982,20 +949,17 @@ void gvir_storage_pool_stop_async (GVirStoragePool *pool,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
+ GTask *task;
g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
- res = g_simple_async_result_new(G_OBJECT(pool),
- callback,
- user_data,
- gvir_storage_pool_stop_async);
- g_simple_async_result_run_in_thread(res,
- gvir_storage_pool_stop_helper,
- G_PRIORITY_DEFAULT,
- cancellable);
- g_object_unref(res);
+ task = g_task_new(G_OBJECT(pool),
+ cancellable,
+ callback,
+ user_data);
+ g_task_run_in_thread(task, gvir_storage_pool_stop_helper);
+ g_object_unref(task);
}
/**
@@ -1011,16 +975,10 @@ gboolean gvir_storage_pool_stop_finish(GVirStoragePool *pool,
GError **err)
{
g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
- g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
- gvir_storage_pool_stop_async),
- FALSE);
+ g_return_val_if_fail(g_task_is_valid(result, pool), FALSE);
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
- if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
- err))
- return FALSE;
-
- return TRUE;
+ return g_task_propagate_boolean(G_TASK(result), err);
}
/**
@@ -1100,23 +1058,21 @@ gboolean gvir_storage_pool_set_autostart(GVirStoragePool *pool,
}
static void
-gvir_storage_pool_delete_helper(GSimpleAsyncResult *res,
- GObject *object,
+gvir_storage_pool_delete_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable G_GNUC_UNUSED)
{
- GVirStoragePool *pool = GVIR_STORAGE_POOL(object);
+ GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
StoragePoolBuildData *data;
GError *err = NULL;
- data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res),
- "StoragePoolBuildData");
+ data = (StoragePoolBuildData *) task_data;
- if (!gvir_storage_pool_delete(pool, data->flags, &err)) {
- g_simple_async_result_set_from_error(res, err);
- g_error_free(err);
- }
-
- g_slice_free (StoragePoolBuildData, data);
+ if (!gvir_storage_pool_delete(pool, data->flags, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -1133,7 +1089,7 @@ void gvir_storage_pool_delete_async (GVirStoragePool *pool,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
+ GTask *task;
StoragePoolBuildData *data;
g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
@@ -1142,16 +1098,13 @@ void gvir_storage_pool_delete_async (GVirStoragePool *pool,
data = g_slice_new0(StoragePoolBuildData);
data->flags = flags;
- res = g_simple_async_result_new(G_OBJECT(pool),
- callback,
- user_data,
- gvir_storage_pool_delete_async);
- g_object_set_data(G_OBJECT(res), "StoragePoolBuildData", data);
- g_simple_async_result_run_in_thread(res,
- gvir_storage_pool_delete_helper,
- G_PRIORITY_DEFAULT,
- cancellable);
- g_object_unref(res);
+ task = g_task_new(G_OBJECT(pool),
+ cancellable,
+ callback,
+ user_data);
+ g_task_set_task_data(task, data, (GDestroyNotify)storage_pool_build_data_free);
+ g_task_run_in_thread(task, gvir_storage_pool_delete_helper);
+ g_object_unref(task);
}
/**
@@ -1167,16 +1120,10 @@ gboolean gvir_storage_pool_delete_finish(GVirStoragePool *pool,
GError **err)
{
g_return_val_if_fail(GVIR_IS_STORAGE_POOL(pool), FALSE);
- g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(pool),
- gvir_storage_pool_delete_async),
- FALSE);
+ g_return_val_if_fail(g_task_is_valid(result, pool), FALSE);
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
- if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result),
- err))
- return FALSE;
-
- return TRUE;
+ return g_task_propagate_boolean(G_TASK(result), err);
}
G_GNUC_INTERNAL void gvir_storage_pool_delete_vol(GVirStoragePool *pool,
diff --git a/libvirt-gobject/libvirt-gobject-stream.c b/libvirt-gobject/libvirt-gobject-stream.c
index 46dbd9a..a40ac99 100644
--- a/libvirt-gobject/libvirt-gobject-stream.c
+++ b/libvirt-gobject/libvirt-gobject-stream.c
@@ -129,14 +129,13 @@ static gboolean gvir_stream_close(GIOStream *io_stream,
return (i_ret && o_ret);
}
-
-static void gvir_stream_close_async(GIOStream *stream,
- int io_priority G_GNUC_UNUSED,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+static void
+gvir_stream_close_helper(GTask *task,
+ gpointer source_object,
+ gpointer task_data G_GNUC_UNUSED,
+ GCancellable *cancellable)
{
- GSimpleAsyncResult *res;
+ GIOStream *stream = G_IO_STREAM(source_object);
GIOStreamClass *class;
GError *error;
@@ -146,27 +145,40 @@ static void gvir_stream_close_async(GIOStream *stream,
error = NULL;
if (class->close_fn &&
!class->close_fn(stream, cancellable, &error)) {
- g_simple_async_report_take_gerror_in_idle(G_OBJECT (stream),
- callback, user_data,
- error);
+ g_task_return_error(task, error);
return;
}
- res = g_simple_async_result_new(G_OBJECT (stream),
- callback,
- user_data,
- gvir_stream_close_async);
- g_simple_async_result_complete_in_idle(res);
- g_object_unref (res);
+ g_task_return_boolean(task, TRUE);
+}
+
+static void gvir_stream_close_async(GIOStream *stream,
+ int io_priority G_GNUC_UNUSED,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+
+ task = g_task_new(G_OBJECT(stream),
+ cancellable,
+ callback,
+ user_data);
+ g_task_run_in_thread(task, gvir_stream_close_helper);
+ g_object_unref(task);
}
static gboolean
-gvir_stream_close_finish(GIOStream *stream G_GNUC_UNUSED,
- GAsyncResult *result G_GNUC_UNUSED,
- GError **error G_GNUC_UNUSED)
+gvir_stream_close_finish(GIOStream *stream,
+ GAsyncResult *result,
+ GError **error)
{
- return TRUE;
+ g_return_val_if_fail(GVIR_IS_STREAM(stream), -1);
+ g_return_val_if_fail(g_task_is_valid(result, stream), -1);
+ g_return_val_if_fail(error == NULL || *error == NULL, -1);
+
+ return g_task_propagate_boolean(G_TASK(result), error);
}
--
2.5.0
9 years
[libvirt] [PATCH] storage: Ignore block devices that fail format detection
by John Ferlan
https://bugzilla.redhat.com/show_bug.cgi?id=1276198
Prior to commit id '98322052' failure to saferead the block device would
cause an error to be logged and the device to be skipped while attempting
to discover/create a stable target path for a new LUN (NPIV).
This was because virStorageBackendSCSIFindLUs ignored errors from
processLU and virStorageBackendSCSINewLun.
Ignoring the failure allowed a multipath device with an "active" and
"ghost" to be present on the host with the "ghost" block device being
ignored. This patch will return a -2 to the caller indicating the desire
to ignore the block device since it cannot be used directly rather than
fail the pool startup.
Additionally, it was found during some debugging that it was possible
for the virStorageBackendDetectBlockVolFormatFD to not detect a format,
which while not a probably - we probably should at least add some sort
of warning message.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/storage/storage_backend.c | 4 ++++
src/storage/storage_backend_scsi.c | 7 ++++++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index a375fe0..2de606f 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -1393,6 +1393,10 @@ virStorageBackendDetectBlockVolFormatFD(virStorageSourcePtr target,
}
}
+ if (target->format == VIR_STORAGE_POOL_DISK_UNKNOWN)
+ VIR_WARN("cannot determine the target format for '%s'",
+ target->path);
+
return 0;
}
diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
index a593a2b..d60473d 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -224,9 +224,14 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
goto cleanup;
}
+ /* Failing to process the format is not fatal - we'll just skip
+ * this volume.
+ */
if (virStorageBackendUpdateVolInfo(vol, true,
- VIR_STORAGE_VOL_OPEN_DEFAULT) < 0)
+ VIR_STORAGE_VOL_OPEN_DEFAULT) < 0) {
+ retval = -2;
goto cleanup;
+ }
if (!(vol->key = virStorageBackendSCSISerial(vol->target.path)))
goto cleanup;
--
2.1.0
9 years
[libvirt] [PATCH 0/6] Add virtio-gpu & virgl support
by Marc-André Lureau
The following series allow using virtio-gpu and virgl if qemu support
it. Ths Spice bits are not yet in qemu 2.5, but should make it in 2.6
and I added the RFC patches that are expected to not change much.
Marc-André Lureau (6):
qemu: add virtio video device
qemu: query virtio-gpu for virgl support
tests: add qemu 2.5 caps test
tests: add a few qemuxml2argv virtio-gpu tests
RFC qemu: add spice opengl support
RFC tests: add virgl/spice qemuxml2argv test
docs/formatdomain.html.in | 11 +-
docs/schemas/domaincommon.rng | 6 +
src/conf/domain_conf.c | 14 +-
src/conf/domain_conf.h | 2 +
src/qemu/qemu_capabilities.c | 21 +
src/qemu/qemu_capabilities.h | 5 +
src/qemu/qemu_command.c | 44 +-
tests/qemucapabilitiesdata/caps_1.2.2-1.replies | 22 +-
tests/qemucapabilitiesdata/caps_1.3.1-1.replies | 22 +-
tests/qemucapabilitiesdata/caps_1.4.2-1.replies | 22 +-
tests/qemucapabilitiesdata/caps_1.5.3-1.replies | 22 +-
tests/qemucapabilitiesdata/caps_1.6.0-1.replies | 22 +-
tests/qemucapabilitiesdata/caps_1.6.50-1.replies | 22 +-
tests/qemucapabilitiesdata/caps_2.1.1-1.replies | 22 +-
tests/qemucapabilitiesdata/caps_2.4.0-1.caps | 3 +
tests/qemucapabilitiesdata/caps_2.4.0-1.replies | 95 +-
tests/qemucapabilitiesdata/caps_2.5.0-1.caps | 170 +
tests/qemucapabilitiesdata/caps_2.5.0-1.replies | 4043 ++++++++++++++++++++
tests/qemucapabilitiestest.c | 1 +
.../qemuxml2argv-video-virtio-gpu-device.args | 23 +
.../qemuxml2argv-video-virtio-gpu-device.xml | 29 +
.../qemuxml2argv-video-virtio-gpu-nodevice.args | 24 +
.../qemuxml2argv-video-virtio-gpu-nodevice.xml | 29 +
.../qemuxml2argv-video-virtio-gpu-virgl.args | 23 +
.../qemuxml2argv-video-virtio-gpu-virgl.xml | 32 +
tests/qemuxml2argvtest.c | 11 +
26 files changed, 4676 insertions(+), 64 deletions(-)
create mode 100644 tests/qemucapabilitiesdata/caps_2.5.0-1.caps
create mode 100644 tests/qemucapabilitiesdata/caps_2.5.0-1.replies
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-device.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-device.xml
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-nodevice.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-nodevice.xml
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-virgl.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-video-virtio-gpu-virgl.xml
--
2.5.0
9 years
[libvirt] build issue due to '-Werror=cast-align' on ARM (armhf) [was: Re: [Xen-devel] [libvirt test] 63528: regressions - FAIL]
by Dario Faggioli
Hello,
The Xen Project's automated test suite is failing at running its
libvirt tests for a few time, like this:
On Wed, 2015-11-04 at 09:04 +0000, osstest service owner wrote:
> flight 63528 libvirt real [real]
> http://logs.test-lab.xenproject.org/osstest/logs/63528/
>
> Regressions :-(
>
> Tests which did not succeed and are blocking,
> including tests which could not be run:
> build-armhf-libvirt 5 libvirt-build fail REGR. vs. 63340
>
More specifically (from a more recent run):
CC util/libvirt_util_la-virnetdevmacvlan.lo
util/virnetdev.c: In function 'virNetDevParseDadStatus':
util/virnetdev.c:1319:188: error: cast increases required alignment of target type [-Werror=cast-align]
util/virnetdev.c:1332:41: error: cast increases required alignment of target type [-Werror=cast-align]
util/virnetdev.c:1334:92: error: cast increases required alignment of target type [-Werror=cast-align]
cc1: all warnings being treated as errors
make[3]: *** [util/libvirt_util_la-virnetdev.lo] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: Leaving directory `/home/osstest/build.64130.build-armhf-libvirt/libvirt/src'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/osstest/build.64130.build-armhf-libvirt/libvirt/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/osstest/build.64130.build-armhf-libvirt/libvirt'
make: *** [all] Error 2
The changeset being tested last, as of now, and still failing, is:
db92aee2b477355759351889e37a365379b43bf6
Full logs available at the following links:
http://logs.test-lab.xenproject.org/osstest/logs/64130/build-armhf-libvir...
http://logs.test-lab.xenproject.org/osstest/logs/64130/build-armhf-libvir...
Right now, I don't have an ARM cross build environment handy to try to
reproduce and attempt a fix, so I figured I at least was reporting it
here.
Regards,
Dario
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
9 years
[libvirt] [PATCH] vz: implementation of domainCreateXML callback
by Mikhail Feoktistov
---
src/vz/vz_driver.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 39f58a4..31dfb6a 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -979,6 +979,38 @@ vzDomainUndefine(virDomainPtr domain)
return vzDomainUndefineFlags(domain, 0);
}
+static virDomainPtr
+vzDomainCreateXML(virConnectPtr conn,
+ const char *xml,
+ unsigned int flags)
+{
+ virDomainPtr domain;
+ int ret;
+
+ virCheckFlags(VIR_DOMAIN_START_PAUSED, NULL);
+
+ domain = vzDomainDefineXMLFlags(conn, xml, 0);
+ if (domain == NULL)
+ return domain;
+
+ ret = vzDomainCreate(domain);
+ if (ret != 0) {
+ vzDomainUndefine(domain);
+ return NULL;
+ }
+
+ if (flags & VIR_DOMAIN_START_PAUSED) {
+ ret = vzDomainSuspend(domain);
+ if (ret != 0) {
+ vzDomainDestroy(domain);
+ vzDomainUndefine(domain);
+ return NULL;
+ }
+ }
+
+ return domain;
+}
+
static int
vzDomainHasManagedSaveImage(virDomainPtr domain, unsigned int flags)
{
@@ -1493,6 +1525,7 @@ static virHypervisorDriver vzDriver = {
.domainShutdown = vzDomainShutdown, /* 0.10.0 */
.domainCreate = vzDomainCreate, /* 0.10.0 */
.domainCreateWithFlags = vzDomainCreateWithFlags, /* 1.2.10 */
+ .domainCreateXML = vzDomainCreateXML, /* 1.2.22 */
.domainReboot = vzDomainReboot, /* 1.2.22 */
.domainDefineXML = vzDomainDefineXML, /* 0.10.0 */
.domainDefineXMLFlags = vzDomainDefineXMLFlags, /* 1.2.12 */
--
1.8.3.1
9 years
[libvirt] [PATCH] vz: allow to boot VM from cdrom
by Mikhail Feoktistov
---
src/vz/vz_sdk.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 750133d..9bdf7aa9a 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -2023,8 +2023,9 @@ prlsdkCheckUnsupportedParams(PRL_HANDLE sdkdom, virDomainDefPtr def)
}
if (!IS_CT(def)) {
- if (def->os.nBootDevs != 1 ||
- def->os.bootDevs[0] != VIR_DOMAIN_BOOT_DISK ||
+ if (def->os.nBootDevs == 0 ||
+ (def->os.bootDevs[0] != VIR_DOMAIN_BOOT_DISK &&
+ def->os.bootDevs[0] != VIR_DOMAIN_BOOT_CDROM) ||
def->os.init != NULL || def->os.initargv != NULL) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -3179,11 +3180,12 @@ static int prlsdkAddDisk(PRL_HANDLE sdkdom,
if (disk->src->type == VIR_STORAGE_TYPE_FILE) {
if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK &&
- virDomainDiskGetFormat(disk) != VIR_STORAGE_FILE_PLOOP) {
+ (virDomainDiskGetFormat(disk) != VIR_STORAGE_FILE_PLOOP &&
+ virDomainDiskGetFormat(disk) != VIR_STORAGE_FILE_NONE)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid format of "
- "disk %s, vz driver supports only "
- "images in ploop format."), disk->src->path);
+ "disk %s, it should be either not set or "
+ "ploop format."), disk->src->path);
goto cleanup;
}
@@ -3205,11 +3207,13 @@ static int prlsdkAddDisk(PRL_HANDLE sdkdom,
pret = PrlVmDev_SetEmulatedType(sdkdisk, emutype);
prlsdkCheckRetGoto(pret, cleanup);
- pret = PrlVmDev_SetSysName(sdkdisk, disk->src->path);
- prlsdkCheckRetGoto(pret, cleanup);
+ if (disk->src->path != NULL) {
+ pret = PrlVmDev_SetSysName(sdkdisk, disk->src->path);
+ prlsdkCheckRetGoto(pret, cleanup);
- pret = PrlVmDev_SetFriendlyName(sdkdisk, disk->src->path);
- prlsdkCheckRetGoto(pret, cleanup);
+ pret = PrlVmDev_SetFriendlyName(sdkdisk, disk->src->path);
+ prlsdkCheckRetGoto(pret, cleanup);
+ }
drive = &disk->info.addr.drive;
if (drive->controller > 0) {
--
1.8.3.1
9 years
[libvirt] [perl PATCH] Post-release version bump to 1.3.0
by Pavel Hrdina
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
Makefile.PL | 2 +-
README | 2 +-
lib/Sys/Virt.pm | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/Makefile.PL b/Makefile.PL
index 709be83..4ae538f 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -3,7 +3,7 @@ use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
-my $libvirtver = "1.2.21";
+my $libvirtver = "1.3.0";
my $stat = system "pkg-config --atleast-version=$libvirtver libvirt";
die "cannot run pkg-config to check libvirt version" if $stat == -1;
die "libvirt >= $libvirtver is required\n" unless $stat == 0;
diff --git a/README b/README
index 757d652..a942d66 100644
--- a/README
+++ b/README
@@ -7,6 +7,6 @@ further details on libvirt consult its website http://libvirt.org/
The only pre-requisite for this module is libvirt itself. For
installation instructions, consult the INSTALL file.
-The current minimum required version of libvirt is 1.2.21
+The current minimum required version of libvirt is 1.3.0
-- End
diff --git a/lib/Sys/Virt.pm b/lib/Sys/Virt.pm
index 0371d08..9e7c6d9 100644
--- a/lib/Sys/Virt.pm
+++ b/lib/Sys/Virt.pm
@@ -78,7 +78,7 @@ use Sys::Virt::NWFilter;
use Sys::Virt::DomainSnapshot;
use Sys::Virt::Stream;
-our $VERSION = '1.2.21';
+our $VERSION = '1.3.0';
require XSLoader;
XSLoader::load('Sys::Virt', $VERSION);
--
2.6.3
9 years
[libvirt] [PATCH v2] Post-release version bump to 1.3.0
by Pavel Hrdina
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
configure.ac | 2 +-
src/libxl/libxl_driver.c | 4 ++--
src/vz/vz_driver.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/configure.ac b/configure.ac
index f481c50..4b7c9ed 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@ dnl You should have received a copy of the GNU Lesser General Public
dnl License along with this library. If not, see
dnl <http://www.gnu.org/licenses/>.
-AC_INIT([libvirt], [1.2.22], [libvir-list(a)redhat.com], [], [http://libvirt.org])
+AC_INIT([libvirt], [1.3.0], [libvir-list(a)redhat.com], [], [http://libvirt.org])
AC_CONFIG_SRCDIR([src/libvirt.c])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_HEADERS([config.h])
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index d77a0e4..35d7fae 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5421,8 +5421,8 @@ static virHypervisorDriver libxlHypervisorDriver = {
#endif
.nodeGetFreeMemory = libxlNodeGetFreeMemory, /* 0.9.0 */
.nodeGetCellsFreeMemory = libxlNodeGetCellsFreeMemory, /* 1.1.1 */
- .domainMemoryStats = libxlDomainMemoryStats, /* 1.2.22 */
- .domainGetCPUStats = libxlDomainGetCPUStats, /* 1.2.22 */
+ .domainMemoryStats = libxlDomainMemoryStats, /* 1.3.0 */
+ .domainGetCPUStats = libxlDomainGetCPUStats, /* 1.3.0 */
.connectDomainEventRegister = libxlConnectDomainEventRegister, /* 0.9.0 */
.connectDomainEventDeregister = libxlConnectDomainEventDeregister, /* 0.9.0 */
.domainManagedSave = libxlDomainManagedSave, /* 0.9.2 */
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 39f58a4..ea1090a 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -1493,7 +1493,7 @@ static virHypervisorDriver vzDriver = {
.domainShutdown = vzDomainShutdown, /* 0.10.0 */
.domainCreate = vzDomainCreate, /* 0.10.0 */
.domainCreateWithFlags = vzDomainCreateWithFlags, /* 1.2.10 */
- .domainReboot = vzDomainReboot, /* 1.2.22 */
+ .domainReboot = vzDomainReboot, /* 1.3.0 */
.domainDefineXML = vzDomainDefineXML, /* 0.10.0 */
.domainDefineXMLFlags = vzDomainDefineXMLFlags, /* 1.2.12 */
.domainUndefine = vzDomainUndefine, /* 1.2.10 */
--
2.6.3
9 years
[libvirt] [python PATCH] Post-release version bump to 1.3.0
by Pavel Hrdina
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
Pushed
setup.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/setup.py b/setup.py
index 61fa369..04e3de4 100755
--- a/setup.py
+++ b/setup.py
@@ -311,7 +311,7 @@ class my_clean(clean):
_c_modules, _py_modules = get_module_lists()
setup(name = 'libvirt-python',
- version = '1.2.21',
+ version = '1.3.0',
url = 'http://www.libvirt.org',
maintainer = 'Libvirt Maintainers',
maintainer_email = 'libvir-list(a)redhat.com',
--
2.6.3
9 years
[libvirt] [PATCH] qemu: pass the asyncJob to qemuProcessStartCPUs
by Ján Tomko
Now that new domains are started inside a QEMU_ASYNC_JOB_START job,
we need to pass it down to qemuProcessStartCPUs too.
This removes the warning:
qemuDomainObjEnterMonitorInternal:1750 : This thread seems to be the
async job owner; entering monitor without asking for a nested job is
dangerous
Introduced by commit 04c721f, before that this code path was only
executed with QEMU_ASYNC_JOB_NONE.
(This code is not executed on migration, because qemuMigrationPrepareAny
sets the VIR_QEMU_PROCESS_START_PAUSED flag.)
---
src/qemu/qemu_process.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 2192ad8..68542e7 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5013,15 +5013,15 @@ int qemuProcessStart(virConnectPtr conn,
goto error;
if (!(flags & VIR_QEMU_PROCESS_START_PAUSED)) {
VIR_DEBUG("Starting domain CPUs");
/* Allow the CPUS to start executing */
if (qemuProcessStartCPUs(driver, vm, conn,
VIR_DOMAIN_RUNNING_BOOTED,
- QEMU_ASYNC_JOB_NONE) < 0) {
+ asyncJob) < 0) {
if (virGetLastError() == NULL)
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("resume operation failed"));
goto error;
}
} else {
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
--
2.4.6
9 years