qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Lei Li <lilei@linux.vnet.ibm.com>
Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH 3/3] qga: add guest-set-time command
Date: Mon, 07 Jan 2013 15:26:52 -0700	[thread overview]
Message-ID: <50EB4BAC.7060908@redhat.com> (raw)
In-Reply-To: <1357466820-12860-4-git-send-email-lilei@linux.vnet.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 4208 bytes --]

On 01/06/2013 03:07 AM, Lei Li wrote:
> Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
> ---
>  qga/commands-posix.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  qga/qapi-schema.json |   32 ++++++++++++++++++++++++++++
>  2 files changed, 89 insertions(+), 0 deletions(-)
> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 190199d..7fff49a 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -121,6 +121,63 @@ struct HostTimeInfo *qmp_guest_get_time(Error **errp)
>      return host_time;
>  }
>  
> +void qmp_guest_set_time(bool has_seconds, int64_t seconds,
> +                        bool has_microseconds, int64_t microseconds,
> +                        bool has_utc_offset, int64_t utc_offset, Error **errp)
> +{
> +    int ret;
> +    int status;
> +    pid_t pid, rpid;
> +    struct timeval tv;
> +    HostTimeInfo *host_time;
> +
> +    if ((!has_seconds) && (!has_microseconds) && (!has_utc_offset)) {

Is it really qemu style to parenthesize this much?

> +        host_time = get_host_time();
> +        if (!host_time) {
> +            error_set(errp, QERR_QGA_COMMAND_FAILED, "Failed to set guest time");
> +            return;
> +        }
> +        tv.tv_sec = host_time->seconds;
> +        tv.tv_usec = host_time->microseconds;
> +    } else if (has_seconds && has_microseconds && has_utc_offset) {
> +        tv.tv_sec = (time_t) seconds + utc_offset;

You need to worry about overflow on hosts where time_t is 32-bits but
the user passed time using 64-bits (such as past the year 2038).
Likewise, it might be worth bounds-checking utc-offset to be at most 12
hours away from UTC (or is there a better bounds?).

> +        tv.tv_usec = (time_t) microseconds;

Likewise, you should range-validate that microseconds does not overflow
1000000 (or, if you take my suggestion about using nanoseconds, since
struct timespec is a bit more expressive, then bound things by
1000000000, and properly round when converting to lower resolution
interfaces such as settimeofday()).

> +    } else {
> +        error_set(errp, QERR_INVALID_PARAMETER, "parameter missing");

That's a bit harsh.  I'm thinking it might be nicer to support:

all three missing - grab time from the host
at least seconds present - populate any missing subseconds or utc_offset
as 0
seconds missing, but other fields present - error

making this look more like:

if (!has_seconds) {
    if (has_subseconds || has_utc_offset) {
        error_set();
    } else {
        use get_host_time();
    }
} else {
    tv.tv_sec = seconds + (has_utc_offset ? utc_offset : 0);
    ...
}

> +++ b/qga/qapi-schema.json
> @@ -117,6 +117,38 @@
>    'returns': 'HostTimeInfo' }
>  
>  ##
> +# @guest-set-time:
> +#
> +# Set guest time. If none arguments were given, will set

s/none/no/

> +# host time to guest.
> +#
> +# Right now, when a guest is paused or migrated to a file
> +# then loaded from that file, the guest OS has no idea that
> +# there was a big gap in the time. Depending on how long
> +# the gap was, NTP might not be able to resynchronize the
> +# guest.
> +#
> +# This command tries to set guest time based on the information
> +# from host or an absolute value given by management app, and
> +# set the Hardware Clock to the current System Time. This
> +# will make it easier for a guest to resynchronize without
> +# waiting for NTP.
> +#
> +# @seconds: #optional "seconds" time.
> +#
> +# @microseconds: #optional "microseconds" time.
> +#
> +# @utc-offset: #optional utc offset.

If you like my above suggestions, this might be worth documenting that
@microseconds (or @nanoseconds) must not be provided unless @seconds is
present, and so on.

Same questions as in patch 1/3 - you need to document what @seconds is
relative to (presumably the Epoch of 1970-01-01), and what format
utc-offset takes.  Based on this patch, it looks like you are using
utc-offset as the number of seconds difference, so one hour is
represented as 3600.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

  reply	other threads:[~2013-01-07 22:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-06 10:06 [Qemu-devel] [RFC PATCH 0/3] Time resync support by qemu-ga Lei Li
2013-01-06 10:06 ` [Qemu-devel] [PATCH 1/3] qga: add support to get host time Lei Li
2013-01-07 21:52   ` Eric Blake
2013-01-11  7:18     ` Lei Li
2013-01-11 15:37       ` Eric Blake
2013-01-14  3:17         ` Lei Li
2013-01-14 14:23           ` Eric Blake
2013-01-09 13:32   ` Luiz Capitulino
2013-01-11  7:19     ` Lei Li
2013-01-11 11:14       ` Luiz Capitulino
2013-01-09 15:36   ` mdroth
2013-01-11  7:20     ` Lei Li
2013-01-06 10:06 ` [Qemu-devel] [PATCH 2/3] qga: add guest-get-time command Lei Li
2013-01-07 22:04   ` Eric Blake
2013-01-11  7:37     ` Lei Li
2013-01-11 17:28       ` mdroth
2013-01-09 13:33   ` Luiz Capitulino
2013-01-11  7:50     ` Lei Li
2013-01-06 10:07 ` [Qemu-devel] [PATCH 3/3] qga: add guest-set-time command Lei Li
2013-01-07 22:26   ` Eric Blake [this message]
2013-01-11  8:00     ` Lei Li
2013-01-09 13:40   ` Luiz Capitulino
2013-01-11  8:03     ` Lei Li
2013-01-07 19:01 ` [Qemu-devel] [RFC PATCH 0/3] Time resync support by qemu-ga Eric Blake
2013-01-11  7:36   ` Lei Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50EB4BAC.7060908@redhat.com \
    --to=eblake@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=lilei@linux.vnet.ibm.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).