Time resync support by qemu-ga
cover Time resync support by qemu-ga
This patch series attempts to add time resync support to qemu-ga by introducing qemu-ga commands guest-get-time and guest-set-time.
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. So adding new guest-agent command that is called any time a guest is resumed and which tells the guest to update its own wall clock time based on the information from the host will make it easier for a guest to resynchronize without waiting for NTP.
The previous RFC send for discussion and suggestion as link here:
http://article.gmane.org/gmane.comp.emulators.qemu/186126
The interface for these commands like:
{ 'command': 'guest-get-time', 'returns': 'HostTimeInfo' }
{ 'command': 'guest-set-time',
'data': { '*seconds': 'int', '*microseconds': 'int',
'*utc-offset': 'int' } }
TODO:
This is a RFC version with POSIX-specific command implemented. I just test on Linux guest, will add win32-specific command to support Windows guest later. Since I want to make sure if this seems like the way we should be headed.
Your comments and suggestions are very welcome!
Lei Li (3):
qga: add support to get host time
qga: add guest-get-time command
qga: add guest-set-time command
PATCH 1/3 qga: add support to get host time
--- qga/commands-posix.c | 18 ++++++++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-)
qga/commands-posix.c +18 -0
@@ -91,6 +91,24 @@ exit_err:error_set (err,QERR_UNDEFINED_ERROR ); } +static HostTimeInfo *get_host_time (void ) +{ +int err; +qemu_timeval tq; +HostTimeInfo *host_time; + + err =qemu_gettimeofday (&tq); +if (err <0 ) { +return NULL ; + } + + host_time =g_malloc0 (sizeof (HostTimeInfo)); + host_time->seconds = tq.tv_sec; + host_time->microseconds = tq.tv_usec; + +return host_time; +} + typedef struct GuestFileHandle { uint64_t id; FILE *fh;
qga/qapi-schema.json +17 -0
@@ -83,6 +83,23 @@ { 'command': 'guest-ping' } ## +# @HostTimeInfo +# +# Information about host time. +# +# @seconds: "seconds" time from the host. +# +# @microseconds: "microseconds" time from the host. +# +# @utc-offset: information about utc offset. +# +# Since: 1.4 +## +{ 'type': 'HostTimeInfo', + 'data': { 'seconds': 'int', 'microseconds': 'int', + 'utc-offset': 'int' } } + +## # @GuestAgentCommandInfo: # # Information about guest agent commands.
Signature · 1 line
1.7.7.6
Re: [Qemu-devel] [PATCH 1/3] qga: add support to get host time
Quoted 11 lines · Lei Li
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 18 ++++++++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-)qga/commands-posix.c +0
-0
qga/commands-posix.c exit_err: · line 99
Quoted 9 lines
qga/commands-posix.c +5
-0@@ -91,6 +91,24 @@ exit_err:error_set (err,QERR_UNDEFINED_ERROR ); } +static HostTimeInfo *get_host_time (void ) +{ + host_time =g_malloc0 (sizeof (HostTimeInfo)); + host_time->seconds = tq.tv_sec; + host_time->microseconds = tq.tv_usec;
Why usec? struct timespec with nanoseconds might be a nicer unit, even if for the initial implementation, you use qemu_gettimeofday().tv_usec*1000 rather than dragging in a realtime library for full ns resolution. If nothing else, the lesson that ought to be learned from the proliferation of time types is that any time you don't report lots of precision, someone comes along later on having to add yet another interface adding more precision.
qga/commands-posix.c line 90
Quoted 10 lines
qga/commands-posix.c +6
-0+++ b/qga/qapi-schema.json@@ -83,6 +83,23 @@ { 'command': 'guest-ping' } ## +# @HostTimeInfo +# +# Information about host time. +# +# @seconds: "seconds" time from the host.
Document that this is relative to the Epoch of 1970-01-01 (no matter what the host uses for its internal reference point).
qga/commands-posix.c line 92
Quoted 2 lines
qga/commands-posix.c +2
-0+# +# @microseconds: "microseconds" time from the host.
Again, nanoseconds (struct timespec) might be nicer.
qga/commands-posix.c line 94
Quoted 2 lines
qga/commands-posix.c +2
-0+# +# @utc-offset: information about utc offset.
In what format? Minutes away from UTC, a 4-digit decimal value, or something else (that is, is a one-hour offset represented as 60 or 100)?
Are negative values east or west of UTC?
qga/commands-posix.c line 100
Quoted 6 lines
qga/commands-posix.c +6
-0+# +# Since : 1.4 +## +{ 'type': 'HostTimeInfo', + 'data': { 'seconds': 'int', 'microseconds': 'int', + 'utc-offset': 'int' } }
Indentation seems inconsistent.
Ah, here you made them mandatory - only your cover letter implied that they were optional.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 1/3] qga: add support to get host time
Quoted 15 lines · Eric Blake
Quoted 14 lines · Lei Li
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 18 ++++++++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-)qga/commands-posix.c +0
-0@@ -91,6 +91,24 @@ exit_err:error_set (err,QERR_UNDEFINED_ERROR ); }
Quoted 12 lines
qga/commands-posix.c exit_err: · line 107
Quoted 5 lines
qga/commands-posix.c +5
-0+static HostTimeInfo *get_host_time (void ) +{ + host_time =g_malloc0 (sizeof (HostTimeInfo)); + host_time->seconds = tq.tv_sec; + host_time->microseconds = tq.tv_usec;Why usec? struct timespec with nanoseconds might be a nicer unit, even if for the initial implementation, you use qemu_gettimeofday().tv_usec*1000 rather than dragging in a realtime library for full ns resolution. If nothing else, the lesson that ought to be learned from the proliferation of time types is that any time you don't report lots of precision, someone comes along later on having to add yet another interface adding more precision.
ok, I will have a try to change it to a ns resolution.
Quoted 5 lines
Quoted 5 lines
qga/commands-posix.c +1
-0+++ b/qga/qapi-schema.json@@ -83,6 +83,23 @@ { 'command': 'guest-ping' }
Quoted 8 lines
qga/commands-posix.c line 90
Quoted 6 lines
qga/commands-posix.c +5
-0## +# @HostTimeInfo +# +# Information about host time. +# +# @seconds: "seconds" time from the host.Document that this is relative to the Epoch of 1970-01-01 (no matter what the host uses for its internal reference point).
Sure.
Quoted 10 lines
qga/commands-posix.c line 92
Quoted 3 lines
qga/commands-posix.c +2
-0+# +# @microseconds: "microseconds" time from the host.Again, nanoseconds (struct timespec) might be nicer.
qga/commands-posix.c line 94
Quoted 2 lines
qga/commands-posix.c +2
-0+# +# @utc-offset: information about utc offset.In what format? Minutes away from UTC, a 4-digit decimal value, or something else (that is, is a one-hour offset represented as 60 or 100)?
Are negative values east or west of UTC?
For this version, it's a one-hour offset represented as:±[hh]. Negative values are west, andpositive values are east of UTC.
Quoted 10 lines
qga/commands-posix.c line 100
Quoted 6 lines
qga/commands-posix.c +6
-0+# +# Since : 1.4 +## +{ 'type': 'HostTimeInfo', + 'data': { 'seconds': 'int', 'microseconds': 'int', + 'utc-offset': 'int' } }Indentation seems inconsistent.
Ah, here you made them mandatory - only your cover letter implied that they were optional.
Sorry for the inconsistent indentation.
No, this is just the definition of the time structure. The optional arguments mentioned in the cover letter are for command "guest-set-time". :)
Signature · 1 line
Lei
Re: [Qemu-devel] [PATCH 1/3] qga: add support to get host time
Quoted 3 lines · Lei Li
For this version, it's a one-hour offset represented as:±[hh]. Negative values are west, andpositive values are east of UTC.
Won't work. There are timezones with a half-hour offset. You need to express offset at least in terms of minutes, not just hours.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 1/3] qga: add support to get host time
Quoted 6 lines · Eric Blake
Quoted 2 lines · Lei Li
For this version, it's a one-hour offset represented as:±[hh]. Negative values are west, andpositive values are east of UTC.
Won't work. There are timezones with a half-hour offset. You need to express offset at least in terms of minutes, not just hours.
Yes, I have thought about this. For the timezones with a half-hour offset, it can just represented as +0.5 for example.
Signature · 1 line
Lei
Re: [Qemu-devel] [PATCH 1/3] qga: add support to get host time
Quoted 9 lines · Lei Li
Quoted 6 lines · Eric Blake
Quoted 2 lines · Lei Li
For this version, it's a one-hour offset represented as:±[hh]. Negative values are west, andpositive values are east of UTC.
Won't work. There are timezones with a half-hour offset. You need to express offset at least in terms of minutes, not just hours.
Yes, I have thought about this. For the timezones with a half-hour offset, it can just represented as +0.5 for example.
Floating point parsing is a pain compared to integer parsing. Remember, there is no way in POSIX to print a locale-independent floating point number, which forces programs to jump through quite a few hoops to guarantee that they are using '.' for the radix character in JSON output while still honoring the user's locale.
Please, use something based at a minimum on minutes (seconds is also possible), not hours,
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 1/3] qga: add support to get host time
In reply to Lei LiQuoted 11 lines · On Sun, 6 Jan 2013 18:06:58 +0800 Lei Li <[email protected]> wrote:
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 18 ++++++++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-)qga/commands-posix.c +0
-0
qga/commands-posix.c exit_err: · line 95
Quoted 5 lines
qga/commands-posix.c +2
-0@@ -91,6 +91,24 @@ exit_err:error_set (err,QERR_UNDEFINED_ERROR ); } +static HostTimeInfo *get_host_time (void ) +{
Does this build? Because no one is using this function.
qga/commands-posix.c exit_err: · line 101
Quoted 6 lines
qga/commands-posix.c +6
-0+int err; +qemu_timeval tq; +HostTimeInfo *host_time; + + err =qemu_gettimeofday (&tq); +if (err <0 ) {
I'd recommend taking an Error * argument and setting it with error_set_errno().
Quoted 18 lines
qga/commands-posix.c +10
-0+return NULL ; + } + + host_time =g_malloc0 (sizeof (HostTimeInfo)); + host_time->seconds = tq.tv_sec; + host_time->microseconds = tq.tv_usec; + +return host_time; +} + typedef struct GuestFileHandle { uint64_t id; FILE *fh;qga/qapi-schema.json +0
-0
qga/qapi-schema.json line 86
Quoted 4 lines
qga/qapi-schema.json +1
-0@@ -83,6 +83,23 @@ { 'command': 'guest-ping' } ## +# @HostTimeInfo
I'm a bit confused, why do you call it HostTimeInfo if this runs in the guest?
Quoted 19 lines
qga/qapi-schema.json +16
-0+# +# Information about host time. +# +# @seconds: "seconds" time from the host. +# +# @microseconds: "microseconds" time from the host. +# +# @utc-offset: information about utc offset. +# +# Since: 1.4 +## +{ 'type': 'HostTimeInfo', + 'data': { 'seconds': 'int', 'microseconds': 'int', + 'utc-offset': 'int' } } + +## # @GuestAgentCommandInfo: # # Information about guest agent commands.
Re: [Qemu-devel] [PATCH 1/3] qga: add support to get host time
Quoted 17 lines · Luiz Capitulino
Quoted 14 lines · On Sun, 6 Jan 2013 18:06:58 +0800 Lei Li <[email protected]> wrote:
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 18 ++++++++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-)qga/commands-posix.c +0
-0@@ -91,6 +91,24 @@ exit_err:error_set (err,QERR_UNDEFINED_ERROR ); }
Quoted 3 lines
qga/commands-posix.c exit_err: · line 95
Quoted 2 lines
qga/commands-posix.c +2
-0+static HostTimeInfo *get_host_time (void ) +{Does this build? Because no one is using this function.
Yes, this should be squashed into patch #2 as Mike also pointed out that.
Quoted 8 lines
qga/commands-posix.c exit_err: · line 101
Quoted 6 lines
qga/commands-posix.c +6
-0+int err; +qemu_timeval tq; +HostTimeInfo *host_time; + + err =qemu_gettimeofday (&tq); +if (err <0 ) {I'd recommend taking an Error * argument and setting it with
error_set_errno().
ok.
Quoted 21 lines
Quoted 21 lines
qga/commands-posix.c +10
-0+return NULL ; + } + + host_time =g_malloc0 (sizeof (HostTimeInfo)); + host_time->seconds = tq.tv_sec; + host_time->microseconds = tq.tv_usec; + +return host_time; +} + typedef struct GuestFileHandle { uint64_t id; FILE *fh;qga/qapi-schema.json +0
-0@@ -83,6 +83,23 @@ { 'command': 'guest-ping' }
Quoted 4 lines
qga/qapi-schema.json line 86
Quoted 2 lines
qga/qapi-schema.json +1
-0## +# @HostTimeInfoI'm a bit confused, why do you call it HostTimeInfo if this runs in the guest?
I call it HostTimeInfo because it contains the host time information. But seems that all of you don't like this 'HostTimeInfo', 'TimeInfo' might be better?
Quoted 19 lines
Quoted 19 lines
qga/qapi-schema.json +16
-0+# +# Information about host time. +# +# @seconds: "seconds" time from the host. +# +# @microseconds: "microseconds" time from the host. +# +# @utc-offset: information about utc offset. +# +# Since: 1.4 +## +{ 'type': 'HostTimeInfo', + 'data': { 'seconds': 'int', 'microseconds': 'int', + 'utc-offset': 'int' } } + +## # @GuestAgentCommandInfo: # # Information about guest agent commands.
Signature · 1 line
Lei
Re: [Qemu-devel] [PATCH 1/3] qga: add support to get host time
Quoted 6 lines · On Fri, 11 Jan 2013 15:19:35 +0800 Lei Li <[email protected]> wrote:
Quoted 4 lines
Quoted 2 lines
##
+# @HostTimeInfoI'm a bit confused, why do you call it HostTimeInfo if this runs in the guest?
I call it HostTimeInfo because it contains the host time information.
qemu-ga runs in the guest, so it's actually the guest time.
Quoted 2 lines
But seems that all of you don't like this 'HostTimeInfo', 'TimeInfo' might be better?
Yes, looks better for me.
Re: [Qemu-devel] [PATCH 1/3] qga: add support to get host time
In reply to Lei LiQuoted 11 lines · Lei Li
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 18 ++++++++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-)qga/commands-posix.c +0
-0
qga/commands-posix.c exit_err: · line 95
Quoted 5 lines
qga/commands-posix.c +2
-0@@ -91,6 +91,24 @@ exit_err:error_set (err,QERR_UNDEFINED_ERROR ); } +static HostTimeInfo *get_host_time (void ) +{
Should squash this into patch #2, since it doesn't get used till then. Otherwise we'll break build bisection when compiling with -Wunused/-Wall && -Werror, which is usually the default.
Quoted 50 lines
qga/commands-posix.c +16
-0+int err; +qemu_timeval tq; +HostTimeInfo *host_time; + + err =qemu_gettimeofday (&tq); +if (err <0 ) { +return NULL ; + } + + host_time =g_malloc0 (sizeof (HostTimeInfo)); + host_time->seconds = tq.tv_sec; + host_time->microseconds = tq.tv_usec; + +return host_time; +} + typedef struct GuestFileHandle { uint64_t id; FILE *fh;qga/qapi-schema.json +17
-0@@ -83,6 +83,23 @@ { 'command': 'guest-ping' } ## +# @HostTimeInfo +# +# Information about host time. +# +# @seconds: "seconds" time from the host. +# +# @microseconds: "microseconds" time from the host. +# +# @utc-offset: information about utc offset. +# +# Since: 1.4 +## +{ 'type': 'HostTimeInfo', + 'data': { 'seconds': 'int', 'microseconds': 'int', + 'utc-offset': 'int' } } + +## # @GuestAgentCommandInfo: # # Information about guest agent commands.Signature · 1 line
1.7.7.6
Re: [Qemu-devel] [PATCH 1/3] qga: add support to get host time
Quoted 15 lines · mdroth
Quoted 14 lines · Lei Li
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 18 ++++++++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-)qga/commands-posix.c +0
-0@@ -91,6 +91,24 @@ exit_err:error_set (err,QERR_UNDEFINED_ERROR ); }
Quoted 5 lines
qga/commands-posix.c exit_err: · line 95
Quoted 2 lines
qga/commands-posix.c +2
-0+static HostTimeInfo *get_host_time (void ) +{Should squash this into patch #2, since it doesn't get used till then. Otherwise we'll break build bisection when compiling with -Wunused/-Wall && -Werror, which is usually the default.
ok, got it.
Thanks!
Quoted 50 lines
Quoted 50 lines
qga/commands-posix.c +16
-0+int err; +qemu_timeval tq; +HostTimeInfo *host_time; + + err =qemu_gettimeofday (&tq); +if (err <0 ) { +return NULL ; + } + + host_time =g_malloc0 (sizeof (HostTimeInfo)); + host_time->seconds = tq.tv_sec; + host_time->microseconds = tq.tv_usec; + +return host_time; +} + typedef struct GuestFileHandle { uint64_t id; FILE *fh;qga/qapi-schema.json +17
-0@@ -83,6 +83,23 @@ { 'command': 'guest-ping' } ## +# @HostTimeInfo +# +# Information about host time. +# +# @seconds: "seconds" time from the host. +# +# @microseconds: "microseconds" time from the host. +# +# @utc-offset: information about utc offset. +# +# Since: 1.4 +## +{ 'type': 'HostTimeInfo', + 'data': { 'seconds': 'int', 'microseconds': 'int', + 'utc-offset': 'int' } } + +## # @GuestAgentCommandInfo: # # Information about guest agent commands.Signature · 1 line
1.7.7.6
Signature · 1 line
Lei
PATCH 2/3 qga: add guest-get-time command
In reply to Lei Li--- qga/commands-posix.c | 12 ++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 0 deletions(-)
qga/commands-posix.c +12 -0
@@ -109,6 +109,18 @@ static HostTimeInfo *get_host_time(void)return host_time; } +struct HostTimeInfo *qmp_guest_get_time (Error **errp) +{ +HostTimeInfo *host_time =get_host_time (); + +if (!host_time) { +error_set (errp,QERR_QGA_COMMAND_FAILED ,"Failed to get host time" ); +return NULL ; + } + +return host_time; +} + typedef struct GuestFileHandle { uint64_t id; FILE *fh;
qga/qapi-schema.json +17 -0
@@ -100,6 +100,23 @@ 'utc-offset': 'int' } } ## +# @guest-get-time: +# +# Get the information about host time in UTC and the +# UTC offset. +# +# This command tries to get the host time which is +# presumably correct, since need to be able to resynchronize +# clock to host in guest. +# +# Returns: @HostTimeInfo on success. +# +# Since 1.4 +## +{ 'command': 'guest-get-time', + 'returns': 'HostTimeInfo' } + +## # @GuestAgentCommandInfo: # # Information about guest agent commands.
Signature · 1 line
1.7.7.6
Re: [Qemu-devel] [PATCH 2/3] qga: add guest-get-time command
Quoted 9 lines · Lei Li
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 12 ++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 0 deletions(-)+++
b/qga/qapi-schema.json
qga/qapi-schema.json line 106
Quoted 7 lines
qga/qapi-schema.json +4
-0@@ -100,6 +100,23 @@ 'utc-offset': 'int' } } ## +# @guest-get-time: +# +# Get the information about host time in UTC and the +# UTC offset.
About the host time, or about the guest time? In other words, doesn't this command exist for the host to ask the guest what time the _guest_ thinks it is, so that the host can then decide whether to issue a followup command to tell the guest to adjust its time?
qga/qapi-schema.json line 112
Quoted 6 lines
qga/qapi-schema.json +6
-0+# +# This command tries to get the host time which is +# presumably correct, since need to be able to resynchronize +# clock to host in guest. +# +# Returns: @HostTimeInfo on success.
For that matter, should we name the type in patch 1/3 'TimeInfo', instead of 'HostTimeInfo', as it is not intrinsically tied to host or guest, but more a function of who is being queried?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 2/3] qga: add guest-get-time command
Quoted 11 lines · Eric Blake
Quoted 10 lines · Lei Li
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 12 ++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 0 deletions(-)+++
b/qga/qapi-schema.jsonqga/qapi-schema.json +0
-0@@ -100,6 +100,23 @@ 'utc-offset': 'int' } }
Quoted 9 lines
qga/qapi-schema.json line 106
Quoted 5 lines
qga/qapi-schema.json +4
-0## +# @guest-get-time: +# +# Get the information about host time in UTC and the +# UTC offset.About the host time, or about the guest time? In other words, doesn't this command exist for the host to ask the guest what time the _guest_ thinks it is, so that the host can then decide whether to issue a followup command to tell the guest to adjust its time?
No, this command is for getting host time. You might want to take a look at the RFC and the reply from Mike I sent few days ago for suggestions and discussions.
http://article.gmane.org/gmane.comp.emulators.qemu/186126
Quoted 9 lines
qga/qapi-schema.json line 112
Quoted 6 lines
qga/qapi-schema.json +6
-0+# +# This command tries to get the host time which is +# presumably correct, since need to be able to resynchronize +# clock to host in guest. +# +# Returns: @HostTimeInfo on success.For that matter, should we name the type in patch 1/3 'TimeInfo', instead of 'HostTimeInfo', as it is not intrinsically tied to host or guest, but more a function of who is being queried?
Yes, it make sense. Luiz feel confused about this 'HostTimeInfo' too, I think 'TimeInfo' might be a good idea. :)
Signature · 1 line
Lei
Re: [Qemu-devel] [PATCH 2/3] qga: add guest-get-time command
Quoted 21 lines · Lei Li
Quoted 7 lines · Eric Blake
Quoted 6 lines · Lei Li
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 12 ++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 0 deletions(-)Quoted 12 lines
qga/qapi-schema.json line 105
Quoted 8 lines
+++
b/qga/qapi-schema.jsonqga/qapi-schema.json +4
-0@@ -100,6 +100,23 @@ 'utc-offset': 'int' } } ## +# @guest-get-time: +# +# Get the information about host time in UTC and the +# UTC offset.About the host time, or about the guest time? In other words, doesn't this command exist for the host to ask the guest what time the _guest_ thinks it is, so that the host can then decide whether to issue a followup command to tell the guest to adjust its time?
Quoted 5 lines
No, this command is for getting host time. You might want to take a look at the RFC and the reply from Mike I sent few days ago for suggestions and discussions.
As mentioned elsewhere, what your guest-get-time implementation is actually returning is the guest time. But that's exactly what we want, since it provides all the information the host needs to calculate what value it should pass to guest-set-time (really we just need the utc-offset for this, but the other values are useful for other use cases. In fact, if you document guest-*-time to always return values relative to UTC 1970 epoch, we don't even actually need *that* unless we need to change the guest utc-offset for some reason, but again, nice to handle other use cases)
Quoted 11 lines
Quoted 10 lines
qga/qapi-schema.json line 112
Quoted 7 lines
qga/qapi-schema.json +6
-0+# +# This command tries to get the host time which is +# presumably correct, since need to be able to resynchronize +# clock to host in guest. +# +# Returns: @HostTimeInfo on success.For that matter, should we name the type in patch 1/3 'TimeInfo', instead of 'HostTimeInfo', as it is not intrinsically tied to host or guest, but more a function of who is being queried?
Quoted 2 lines
Yes, it make sense. Luiz feel confused about this 'HostTimeInfo' too, I think 'TimeInfo' might be a good idea. :)
Fourth'd :)
Quoted 6 lines
Signature · 2 lines
-- Lei
Re: [Qemu-devel] [PATCH 2/3] qga: add guest-get-time command
In reply to Lei LiQuoted 11 lines · On Sun, 6 Jan 2013 18:06:59 +0800 Lei Li <[email protected]> wrote:
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 12 ++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 0 deletions(-)qga/commands-posix.c +0
-0
qga/commands-posix.c static HostTimeInfo *get_host_time(void) · line 114
Quoted 6 lines
qga/commands-posix.c +3
-0@@ -109,6 +109,18 @@ static HostTimeInfo *get_host_time(void)return host_time; } +struct HostTimeInfo *qmp_guest_get_time (Error **errp) +{ +HostTimeInfo *host_time =get_host_time ();
The command is called guest_get_time() and runs in the guest, but it returns HostTimeInfo. Is this correct?
Quoted 40 lines
qga/commands-posix.c +9
-0+ +if (!host_time) { +error_set (errp,QERR_QGA_COMMAND_FAILED ,"Failed to get host time" ); +return NULL ; + } + +return host_time; +} + typedef struct GuestFileHandle { uint64_t id; FILE *fh;qga/qapi-schema.json +17
-0@@ -100,6 +100,23 @@ 'utc-offset': 'int' } } ## +# @guest-get-time: +# +# Get the information about host time in UTC and the +# UTC offset. +# +# This command tries to get the host time which is +# presumably correct, since need to be able to resynchronize +# clock to host in guest. +# +# Returns: @HostTimeInfo on success. +# +# Since 1.4 +## +{ 'command': 'guest-get-time', + 'returns': 'HostTimeInfo' } + +## # @GuestAgentCommandInfo: # # Information about guest agent commands.
Re: [Qemu-devel] [PATCH 2/3] qga: add guest-get-time command
Quoted 17 lines · Luiz Capitulino
Quoted 14 lines · On Sun, 6 Jan 2013 18:06:59 +0800 Lei Li <[email protected]> wrote:
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 12 ++++++++++++ qga/qapi-schema.json | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 0 deletions(-)qga/commands-posix.c +0
-0@@ -109,6 +109,18 @@ static HostTimeInfo *get_host_time(void)return host_time; }
Quoted 5 lines
qga/commands-posix.c static HostTimeInfo *get_host_time(void) · line 114
Quoted 3 lines
qga/commands-posix.c +3
-0+struct HostTimeInfo *qmp_guest_get_time (Error **errp) +{ +HostTimeInfo *host_time =get_host_time ();The command is called
guest_get_time()and runs in the guest, but it returns HostTimeInfo. Is this correct?
Okay, looks like this 'HostTimeInfo' brings a lots of confusion. I will change it to 'TimeInfo' as I replied to another patch.
Quoted 40 lines
Quoted 40 lines
qga/commands-posix.c +9
-0+ +if (!host_time) { +error_set (errp,QERR_QGA_COMMAND_FAILED ,"Failed to get host time" ); +return NULL ; + } + +return host_time; +} + typedef struct GuestFileHandle { uint64_t id; FILE *fh;qga/qapi-schema.json +17
-0@@ -100,6 +100,23 @@ 'utc-offset': 'int' } } ## +# @guest-get-time: +# +# Get the information about host time in UTC and the +# UTC offset. +# +# This command tries to get the host time which is +# presumably correct, since need to be able to resynchronize +# clock to host in guest. +# +# Returns: @HostTimeInfo on success. +# +# Since 1.4 +## +{ 'command': 'guest-get-time', + 'returns': 'HostTimeInfo' } + +## # @GuestAgentCommandInfo: # # Information about guest agent commands.
Signature · 1 line
Lei
PATCH 3/3 qga: add guest-set-time command
In reply to Lei Li--- qga/commands-posix.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ qga/qapi-schema.json | 32 ++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 0 deletions(-)
qga/commands-posix.c +57 -0
@@ -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)) { + 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; + tv.tv_usec = (time_t ) microseconds; + }else { +error_set (errp,QERR_INVALID_PARAMETER ,"parameter missing" ); +return ; + } + + ret =settimeofday (&tv,NULL ); +if (ret <0 ) { +error_set (errp,QERR_QGA_COMMAND_FAILED ,strerror (errno)); +return ; + } + +/* Set the Hardware Clock to the current System Time. */ + pid =fork (); +if (pid ==0 ) { +setsid (); +reopen_fd_to_null (0 ); +reopen_fd_to_null (1 ); +reopen_fd_to_null (2 ); + +execle ("/sbin/hwclock" ,"hwclock" ,"-w" ,NULL , environ); +_exit (EXIT_FAILURE ); + }else if (pid <0 ) { + goto exit_err; + } + +do { + rpid =waitpid (pid, &status,0 ); + }while (rpid ==-1 && errno ==EINTR ); +if (rpid == pid &&WIFEXITED (status) && !WEXITSTATUS (status)) { +return ; + } + +exit_err: +error_set (errp,QERR_UNDEFINED_ERROR ); +} + typedef struct GuestFileHandle { uint64_t id; FILE *fh;
qga/qapi-schema.json +32 -0
@@ -117,6 +117,38 @@ 'returns': 'HostTimeInfo' } ## +# @guest-set-time: +# +# Set guest time. If none arguments were given, will set +# 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. +# +# Returns: Nothing on success. +# +# Since: 1.4 +## +{ 'command': 'guest-set-time', + 'data': { '*seconds': 'int', '*microseconds': 'int', + '*utc-offset': 'int' } } + +## # @GuestAgentCommandInfo: # # Information about guest agent commands.
Signature · 1 line
1.7.7.6
Re: [Qemu-devel] [PATCH 3/3] qga: add guest-set-time command
Quoted 15 lines · Lei Li
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ qga/qapi-schema.json | 32 ++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 0 deletions(-)qga/commands-posix.c +1
-0@@ -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,
qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 134
Quoted 10 lines
qga/commands-posix.c +10
-0+ 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?
qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 143
Quoted 9 lines
qga/commands-posix.c +9
-0+ 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?).
qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 144
Quoted 1 line
qga/commands-posix.c +1
-0+ 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()).
qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 146
Quoted 2 lines
qga/commands-posix.c +2
-0+ }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);
...
}qga/commands-posix.c line 122
Quoted 8 lines
qga/commands-posix.c +4
-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/
Quoted 9 lines
qga/commands-posix.c +9
-0+# 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
qga/commands-posix.c line 141
Quoted 10 lines
qga/commands-posix.c +10
-0+# 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.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 3/3] qga: add guest-set-time command
Quoted 60 lines · Eric Blake
Quoted 15 lines · Lei Li
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ qga/qapi-schema.json | 32 ++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 0 deletions(-)qga/commands-posix.c +1
-0@@ -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,qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 134
Quoted 10 lines
qga/commands-posix.c +10
-0+ 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?
qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 143
Quoted 9 lines
qga/commands-posix.c +9
-0+ 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_tis 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?).qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 144
Quoted 1 line
qga/commands-posix.c +1
-0+ 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()).qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 146
Quoted 2 lines
qga/commands-posix.c +2
-0+ }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 orutc_offsetas 0
seconds missing, but other fields present - errormaking this look more like:
Quoted 10 lines
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);
...
}Good suggestions!
Yes, I know this is harsh. I will improve it in next version, as well as the document.
Quoted 34 lines
qga/commands-posix.c line 122
Quoted 8 lines
qga/commands-posix.c +4
-0+++ b/qga/qapi-schema.json@@ -117,6 +117,38 @@ 'returns': 'HostTimeInfo' } ## +# @guest-set-time: +# +# Set guest time. If none arguments were given, will sets/none/no/
Quoted 9 lines
qga/commands-posix.c +9
-0+# 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 informationqga/commands-posix.c line 141
Quoted 10 lines
qga/commands-posix.c +10
-0+# 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.
Quoted 5 lines
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.
Sure. About the utc-offset format, I have replied to the previous patch. It would be one-hour offset, and it's my mistake here...:(
Quoted 1 line
Signature · 1 line
Lei
Re: [Qemu-devel] [PATCH 3/3] qga: add guest-set-time command
In reply to Lei LiQuoted 18 lines · On Sun, 6 Jan 2013 18:07:00 +0800 Lei Li <[email protected]> wrote:
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ qga/qapi-schema.json | 32 ++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 0 deletions(-)qga/commands-posix.c +4
-0@@ -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) +{
qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 137
Quoted 10 lines
qga/commands-posix.c +10
-0+int ret; +int status; +pid_t pid, rpid; +struct timeval tv; +HostTimeInfo *host_time; + +if ((!has_seconds) && (!has_microseconds) && (!has_utc_offset)) { + host_time =get_host_time (); +if (!host_time) { +error_set (errp,QERR_QGA_COMMAND_FAILED ,"Failed to set guest time" );
If you change get_host_time() to take an Error * argument, you can drop this.
qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 146
Quoted 9 lines
qga/commands-posix.c +9
-0+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; + tv.tv_usec = (time_t ) microseconds; + }else { +error_set (errp,QERR_INVALID_PARAMETER ,"parameter missing" );
Please, use error_setg() instead.
qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 152
Quoted 6 lines
qga/commands-posix.c +6
-0+return ; + } + + ret =settimeofday (&tv,NULL ); +if (ret <0 ) { +error_set (errp,QERR_QGA_COMMAND_FAILED ,strerror (errno));
Please, use error_setg_errno().
qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 164
Quoted 12 lines
qga/commands-posix.c +12
-0+return ; + } + +/* Set the Hardware Clock to the current System Time. */ + pid =fork (); +if (pid ==0 ) { +setsid (); +reopen_fd_to_null (0 ); +reopen_fd_to_null (1 ); +reopen_fd_to_null (2 ); + +execle ("/sbin/hwclock" ,"hwclock" ,"-w" ,NULL , environ);
Honest question: is this really necessary? Can't we do whatever hwclock does?
Quoted 62 lines
qga/commands-posix.c +16
-0+_exit (EXIT_FAILURE ); + }else if (pid <0 ) { + goto exit_err; + } + +do { + rpid =waitpid (pid, &status,0 ); + }while (rpid ==-1 && errno ==EINTR ); +if (rpid == pid &&WIFEXITED (status) && !WEXITSTATUS (status)) { +return ; + } + +exit_err: +error_set (errp,QERR_UNDEFINED_ERROR ); +} + typedef struct GuestFileHandle { uint64_t id; FILE *fh;qga/qapi-schema.json +32
-0@@ -117,6 +117,38 @@ 'returns': 'HostTimeInfo' } ## +# @guest-set-time: +# +# Set guest time. If none arguments were given, will set +# 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. +# +# Returns: Nothing on success. +# +# Since: 1.4 +## +{ 'command': 'guest-set-time', + 'data': { '*seconds': 'int', '*microseconds': 'int', + '*utc-offset': 'int' } } + +## # @GuestAgentCommandInfo: # # Information about guest agent commands.
Re: [Qemu-devel] [PATCH 3/3] qga: add guest-set-time command
Quoted 17 lines · Luiz Capitulino
Quoted 14 lines · On Sun, 6 Jan 2013 18:07:00 +0800 Lei Li <[email protected]> wrote:
Signed-off-by Lei Li <[email protected]>--- qga/commands-posix.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ qga/qapi-schema.json | 32 ++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 0 deletions(-)qga/commands-posix.c +0
-0@@ -121,6 +121,63 @@ struct HostTimeInfo *qmp_guest_get_time(Error **errp)return host_time; }
Quoted 15 lines
Quoted 4 lines
qga/commands-posix.c +4
-0+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) +{qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 137
Quoted 10 lines
qga/commands-posix.c +10
-0+int ret; +int status; +pid_t pid, rpid; +struct timeval tv; +HostTimeInfo *host_time; + +if ((!has_seconds) && (!has_microseconds) && (!has_utc_offset)) { + host_time =get_host_time (); +if (!host_time) { +error_set (errp,QERR_QGA_COMMAND_FAILED ,"Failed to set guest time" );If you change
get_host_time()to take an Error * argument, you can drop this.
ok.
Quoted 10 lines
qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 146
Quoted 9 lines
qga/commands-posix.c +9
-0+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; + tv.tv_usec = (time_t ) microseconds; + }else { +error_set (errp,QERR_INVALID_PARAMETER ,"parameter missing" );Please, use
error_setg()instead.
Sure.
Quoted 8 lines
qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 152
Quoted 6 lines
qga/commands-posix.c +6
-0+return ; + } + + ret =settimeofday (&tv,NULL ); +if (ret <0 ) { +error_set (errp,QERR_QGA_COMMAND_FAILED ,strerror (errno));Please, use
error_setg_errno().
Yes.
Quoted 5 lines
Quoted 5 lines
qga/commands-posix.c +5
-0+return ; + } + +/* Set the Hardware Clock to the current System Time. */ + pid =fork ();
Quoted 9 lines
qga/commands-posix.c struct HostTimeInfo *qmp_guest_get_time(Error **errp) · line 164
Quoted 7 lines
qga/commands-posix.c +7
-0+if (pid ==0 ) { +setsid (); +reopen_fd_to_null (0 ); +reopen_fd_to_null (1 ); +reopen_fd_to_null (2 ); + +execle ("/sbin/hwclock" ,"hwclock" ,"-w" ,NULL , environ);Honest question: is this really necessary? Can't we do whatever hwclock does?
I have thought about implementing this ourselves, and I did take a look at the source code of hwclock. But looks like the implement ofthe synchronization for hardware clock and system clock is a little complicated, so I am not sure if it's worth to have a try here.
Quoted 63 lines
Quoted 62 lines
qga/commands-posix.c +16
-0+_exit (EXIT_FAILURE ); + }else if (pid <0 ) { + goto exit_err; + } + +do { + rpid =waitpid (pid, &status,0 ); + }while (rpid ==-1 && errno ==EINTR ); +if (rpid == pid &&WIFEXITED (status) && !WEXITSTATUS (status)) { +return ; + } + +exit_err: +error_set (errp,QERR_UNDEFINED_ERROR ); +} + typedef struct GuestFileHandle { uint64_t id; FILE *fh;qga/qapi-schema.json +32
-0@@ -117,6 +117,38 @@ 'returns': 'HostTimeInfo' } ## +# @guest-set-time: +# +# Set guest time. If none arguments were given, will set +# 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. +# +# Returns: Nothing on success. +# +# Since: 1.4 +## +{ 'command': 'guest-set-time', + 'data': { '*seconds': 'int', '*microseconds': 'int', + '*utc-offset': 'int' } } + +## # @GuestAgentCommandInfo: # # Information about guest agent commands.
Signature · 1 line
Lei
Quoted 6 lines · Lei Li
This patch series attempts to add time resync support to qemu-ga by introducing qemu-ga commands guest-get-time and guest-set-time.
Quoted 7 lines
The interface for these commands like:
{ 'command': 'guest-get-time', 'returns': 'HostTimeInfo' }
{ 'command': 'guest-set-time',
'data': { '*seconds': 'int', '*microseconds': 'int','*utc-offset': 'int' } }
Why are these fields marked optional? I guess I'll find out in the actual patch, but at first glance, I think all three would be mandatory.
Quoted 6 lines
TODO:
This is a RFC version with POSIX-specific command implemented. I just test on Linux guest, will add win32-specific command to support Windows guest later. Since I want to make sure if this seems like the way we should be headed.
I hope that you just meant that you are lacking a win32 implementation of the command, but that when it is implemented, it will still use the same interface. That is, even though windows itself doesn't use POSIX time, and has a different Epoch than Jan 1 1970, such differences should be transparent to the user, who should always pass a POSIX timestamp through the interface. What we don't want is two different commands, where the management app then has to know whether the guest is Unix or Windows based, to know which of the two commands to send.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 20 lines · Eric Blake
Quoted 11 lines · Lei Li
This patch series attempts to add time resync support to qemu-ga by introducing qemu-ga commands guest-get-time and guest-set-time.
The interface for these commands like:
{ 'command': 'guest-get-time', 'returns': 'HostTimeInfo' }
{ 'command': 'guest-set-time',
'data': { '*seconds': 'int', '*microseconds': 'int','*utc-offset': 'int' } }Why are these fields marked optional? I guess I'll find out in the actual patch, but at first glance, I think all three would be mandatory.
Quoted 5 lines
TODO:
This is a RFC version with POSIX-specific command implemented. I just test on Linux guest, will add win32-specific command to support Windows guest later. Since I want to make sure if this seems like the way we should be headed.
Quoted 8 lines
I hope that you just meant that you are lacking a win32 implementation of the command, but that when it is implemented, it will still use the same interface. That is, even though windows itself doesn't use POSIX time, and has a different Epoch than Jan 1 1970, such differences should be transparent to the user, who should always pass a POSIX timestamp through the interface. What we don't want is two different commands, where the management app then has to know whether the guest is Unix or Windows based, to know which of the two commands to send.
Yes, I mean that there is win32 implementation of this command lacking. And thanks for your reminder of the differences for the Epoch between Linux and Windows.
Signature · 1 line
Lei