From patchwork Tue Apr 2 14:13:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 233009 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 211042C008E for ; Wed, 3 Apr 2013 01:17:35 +1100 (EST) Received: from localhost ([::1]:53080 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UN21l-0000V8-7g for incoming@patchwork.ozlabs.org; Tue, 02 Apr 2013 10:17:33 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=UTZkdG5FibSKsz2atO+KGbvRTsk4ubPRkt2F9GWn2y0=; b=k+WJi4css/32ny++UYfzJkGFDsUCPpZuytiaphHXbpTDCaQhanxgIoUYLIo3Z/1g8H YTUeNHbrRR1GKURkMnX/Rt6Jpf1JIt+kU2x0hGGgldWk18bj9vGrK0xho3F+6CjSBnmb VTpw42lnvD1klJ0yAiFOE+xvVnwzFPGsHJmZsHnqWUWqlL3K6uKfWds7JmI+5gul7I38 y5YehGIryUnrwwxydwz2orMFWeQCMMIGNVsmDu0MDuttPgUiPAmET6XNjYvYhFFYiKjV eLNHbN61JZrQS/eucH2XpnFCFFStEn86K2TDJRzu3pEIg+n7ORQ9un6jQ9O0Mwjt3KG7 DY3w== X-Received: by 10.236.24.170 with SMTP id x30mr14772471yhx.121.1364912129703; Tue, 02 Apr 2013 07:15:29 -0700 (PDT) Received: from localhost ([32.97.110.51]) by mx.google.com with ESMTPS id s45sm3208826yhk.22.2013.04.02.07.15.28 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 02 Apr 2013 07:15:29 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 2 Apr 2013 09:13:10 -0500 Message-Id: <1364911993-31042-3-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 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> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4002:c01::22c Cc: aliguori@us.ibm.com, lersek@redhat.com, lilei@linux.vnet.ibm.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 2/5] 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 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)