diff options
author | Lei Li <lilei@linux.vnet.ibm.com> | 2013-03-15 17:29:05 +0800 |
---|---|---|
committer | Michael Roth <mdroth@linux.vnet.ibm.com> | 2013-04-02 09:06:11 -0500 |
commit | b8f954fea019801370954fe85c32df49edf6397d (patch) | |
tree | b7da45658f44e755b105bd07464cfe0e95a2a88f /qga/commands-win32.c | |
parent | 3f2a6087de291dc96a2c4975139da27649cf32ff (diff) |
qga: add windows implementation for guest-set-time
Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qga/commands-win32.c')
-rw-r--r-- | qga/commands-win32.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/qga/commands-win32.c b/qga/commands-win32.c index d98e3eeff0..24e4ad0319 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) |