From patchwork Wed Mar 6 13:45:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 225494 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 794CE2C0362 for ; Thu, 7 Mar 2013 00:47:02 +1100 (EST) Received: from localhost ([::1]:32982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDEgO-00036S-Oo for incoming@patchwork.ozlabs.org; Wed, 06 Mar 2013 08:47:00 -0500 Received: from eggs.gnu.org ([208.118.235.92]:36665) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDEf2-0001gh-Jn for qemu-devel@nongnu.org; Wed, 06 Mar 2013 08:45:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UDEex-00072S-Lv for qemu-devel@nongnu.org; Wed, 06 Mar 2013 08:45:36 -0500 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:59138) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDEex-000727-42 for qemu-devel@nongnu.org; Wed, 06 Mar 2013 08:45:31 -0500 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Mar 2013 23:35:40 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 6 Mar 2013 23:35:38 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 8CCAA2BB004F for ; Thu, 7 Mar 2013 00:45:25 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r26DWdBJ7602654 for ; Thu, 7 Mar 2013 00:32:39 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r26DjONo027197 for ; Thu, 7 Mar 2013 00:45:25 +1100 Received: from localhost.localdomain ([9.77.180.221]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r26DjGNZ027015; Thu, 7 Mar 2013 00:45:23 +1100 From: Lei Li To: qemu-devel@nongnu.org Date: Wed, 6 Mar 2013 21:45:04 +0800 Message-Id: <1362577504-7994-3-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1362577504-7994-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1362577504-7994-1-git-send-email-lilei@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13030613-9264-0000-0000-000003477F29 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.146 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 | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 4febec7..1a90aa7 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -136,6 +136,41 @@ int64_t qmp_guest_get_time(Error **errp) return time_ns; } +void qmp_guest_set_time(int64_t time_ns, Error **errp) +{ + SYSTEMTIME ts; + FILETIME tf; + LONGLONG time; + + /* year-2038 will overflow in case time_t is 32bit */ + if (time_ns / 1000000000 != (time_t)(time_ns / 1000000000)) { + error_setg(errp, "Time %" PRId64 " is too large", time_ns); + return; + } + + acquire_privilege(SE_SYSTEMTIME_NAME, errp); + if (error_is_set(errp)) { + error_setg(errp, "Failed to acquire privilege"); + 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"); + return; + } + + if (!SetSystemTime(&ts)) { + slog("guest-set-time failed: %d", GetLastError()); + error_setg_errno(errp, errno, "Failed to set time to guest"); + return; + } +} + int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Error **err) { error_set(err, QERR_UNSUPPORTED);