[libvirt] [PATCH] virtlogd: use PRIu64 to print 64bit types
by Guido Günther
Otherwise we fail on 32bit with:
CC logging/virtlogd-log_daemon_dispatch.o
logging/log_daemon_dispatch.c: In function 'virLogManagerProtocolDispatchDomainReadLogFile':
logging/log_daemon_dispatch.c:120:9: error: format '%zu' expects argument of type 'size_t', but argument 7 has type 'uint64_t' [-Werror=format]
---
src/logging/log_daemon_dispatch.c | 3 ++-
tests/virrotatingfiletest.c | 4 +++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/logging/log_daemon_dispatch.c b/src/logging/log_daemon_dispatch.c
index 269255a..7391a6f 100644
--- a/src/logging/log_daemon_dispatch.c
+++ b/src/logging/log_daemon_dispatch.c
@@ -21,6 +21,7 @@
*/
#include <config.h>
+#include <inttypes.h>
#include "rpc/virnetserver.h"
#include "rpc/virnetserverclient.h"
@@ -118,7 +119,7 @@ virLogManagerProtocolDispatchDomainReadLogFile(virNetServerPtr server ATTRIBUTE_
if (args->maxlen > VIR_LOG_MANAGER_PROTOCOL_STRING_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Requested data len %zu is larger than maximum %d"),
+ _("Requested data len %"PRIu64" is larger than maximum %d"),
args->maxlen, VIR_LOG_MANAGER_PROTOCOL_STRING_MAX);
goto cleanup;
}
diff --git a/tests/virrotatingfiletest.c b/tests/virrotatingfiletest.c
index ed55e63..73f0c26 100644
--- a/tests/virrotatingfiletest.c
+++ b/tests/virrotatingfiletest.c
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
+#include <inttypes.h>
#include "virrotatingfile.h"
#include "virlog.h"
@@ -57,7 +58,8 @@ static int testRotatingFileWriterAssertOneFileSize(const char *filename,
fprintf(stderr, "File %s should not exist\n", filename);
return -1;
} else if (sb.st_size != size) {
- fprintf(stderr, "File %s should be %zu bytes not %zu\n",
+ fprintf(stderr, "File %s should be %" PRIu64
+ " bytes not %" PRIu64 "\n",
filename, size, sb.st_size);
return -1;
} else {
--
2.6.2
9 years, 1 month
[libvirt] [PATCH] virtlogd: cast maxlen to size_t
by Guido Günther
Otherwise we fail on 32bit with:
CC logging/virtlogd-log_daemon_dispatch.o
logging/log_daemon_dispatch.c: In function 'virLogManagerProtocolDispatchDomainReadLogFile':
logging/log_daemon_dispatch.c:120:9: error: format '%zu' expects argument of type 'size_t', but argument 7 has type 'uint64_t' [-Werror=format]
---
src/logging/log_daemon_dispatch.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/logging/log_daemon_dispatch.c b/src/logging/log_daemon_dispatch.c
index 269255a..70b5f1d 100644
--- a/src/logging/log_daemon_dispatch.c
+++ b/src/logging/log_daemon_dispatch.c
@@ -119,7 +119,7 @@ virLogManagerProtocolDispatchDomainReadLogFile(virNetServerPtr server ATTRIBUTE_
if (args->maxlen > VIR_LOG_MANAGER_PROTOCOL_STRING_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Requested data len %zu is larger than maximum %d"),
- args->maxlen, VIR_LOG_MANAGER_PROTOCOL_STRING_MAX);
+ (size_t)args->maxlen, VIR_LOG_MANAGER_PROTOCOL_STRING_MAX);
goto cleanup;
}
--
2.6.2
9 years, 1 month
[libvirt] [libvirt-glib v5] gobject: Port to GTask API
by Zeeshan Ali (Khattak)
Drop usage of deprecated GSimpleAsyncResult API.
---
v5:
* Plug some GError leaks.
* Drop StoragePoolBuildData in favour of GUINT_TO_POINTER/GPOINTER_TO_UINT.
* Don't unref GTask before using it later in idle callback.
libvirt-gobject/libvirt-gobject-domain.c | 290 +++++++++--------------
libvirt-gobject/libvirt-gobject-input-stream.c | 78 +++----
libvirt-gobject/libvirt-gobject-output-stream.c | 76 +++---
libvirt-gobject/libvirt-gobject-storage-pool.c | 296 +++++++++---------------
libvirt-gobject/libvirt-gobject-stream.c | 54 +++--
5 files changed, 320 insertions(+), 474 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..8ef60d6 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,45 @@ 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);
+ }
+ g_error_free (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 +155,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 +164,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 +173,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..6968c3d 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,45 @@ 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);
+ }
+ g_error_free (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 +155,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 +164,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 +173,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..5f97691 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)
@@ -654,28 +647,20 @@ gboolean gvir_storage_pool_build (GVirStoragePool *pool,
return TRUE;
}
-typedef struct {
- guint flags;
-} StoragePoolBuildData;
-
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);
+ guint flags = GPOINTER_TO_UINT(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, flags, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -692,25 +677,18 @@ void gvir_storage_pool_build_async (GVirStoragePool *pool,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
- StoragePoolBuildData *data;
+ GTask *task;
g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
- 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, GUINT_TO_POINTER(flags), NULL);
+ g_task_run_in_thread(task, gvir_storage_pool_build_helper);
+ g_object_unref(task);
}
/**
@@ -726,16 +704,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 +734,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 +760,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 +786,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 +818,19 @@ 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);
- StoragePoolBuildData *data;
+ GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
+ guint flags = GPOINTER_TO_UINT(task_data);
GError *err = NULL;
- data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res),
- "StoragePoolBuildData");
-
- 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, flags, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -887,25 +847,18 @@ void gvir_storage_pool_start_async (GVirStoragePool *pool,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
- StoragePoolBuildData *data;
+ GTask *task;
g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
- 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, GUINT_TO_POINTER(flags), NULL);
+ g_task_run_in_thread(task, gvir_storage_pool_start_helper);
+ g_object_unref(task);
}
/**
@@ -921,16 +874,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 +904,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 +930,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 +956,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 +1039,19 @@ 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);
- StoragePoolBuildData *data;
+ GVirStoragePool *pool = GVIR_STORAGE_POOL(source_object);
+ guint flags = GPOINTER_TO_UINT(task_data);
GError *err = NULL;
- data = (StoragePoolBuildData *) g_object_get_data(G_OBJECT(res),
- "StoragePoolBuildData");
-
- 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, flags, &err))
+ g_task_return_error(task, err);
+ else
+ g_task_return_boolean(task, TRUE);
}
/**
@@ -1133,25 +1068,18 @@ void gvir_storage_pool_delete_async (GVirStoragePool *pool,
GAsyncReadyCallback callback,
gpointer user_data)
{
- GSimpleAsyncResult *res;
- StoragePoolBuildData *data;
+ GTask *task;
g_return_if_fail(GVIR_IS_STORAGE_POOL(pool));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
- 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, GUINT_TO_POINTER(flags), NULL);
+ g_task_run_in_thread(task, gvir_storage_pool_delete_helper);
+ g_object_unref(task);
}
/**
@@ -1167,16 +1095,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..2bb3e20 100644
--- a/libvirt-gobject/libvirt-gobject-stream.c
+++ b/libvirt-gobject/libvirt-gobject-stream.c
@@ -129,14 +129,11 @@ 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 gboolean close_in_idle (gpointer data)
{
- GSimpleAsyncResult *res;
+ GTask *task = G_TASK (data);
+ GIOStream *stream = G_IO_STREAM(g_task_get_source_object (task));
+ GCancellable *cancellable = g_task_get_cancellable (task);
GIOStreamClass *class;
GError *error;
@@ -146,27 +143,42 @@ 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);
- return;
+ g_task_return_error(task, error);
+
+ goto exit;
}
- 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);
+exit:
+ g_object_unref(task);
+ return FALSE;
}
+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_idle_add(close_in_idle, 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, 1 month
[libvirt] [PATCH] Wait for udev events to be handled after removing veth
by Cédric Bosdonnat
As per http://www.redhat.com/archives/libvir-list/2013-July/msg01279.html,
wait for udev events to be handled after removing a virtual NIC.
Any udev rule associated to NIC destroy could happen to run with a new
device with the same name that is being created.
---
src/util/virnetdevveth.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c
index 6905168..c8a38fb 100644
--- a/src/util/virnetdevveth.c
+++ b/src/util/virnetdevveth.c
@@ -225,5 +225,8 @@ int virNetDevVethDelete(const char *veth)
ret = 0;
cleanup:
virCommandFree(cmd);
+ /* Make sure the device is properly down: creating a new one
+ * with the same name could lead to troubles */
+ virFileWaitForDevices();
return ret;
}
--
2.1.4
9 years, 1 month
[libvirt] [PATCH] virsh: Try to keep printed XML pretty with change-media
by Martin Kletzander
When adding a new media with change-media and --print-xml, let's try
making it more readable and nice.
Before:
<disk type="file" device="cdrom">
...
<target dev="hdb" bus="ide"/>
<address type="drive" controller="0" bus="0" target="0" unit="1"/>
<source file="/tmp/a.iso"/></disk>
After:
<disk type="file" device="cdrom">
...
<source file="/tmp/a.iso"/>
<target dev="hdb" bus="ide"/>
<address type="drive" controller="0" bus="0" target="0" unit="1"/>
</disk>
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1219719
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
tools/virsh-domain.c | 48 ++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 44 insertions(+), 4 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index bd00785622b2..16b01d3dc631 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -11566,7 +11566,10 @@ virshUpdateDiskXML(xmlNodePtr disk_node,
const char *target,
virshUpdateDiskXMLType type)
{
+ xmlNodePtr tmp = NULL;
xmlNodePtr source = NULL;
+ xmlNodePtr target_node = NULL;
+ xmlNodePtr text_node = NULL;
char *device_type = NULL;
char *ret = NULL;
char *startupPolicy = NULL;
@@ -11583,9 +11586,31 @@ virshUpdateDiskXML(xmlNodePtr disk_node,
}
/* find the current source subelement */
- for (source = disk_node->children; source; source = source->next) {
- if (source->type == XML_ELEMENT_NODE &&
- xmlStrEqual(source->name, BAD_CAST "source"))
+ for (tmp = disk_node->children; tmp; tmp = tmp->next) {
+ /*
+ * Safe the last text node before the <target/>. The
+ * reasoning behind this is that the target node will be
+ * present in this case and also has a proper indentation.
+ */
+ if (!target_node && tmp->type == XML_TEXT_NODE)
+ text_node = tmp;
+
+ /*
+ * We need only element nodes from now on.
+ */
+ if (tmp->type != XML_ELEMENT_NODE)
+ continue;
+
+ if (xmlStrEqual(tmp->name, BAD_CAST "source"))
+ source = tmp;
+
+ if (xmlStrEqual(tmp->name, BAD_CAST "target"))
+ target_node = tmp;
+
+ /*
+ * We've found all we needed.
+ */
+ if (source && target_node)
break;
}
@@ -11637,7 +11662,22 @@ virshUpdateDiskXML(xmlNodePtr disk_node,
if (startupPolicy)
xmlNewProp(source, BAD_CAST "startupPolicy", BAD_CAST startupPolicy);
- xmlAddChild(disk_node, source);
+
+ /*
+ * So that the output XML looks nice in case anyone calls
+ * 'change-media' with '--print-xml', let's attach the source
+ * before target...
+ */
+ xmlAddPrevSibling(target_node, source);
+
+ /*
+ * ... and duplicate the text node doing the indentation just
+ * so it's more easily readable. And don't make it fatal.
+ */
+ if ((tmp = xmlCopyNode(text_node, 0))) {
+ if (!xmlAddPrevSibling(target_node, tmp))
+ xmlFreeNode(tmp);
+ }
}
if (!(ret = virXMLNodeToString(NULL, disk_node))) {
--
2.6.3
9 years, 1 month
[libvirt] [PATCH] systemd: Escape machine name for machined
by Martin Kletzander
According to the documentation, CreateMachine accepts only 7bit ASCII
characters in the machinename parameter, so let's make sure we can start
machines with unicode names with systemd. We already have a function
for that, we just forgot to use it.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1062943
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1282846
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
src/util/virsystemd.c | 12 ++++++++----
tests/virsystemdtest.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 50 insertions(+), 7 deletions(-)
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 1354b08b9e04..abd883c73844 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -119,16 +119,20 @@ char *virSystemdMakeMachineName(const char *name,
{
char *machinename = NULL;
char *username = NULL;
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+
if (privileged) {
- if (virAsprintf(&machinename, "%s-%s", drivername, name) < 0)
- goto cleanup;
+ virBufferAsprintf(&buf, "%s-", drivername);
} else {
if (!(username = virGetUserName(geteuid())))
goto cleanup;
- if (virAsprintf(&machinename, "%s-%s-%s", username, drivername, name) < 0)
- goto cleanup;
+
+ virBufferAsprintf(&buf, "%s-%s-", username, drivername);
}
+ virSystemdEscapeName(&buf, name);
+
+ machinename = virBufferContentAndReset(&buf);
cleanup:
VIR_FREE(username);
diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c
index d0b9335b24ae..06fec5495bc2 100644
--- a/tests/virsystemdtest.c
+++ b/tests/virsystemdtest.c
@@ -338,7 +338,7 @@ static int testCreateNetwork(const void *opaque ATTRIBUTE_UNUSED)
}
-struct testScopeData {
+struct testNameData {
const char *name;
const char *expected;
};
@@ -346,7 +346,7 @@ struct testScopeData {
static int
testScopeName(const void *opaque)
{
- const struct testScopeData *data = opaque;
+ const struct testNameData *data = opaque;
int ret = -1;
char *actual = NULL;
@@ -366,6 +366,29 @@ testScopeName(const void *opaque)
return ret;
}
+static int
+testMachineName(const void *opaque)
+{
+ const struct testNameData *data = opaque;
+ int ret = -1;
+ char *actual = NULL;
+
+ if (!(actual = virSystemdMakeMachineName(data->name, "qemu", true)))
+ goto cleanup;
+
+ if (STRNEQ(actual, data->expected)) {
+ fprintf(stderr, "Expected '%s' but got '%s'\n",
+ data->expected, actual);
+ goto cleanup;
+ }
+
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(actual);
+ return ret;
+}
+
typedef int (*virSystemdCanHelper)(bool * result);
struct testPMSupportData {
virSystemdCanHelper tested;
@@ -471,7 +494,7 @@ mymain(void)
# define TEST_SCOPE(name, unitname) \
do { \
- struct testScopeData data = { \
+ struct testNameData data = { \
name, unitname \
}; \
if (virtTestRun("Test scopename", testScopeName, &data) < 0) \
@@ -482,6 +505,22 @@ mymain(void)
TEST_SCOPE("demo-name", "machine-lxc\\x2ddemo\\x2dname.scope");
TEST_SCOPE("demo!name", "machine-lxc\\x2ddemo\\x21name.scope");
TEST_SCOPE(".demo", "machine-lxc\\x2d\\x2edemo.scope");
+ TEST_SCOPE("bull💩", "machine-lxc\\x2dbull\\xf0\\x9f\\x92\\xa9.scope");
+
+# define TEST_MACHINE(name, machinename) \
+ do { \
+ struct testNameData data = { \
+ name, machinename \
+ }; \
+ if (virtTestRun("Test scopename", testMachineName, &data) < 0) \
+ ret = -1; \
+ } while (0)
+
+ TEST_MACHINE("demo", "qemu-demo");
+ TEST_MACHINE("demo-name", "qemu-demo\\x2dname");
+ TEST_MACHINE("demo!name", "qemu-demo\\x21name");
+ TEST_MACHINE(".demo", "qemu-\\x2edemo");
+ TEST_MACHINE("bull\U0001f4a9", "qemu-bull\\xf0\\x9f\\x92\\xa9");
# define TESTS_PM_SUPPORT_HELPER(name, function) \
do { \
--
2.6.3
9 years, 1 month
[libvirt] [PATCH] schema: use a better regex for listen addresses
by Ján Tomko
A domain with '::' as the listen address fails to validate.
Reuse the 'ipAddr' and 'dnsName' regexes from basictypes instead
of reinventing them.
https://bugzilla.redhat.com/show_bug.cgi?id=1285665
---
docs/schemas/domaincommon.rng | 7 ++++---
tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.args | 2 +-
tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.xml | 4 ++--
3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 7e7fd58..95366bb 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -5221,9 +5221,10 @@
</data>
</define>
<define name="addrIPorName">
- <data type="string">
- <param name="pattern">(([0-2]?[0-9]?[0-9]\.){3}[0-2]?[0-9]?[0-9])|(([0-9a-fA-F]+|:)+[0-9a-fA-F]+)|([a-zA-Z0-9_\.\+\-]*)</param>
- </data>
+ <choice>
+ <ref name="ipAddr"/>
+ <ref name="dnsName"/>
+ </choice>
</define>
<define name="usbIdDefault">
<data type="string">
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.args b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.args
index 473b0e5..36e42e5 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.args
@@ -19,5 +19,5 @@ QEMU_AUDIO_DRV=none \
-net none \
-serial none \
-parallel none \
--vnc 127.0.0.1:59630,share=allow-exclusive \
+-vnc '[::]:59630,share=allow-exclusive' \
-vga cirrus
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.xml
index 4b88e49..1c76ddc 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-policy.xml
@@ -25,8 +25,8 @@
<controller type='pci' index='0' model='pci-root'/>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
- <graphics type='vnc' port='65530' autoport='no' listen='127.0.0.1' sharePolicy='allow-exclusive'>
- <listen type='address' address='127.0.0.1'/>
+ <graphics type='vnc' port='65530' autoport='no' listen='::' sharePolicy='allow-exclusive'>
+ <listen type='address' address='::'/>
</graphics>
<video>
<model type='cirrus' vram='16384' heads='1'/>
--
2.4.6
9 years, 1 month
[libvirt] [PATCH] Enhance documentation of virDomainDetachDevice
by Jiri Denemark
Link it to virDomainDetachDeviceFlags.
https://bugzilla.redhat.com/show_bug.cgi?id=1257280
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/libvirt-domain.c | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 7cfbe58..7cfc4d2 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -8392,19 +8392,10 @@ virDomainAttachDeviceFlags(virDomainPtr domain,
* @domain: pointer to domain object
* @xml: pointer to XML description of one device
*
- * Destroy a virtual device attachment to backend. This function,
- * having hot-unplug semantics, is only allowed on an active domain.
+ * This is an equivalent of virDomainDetachDeviceFlags() when called with
+ * @flags parameter set to VIR_DOMAIN_AFFECT_LIVE.
*
- * Be aware that hotplug changes might not persist across a domain going
- * into S4 state (also known as hibernation) unless you also modify the
- * persistent domain definition.
- *
- * The supplied XML description of the device should be as specific
- * as its definition in the domain XML. The set of attributes used
- * to match the device are internal to the drivers. Using a partial definition,
- * or attempting to detach a device that is not present in the domain XML,
- * but shares some specific attributes with one that is present,
- * may lead to unexpected results.
+ * See virDomainDetachDeviceFlags() for more details.
*
* Returns 0 in case of success, -1 in case of failure.
*/
--
2.6.3
9 years, 1 month
[libvirt] [PATCH] lxc: drop sys_admin caps by default
by Cédric Bosdonnat
To make sure the container user doesn't play with mounts, like
changing them from ro to rw, drop the sys_admin capability by default.
If user really needs to play with those, it can be enabled in the
configuration.
---
Note: it seems that patch 3/3 or my last series never reached the list.
Here it is.
src/lxc/lxc_container.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index c5a70a1..d6d6fba 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -2083,6 +2083,7 @@ static int lxcContainerDropCapabilities(virDomainDefPtr def,
case VIR_DOMAIN_CAPS_FEATURE_MKNOD: /* No creating device nodes */
case VIR_DOMAIN_CAPS_FEATURE_AUDIT_CONTROL: /* No messing with auditing status */
case VIR_DOMAIN_CAPS_FEATURE_MAC_ADMIN: /* No messing with LSM config */
+ case VIR_DOMAIN_CAPS_FEATURE_SYS_ADMIN: /* No messing with mounts */
toDrop = (state != VIR_TRISTATE_SWITCH_ON);
break;
default: /* User specified capabilities to drop */
--
2.1.4
9 years, 1 month
[libvirt] [PATCH] virtlockd: fix misc memory leaks and other bugs
by Daniel P. Berrange
Fix memory leaks, failure to restore umask and missing man
page docs.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/locking/lock_daemon.c | 6 +++++-
src/locking/virtlockd.pod.in | 7 ++++++-
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index 3dc47c1..a5a40fe 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -118,6 +118,7 @@ virLockDaemonFree(virLockDaemonPtr lockd)
if (!lockd)
return;
+ virMutexDestroy(&lockd->lock);
virObjectUnref(lockd->dmn);
virHashFree(lockd->lockspaces);
virLockSpaceFree(lockd->defaultLockspace);
@@ -410,6 +411,7 @@ virLockDaemonUnixSocketPaths(bool privileged,
old_umask = umask(077);
if (virFileMakePath(rundir) < 0) {
+ VIR_FREE(rundir);
umask(old_umask);
goto error;
}
@@ -516,6 +518,7 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
old_umask = umask(077);
if (virFileMakePath(logdir) < 0) {
+ VIR_FREE(logdir);
umask(old_umask);
goto error;
}
@@ -1187,7 +1190,7 @@ int main(int argc, char **argv) {
int c;
char *tmp;
- c = getopt_long(argc, argv, "ldf:p:t:vVh", opts, &optidx);
+ c = getopt_long(argc, argv, "df:p:t:vVh", opts, &optidx);
if (c == -1)
break;
@@ -1321,6 +1324,7 @@ int main(int argc, char **argv) {
VIR_ERROR(_("unable to create rundir %s: %s"), run_dir,
virStrerror(errno, ebuf, sizeof(ebuf)));
ret = VIR_LOCK_DAEMON_ERR_RUNDIR;
+ umask(old_umask);
goto cleanup;
}
umask(old_umask);
diff --git a/src/locking/virtlockd.pod.in b/src/locking/virtlockd.pod.in
index 99612aa..661473c 100644
--- a/src/locking/virtlockd.pod.in
+++ b/src/locking/virtlockd.pod.in
@@ -4,7 +4,7 @@ virtlockd - libvirt lock management daemon
=head1 SYNOPSIS
-B<virtlockd> [ -dv ] [ -f config_file ] [ -p pid_file ]
+B<virtlockd> [ -dvV ] [ -t timeout] [ -f config_file ] [ -p pid_file ]
B<virtlockd> --version
@@ -38,6 +38,11 @@ Run as a daemon and write PID file.
Use this configuration file, overriding the default value.
+=item B<-t, --timeout> I<SECONDS>
+
+Automatically shutdown after I<SECONDS> have elapsed with
+no active client or lock.
+
=item B<-p, --pid-file> I<FILE>
Use this name for the PID file, overriding the default value.
--
2.5.0
9 years, 1 month