From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx> --- libvirt-gobject/libvirt-gobject-connection.c | 99 +++++++++++++++++++++++++--- libvirt-gobject/libvirt-gobject-connection.h | 10 +++ libvirt-gobject/libvirt-gobject.sym | 7 ++ 3 files changed, 107 insertions(+), 9 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 3157a66..558ed2a 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -407,14 +407,10 @@ static int domain_event_cb(virConnectPtr conn G_GNUC_UNUSED, return 0; } -/** - * gvir_connection_open: - * @conn: a #GVirConnection - * @cancellable: (allow-none)(transfer none): cancellation object - */ -gboolean gvir_connection_open(GVirConnection *conn, - GCancellable *cancellable, - GError **err) +static gboolean _gvir_connection_open(GVirConnection *conn, + gboolean read_only, + GCancellable *cancellable, + GError **err) { GVirConnectionPrivate *priv; @@ -438,7 +434,11 @@ gboolean gvir_connection_open(GVirConnection *conn, return FALSE; } - if (!(priv->conn = virConnectOpen(priv->uri))) { + if (read_only) + priv->conn = virConnectOpenReadOnly(priv->uri); + else + priv->conn = virConnectOpen(priv->uri); + if (!priv->conn) { gvir_set_error(err, GVIR_CONNECTION_ERROR, 0, "Unable to open %s", @@ -472,6 +472,24 @@ gboolean gvir_connection_open(GVirConnection *conn, return TRUE; } +/** + * gvir_connection_open: + * @conn: a #GVirConnection + * @cancellable: (allow-none)(transfer none): cancellation object + */ +gboolean gvir_connection_open(GVirConnection *conn, + GCancellable *cancellable, + GError **err) +{ + return _gvir_connection_open(conn, FALSE, cancellable, err); +} + +gboolean gvir_connection_open_read_only(GVirConnection *conn, + GCancellable *cancellable, + GError **err) +{ + return _gvir_connection_open(conn, TRUE, cancellable, err); +} static void gvir_connection_open_helper(GSimpleAsyncResult *res, @@ -537,6 +555,69 @@ gboolean gvir_connection_open_finish(GVirConnection *conn, return TRUE; } +static void +gvir_connection_open_read_only_helper(GSimpleAsyncResult *res, + GObject *object, + GCancellable *cancellable) +{ + GVirConnection *conn = GVIR_CONNECTION(object); + GError *err = NULL; + + if (!gvir_connection_open_read_only(conn, cancellable, &err)) { + g_simple_async_result_set_from_error(res, err); + g_error_free(err); + } +} + + +/** + * gvir_connection_open_read_only_async: + * @conn: a #GVirConnection + * @cancellable: (allow-none)(transfer none): cancellation object + * @callback: (scope async): completion callback + * @user_data: (closure): opaque data for callback + */ +void gvir_connection_open_read_only_async(GVirConnection *conn, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *res; + + g_return_if_fail(GVIR_IS_CONNECTION(conn)); + g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); + + res = g_simple_async_result_new(G_OBJECT(conn), + callback, + user_data, + gvir_connection_open_read_only_async); + g_simple_async_result_run_in_thread(res, + gvir_connection_open_read_only_helper, + G_PRIORITY_DEFAULT, + cancellable); + g_object_unref(res); +} + + +/** + * gvir_connection_open_read_only_finish: + * @conn: a #GVirConnection + * @result: (transfer none): async method result + */ +gboolean gvir_connection_open_read_only_finish(GVirConnection *conn, + GAsyncResult *result, + GError **err) +{ + g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE); + g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(conn), + gvir_connection_open_read_only_async), + FALSE); + + if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err)) + return FALSE; + + return TRUE; +} gboolean gvir_connection_is_open(GVirConnection *conn) { diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h index f91ca05..d2b0a9f 100644 --- a/libvirt-gobject/libvirt-gobject-connection.h +++ b/libvirt-gobject/libvirt-gobject-connection.h @@ -88,6 +88,9 @@ GVirConnection *gvir_connection_new(const char *uri); gboolean gvir_connection_open(GVirConnection *conn, GCancellable *cancellable, GError **err); +gboolean gvir_connection_open_read_only(GVirConnection *conn, + GCancellable *cancellable, + GError **err); void gvir_connection_open_async(GVirConnection *conn, GCancellable *cancellable, GAsyncReadyCallback callback, @@ -95,6 +98,13 @@ void gvir_connection_open_async(GVirConnection *conn, gboolean gvir_connection_open_finish(GVirConnection *conn, GAsyncResult *result, GError **err); +void gvir_connection_open_read_only_async(GVirConnection *conn, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +gboolean gvir_connection_open_read_only_finish(GVirConnection *conn, + GAsyncResult *result, + GError **err); gboolean gvir_connection_is_open(GVirConnection *conn); void gvir_connection_close(GVirConnection *conn); diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index 8743b88..b02b365 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -224,4 +224,11 @@ LIBVIRT_GOBJECT_0.1.4 { gvir_storage_pool_undefine_finish; } LIBVIRT_GOBJECT_0.1.3; +LIBVIRT_GOBJECT_0.1.5 { + global: + gvir_connection_open_read_only; + gvir_connection_open_read_only_async; + gvir_connection_open_read_only_finish; +} LIBVIRT_GOBJECT_0.1.4; + # .... define new API here using predicted next version number .... -- 1.8.0.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list