* [Qemu-devel] [PATCH 0/2 v7] Add Windows support for time resync by qemu-ga
@ 2013-03-15 9:29 Lei Li
2013-03-15 9:29 ` [Qemu-devel] [PATCH 1/2] qga: add windows implementation for guest-get-time Lei Li
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Lei Li @ 2013-03-15 9:29 UTC (permalink / raw)
To: qemu-devel; +Cc: aliguori, mdroth, Lei Li
This patch series attempts to add Windows implementation
for qemu-ga commands guest-get-time and guest-set-time.
The previous thread about the interfaces introduced and
the POSIX-specific command implementation has already
been accepted, the reference link:
http://article.gmane.org/gmane.comp.emulators.qemu/198472
Notes:
Now It was tested on Windows XP SP3 and Windows 7.
Please comment!
Thanks.
Changes since v6:
- Fix other error handel that I missed.
Changes since v5:
- Fix the error check for GetSystemTime() from Michael.
- Other fixups from Michael.
Changes since v4:
- Error handel improvement from Michael.
- Do the math explicitly for the time convert of FILETIME
suggested by Michael.
Changes since v3:
- Reorder the acquire_privilege to avoid a possible
leak of privileges suggested by Eric.
Changes since v2:
- Overflow check improvement for time_ns from Eric.
Changes since v1:
- Make the macro for the offset between windows baseline
and Unix Epoch more readable from Eric.
- Overflow check for filetime pointed by Eric.
Lei Li (2):
qga: add windows implementation for guest-get-time
qga: add windows implementation for guest-set-time
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/2] qga: add windows implementation for guest-get-time
2013-03-15 9:29 [Qemu-devel] [PATCH 0/2 v7] Add Windows support for time resync by qemu-ga Lei Li
@ 2013-03-15 9:29 ` Lei Li
2013-03-15 9:29 ` [Qemu-devel] [PATCH 2/2] qga: add windows implementation for guest-set-time Lei Li
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Lei Li @ 2013-03-15 9:29 UTC (permalink / raw)
To: qemu-devel; +Cc: aliguori, mdroth, Lei Li
Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
---
qga/commands-win32.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index b19be9d..d98e3ee 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -22,6 +22,12 @@
#define SHTDN_REASON_FLAG_PLANNED 0x80000000
#endif
+/* multiple of 100 nanoseconds elapsed between windows baseline
+ * (1/1/1601) and Unix Epoch (1/1/1970), accounting for leap years */
+#define W32_FT_OFFSET (10000000ULL * 60 * 60 * 24 * \
+ (365 * (1970 - 1601) + \
+ (1970 - 1601) / 4 - 3))
+
static void acquire_privilege(const char *name, Error **err)
{
HANDLE token;
@@ -280,8 +286,25 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **err)
int64_t qmp_guest_get_time(Error **errp)
{
- error_set(errp, QERR_UNSUPPORTED);
- return -1;
+ SYSTEMTIME ts = {0};
+ int64_t time_ns;
+ FILETIME tf;
+
+ GetSystemTime(&ts);
+ if (ts.wYear < 1601 || ts.wYear > 30827) {
+ error_setg(errp, "Failed to get time");
+ return -1;
+ }
+
+ if (!SystemTimeToFileTime(&ts, &tf)) {
+ error_setg(errp, "Failed to convert system time: %d", (int)GetLastError());
+ return -1;
+ }
+
+ time_ns = ((((int64_t)tf.dwHighDateTime << 32) | tf.dwLowDateTime)
+ - W32_FT_OFFSET) * 100;
+
+ return time_ns;
}
void qmp_guest_set_time(int64_t time_ns, Error **errp)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/2] qga: add windows implementation for guest-set-time
2013-03-15 9:29 [Qemu-devel] [PATCH 0/2 v7] Add Windows support for time resync by qemu-ga Lei Li
2013-03-15 9:29 ` [Qemu-devel] [PATCH 1/2] qga: add windows implementation for guest-get-time Lei Li
@ 2013-03-15 9:29 ` Lei Li
2013-03-15 14:46 ` [Qemu-devel] [PATCH 0/2 v7] Add Windows support for time resync by qemu-ga Eric Blake
2013-03-25 16:18 ` mdroth
3 siblings, 0 replies; 5+ messages in thread
From: Lei Li @ 2013-03-15 9:29 UTC (permalink / raw)
To: qemu-devel; +Cc: aliguori, mdroth, Lei Li
Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
---
qga/commands-win32.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index d98e3ee..24e4ad0 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -309,7 +309,34 @@ int64_t qmp_guest_get_time(Error **errp)
void qmp_guest_set_time(int64_t time_ns, Error **errp)
{
- error_set(errp, QERR_UNSUPPORTED);
+ SYSTEMTIME ts;
+ FILETIME tf;
+ LONGLONG time;
+
+ if (time_ns < 0 || time_ns / 100 > INT64_MAX - W32_FT_OFFSET) {
+ error_setg(errp, "Time %" PRId64 "is invalid", time_ns);
+ return;
+ }
+
+ time = time_ns / 100 + W32_FT_OFFSET;
+
+ tf.dwLowDateTime = (DWORD) time;
+ tf.dwHighDateTime = (DWORD) (time >> 32);
+
+ if (!FileTimeToSystemTime(&tf, &ts)) {
+ error_setg(errp, "Failed to convert system time %d", (int)GetLastError());
+ return;
+ }
+
+ acquire_privilege(SE_SYSTEMTIME_NAME, errp);
+ if (error_is_set(errp)) {
+ return;
+ }
+
+ if (!SetSystemTime(&ts)) {
+ error_setg(errp, "Failed to set time to guest: %d", (int)GetLastError());
+ return;
+ }
}
GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2 v7] Add Windows support for time resync by qemu-ga
2013-03-15 9:29 [Qemu-devel] [PATCH 0/2 v7] Add Windows support for time resync by qemu-ga Lei Li
2013-03-15 9:29 ` [Qemu-devel] [PATCH 1/2] qga: add windows implementation for guest-get-time Lei Li
2013-03-15 9:29 ` [Qemu-devel] [PATCH 2/2] qga: add windows implementation for guest-set-time Lei Li
@ 2013-03-15 14:46 ` Eric Blake
2013-03-25 16:18 ` mdroth
3 siblings, 0 replies; 5+ messages in thread
From: Eric Blake @ 2013-03-15 14:46 UTC (permalink / raw)
To: Lei Li; +Cc: aliguori, qemu-devel, mdroth
[-- Attachment #1: Type: text/plain, Size: 635 bytes --]
On 03/15/2013 03:29 AM, Lei Li wrote:
> This patch series attempts to add Windows implementation
> for qemu-ga commands guest-get-time and guest-set-time.
>
> The previous thread about the interfaces introduced and
> the POSIX-specific command implementation has already
> been accepted, the reference link:
>
> http://article.gmane.org/gmane.comp.emulators.qemu/198472
>
> Notes:
> Now It was tested on Windows XP SP3 and Windows 7.
> Please comment!
Series: Reviewed-by: Eric Blake <eblake@redhat.com>
--
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: 621 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 0/2 v7] Add Windows support for time resync by qemu-ga
2013-03-15 9:29 [Qemu-devel] [PATCH 0/2 v7] Add Windows support for time resync by qemu-ga Lei Li
` (2 preceding siblings ...)
2013-03-15 14:46 ` [Qemu-devel] [PATCH 0/2 v7] Add Windows support for time resync by qemu-ga Eric Blake
@ 2013-03-25 16:18 ` mdroth
3 siblings, 0 replies; 5+ messages in thread
From: mdroth @ 2013-03-25 16:18 UTC (permalink / raw)
To: Lei Li; +Cc: aliguori, qemu-devel
On Fri, Mar 15, 2013 at 05:29:03PM +0800, Lei Li wrote:
> This patch series attempts to add Windows implementation
> for qemu-ga commands guest-get-time and guest-set-time.
Thanks, applied to qga branch.
>
> The previous thread about the interfaces introduced and
> the POSIX-specific command implementation has already
> been accepted, the reference link:
>
> http://article.gmane.org/gmane.comp.emulators.qemu/198472
>
> Notes:
> Now It was tested on Windows XP SP3 and Windows 7.
> Please comment!
>
> Thanks.
>
> Changes since v6:
> - Fix other error handel that I missed.
>
> Changes since v5:
> - Fix the error check for GetSystemTime() from Michael.
> - Other fixups from Michael.
>
> Changes since v4:
> - Error handel improvement from Michael.
> - Do the math explicitly for the time convert of FILETIME
> suggested by Michael.
>
> Changes since v3:
> - Reorder the acquire_privilege to avoid a possible
> leak of privileges suggested by Eric.
>
> Changes since v2:
> - Overflow check improvement for time_ns from Eric.
>
> Changes since v1:
> - Make the macro for the offset between windows baseline
> and Unix Epoch more readable from Eric.
> - Overflow check for filetime pointed by Eric.
>
> Lei Li (2):
> qga: add windows implementation for guest-get-time
> qga: add windows implementation for guest-set-time
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-03-25 16:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-15 9:29 [Qemu-devel] [PATCH 0/2 v7] Add Windows support for time resync by qemu-ga Lei Li
2013-03-15 9:29 ` [Qemu-devel] [PATCH 1/2] qga: add windows implementation for guest-get-time Lei Li
2013-03-15 9:29 ` [Qemu-devel] [PATCH 2/2] qga: add windows implementation for guest-set-time Lei Li
2013-03-15 14:46 ` [Qemu-devel] [PATCH 0/2 v7] Add Windows support for time resync by qemu-ga Eric Blake
2013-03-25 16:18 ` mdroth
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).