Hey, On Tue, Oct 27, 2015 at 06:17:58PM +0000, Zeeshan Ali (Khattak) wrote: > --- > libvirt-gobject/libvirt-gobject-domain.c | 126 +++++++++++++++++++++++++++++++ > libvirt-gobject/libvirt-gobject-domain.h | 25 ++++++ > libvirt-gobject/libvirt-gobject.sym | 9 +++ > 3 files changed, 160 insertions(+) > > diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c > index 34eb7ca..26d0cba 100644 > --- a/libvirt-gobject/libvirt-gobject-domain.c > +++ b/libvirt-gobject/libvirt-gobject-domain.c > @@ -1886,3 +1886,129 @@ gboolean gvir_domain_get_has_current_snapshot(GVirDomain *dom, > > return TRUE; > } > + > +/** > + * gvir_domain_set_time: > + * @dom: the domain > + * @seconds: The seconds since Epoch in UTC. > + * @nseconds: The microseconds. > + * @flags: bitwise-OR of #GVirDomainSetTimeFlags. > + * > + * This function tries to set guest time to the given value. The time to set > + * (@seconds and @nseconds) should be in seconds relative to the Epoch of > + * 1970-01-01 00:00:00 in UTC. > + * > + * If you pass #GVIR_DOMAIN_TIME_SYNC as @flags, the time is reset using > + * domain's RTC and @seconds and @nseconds arguments are ignored. I'd add some more articles, but not sure it's needed/better: « using the domain's RTC and the @seconds and @nseconds arguments are ignored. » > + * > + * Please note that some hypervisors may require guest agent to be configured > + * and running in order for this function to work. and here « a guest agent ». Just ignore these comments if you are confident your version reads better to native speakers :) > + */ > +gboolean gvir_domain_set_time(GVirDomain *dom, > + gint64 seconds, > + guint nseconds, A GDateTime would be more convenient than these seconds/nseconds fields. > + guint flags, > + GError **err) > +{ > + GVirDomainPrivate *priv; > + int ret; > + > + g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); > + g_return_val_if_fail(err == NULL || *err == NULL, FALSE); > + g_return_val_if_fail(flags == 0 || flags & GVIR_DOMAIN_TIME_SYNC, FALSE); (flags & GVIR_DOMAIN_TIME_SYNC) != 0 to be consistent with the 'flags == 0' before. However, shouldn't it be flags & GVIR_DOMAIN_TIME_SYNC == GVIR_DOMAIN_TIME_SYNC to be sure we were not passed unknown flags? Looks good otherwise. Out of curiosity have you observed virDomainSetTime blocking, or is the async version there because it will be doing expensive stuff if it has to talk to a guest agent? ACK otherwise. Christophe > + > + priv = dom->priv; > + ret = virDomainSetTime(priv->handle, seconds, nseconds, flags); > + if (ret < 0) { > + gvir_set_error_literal(err, GVIR_DOMAIN_ERROR, > + 0, > + "Unable to set domain time"); > + return FALSE; > + } > + > + return TRUE; > +} > + > +typedef struct { > + gint64 seconds; > + guint nseconds; > + guint flags; > +} DomainSetTimeData; > + > +static void domain_set_time_data_free(DomainSetTimeData *data) > +{ > + g_slice_free(DomainSetTimeData, data); > +} > + > +static void > +gvir_domain_set_time_helper(GTask *task, > + gpointer object, > + gpointer task_data, > + GCancellable *cancellable G_GNUC_UNUSED) > +{ > + GVirDomain *dom = GVIR_DOMAIN(object); > + DomainSetTimeData *data = (DomainSetTimeData *) task_data; > + GError *err = NULL; > + > + if (!gvir_domain_set_time(dom, > + data->seconds, > + data->nseconds, > + data->flags, > + &err)) > + g_task_return_error(task, err); > + else > + g_task_return_boolean(task, TRUE); > +} > + > +/** > + * gvir_domain_set_time_async: > + * @dom: the domain > + * @dom: the domain > + * @seconds: The seconds since Epoch in UTC. > + * @nseconds: The microseconds. > + * @flags: bitwise-OR of #GVirDomainSetTimeFlags. > + * @cancellable: (allow-none)(transfer none): cancellation object > + * @callback: (scope async): completion callback > + * @user_data: (closure): opaque data for callback > + * > + * Asynchronous variant of #gvir_domain_set_time. > + */ > +void gvir_domain_set_time_async(GVirDomain *dom, > + gint64 seconds, > + guint nseconds, > + guint flags, > + GCancellable *cancellable, > + GAsyncReadyCallback callback, > + gpointer user_data) > +{ > + GTask *task; > + DomainSetTimeData *data; > + > + g_return_if_fail(GVIR_IS_DOMAIN(dom)); > + g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable)); > + > + data = g_slice_new0(DomainSetTimeData); > + data->seconds = seconds; > + data->nseconds = nseconds; > + data->flags = flags; > + > + task = g_task_new (G_OBJECT(dom), > + cancellable, > + callback, > + user_data); > + g_task_set_task_data (task, data, (GDestroyNotify)domain_set_time_data_free); > + g_task_run_in_thread(task, gvir_domain_set_time_helper); > + > + g_object_unref(task); > +} > + > +gboolean gvir_domain_set_time_finish(GVirDomain *dom, > + GAsyncResult *result, > + GError **err) > +{ > + g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); > + g_return_val_if_fail(g_task_is_valid(result, G_OBJECT(dom)), FALSE); > + g_return_val_if_fail(err == NULL || *err == NULL, FALSE); > + > + return g_task_propagate_boolean(G_TASK(result), err); > +} > diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h > index 4fe381e..fbf7173 100644 > --- a/libvirt-gobject/libvirt-gobject-domain.h > +++ b/libvirt-gobject/libvirt-gobject-domain.h > @@ -215,6 +215,15 @@ typedef enum { > GVIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL = VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL > } GVirDomainSnapshotListFlags; > > +/** > + * GVirDomainSetTimeFlags: > + * @GVIR_DOMAIN_TIME_NONE: Re-sync domain time to given values. > + * @GVIR_DOMAIN_TIME_SYNC: Re-sync domain time from domain's RTC. > + */ > +typedef enum { > + GVIR_DOMAIN_TIME_NONE = 0, > + GVIR_DOMAIN_TIME_SYNC = VIR_DOMAIN_TIME_SYNC, > +} GVirDomainSetTimeFlags; > > typedef struct _GVirDomainInfo GVirDomainInfo; > struct _GVirDomainInfo > @@ -401,6 +410,22 @@ gboolean gvir_domain_get_has_current_snapshot(GVirDomain *dom, > gboolean *has_current_snapshot, > GError **error); > > +gboolean gvir_domain_set_time(GVirDomain *dom, > + gint64 seconds, > + guint nseconds, > + guint flags, > + GError **err); > +void gvir_domain_set_time_async(GVirDomain *dom, > + gint64 seconds, > + guint nseconds, > + guint flags, > + GCancellable *cancellable, > + GAsyncReadyCallback callback, > + gpointer user_data); > +gboolean gvir_domain_set_time_finish(GVirDomain *dom, > + GAsyncResult *result, > + GError **err); > + > G_END_DECLS > > #endif /* __LIBVIRT_GOBJECT_DOMAIN_H__ */ > diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym > index ca89a45..cbfaa71 100644 > --- a/libvirt-gobject/libvirt-gobject.sym > +++ b/libvirt-gobject/libvirt-gobject.sym > @@ -304,4 +304,13 @@ LIBVIRT_GOBJECT_0.2.2 { > gvir_network_get_dhcp_leases; > } LIBVIRT_GOBJECT_0.2.1; > > +LIBVIRT_GOBJECT_0.2.3 { > + global: > + gvir_domain_set_time_flags_get_type; > + > + gvir_domain_set_time; > + gvir_domain_set_time_async; > + gvir_domain_set_time_finish; > +} LIBVIRT_GOBJECT_0.2.2; > + > # .... define new API here using predicted next version number .... > -- > 2.5.0 > > -- > libvir-list mailing list > libvir-list@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/libvir-list
Attachment:
signature.asc
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list