From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:42141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UN1zu-0006U3-0I for qemu-devel@nongnu.org; Tue, 02 Apr 2013 10:15:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UN1zm-0008Gw-5p for qemu-devel@nongnu.org; Tue, 02 Apr 2013 10:15:37 -0400 Received: from mail-yh0-x22c.google.com ([2607:f8b0:4002:c01::22c]:61540) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UN1zm-0008Go-0s for qemu-devel@nongnu.org; Tue, 02 Apr 2013 10:15:30 -0400 Received: by mail-yh0-f44.google.com with SMTP id q11so58931yhf.17 for ; Tue, 02 Apr 2013 07:15:29 -0700 (PDT) Sender: fluxion From: Michael Roth Date: Tue, 2 Apr 2013 09:13:10 -0500 Message-Id: <1364911993-31042-3-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1364911993-31042-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1364911993-31042-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 2/5] qga: add windows implementation for guest-set-time List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, lersek@redhat.com, lilei@linux.vnet.ibm.com, lcapitulino@redhat.com From: Lei Li Signed-off-by: Lei Li Reviewed-by: Eric Blake Reviewed-by: Michael Roth Signed-off-by: Michael Roth --- 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.9.5