From patchwork Fri Mar 15 09:29:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 227909 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4B6E72C009C for ; Fri, 15 Mar 2013 20:30:57 +1100 (EST) Received: from localhost ([::1]:48138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGQyV-0005Jx-FP for incoming@patchwork.ozlabs.org; Fri, 15 Mar 2013 05:30:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGQxi-0004UN-Nx for qemu-devel@nongnu.org; Fri, 15 Mar 2013 05:30:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UGQxe-0000Kc-Ex for qemu-devel@nongnu.org; Fri, 15 Mar 2013 05:30:06 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:37828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGQxd-0000Cs-Ug for qemu-devel@nongnu.org; Fri, 15 Mar 2013 05:30:02 -0400 Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 15 Mar 2013 19:22:04 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp09.au.ibm.com (202.81.31.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 15 Mar 2013 19:22:01 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 7C34B3578051 for ; Fri, 15 Mar 2013 20:29:56 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2F9GdPg11207126 for ; Fri, 15 Mar 2013 20:16:39 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2F9TP5D011297 for ; Fri, 15 Mar 2013 20:29:25 +1100 Received: from localhost.cn.ibm.com ([9.115.122.48]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r2F9TIop011101; Fri, 15 Mar 2013 20:29:24 +1100 From: Lei Li To: qemu-devel@nongnu.org Date: Fri, 15 Mar 2013 17:29:05 +0800 Message-Id: <1363339745-15639-3-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1363339745-15639-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1363339745-15639-1-git-send-email-lilei@linux.vnet.ibm.com> x-cbid: 13031509-3568-0000-0000-0000034B6058 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.142 Cc: aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, Lei Li Subject: [Qemu-devel] [PATCH 2/2] qga: add windows implementation for guest-set-time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Lei Li --- 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)