From patchwork Sun Jan 27 18:14:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lei Li X-Patchwork-Id: 216025 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 99EE42C0090 for ; Mon, 28 Jan 2013 05:14:56 +1100 (EST) Received: from localhost ([::1]:45175 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzWko-0006qz-HB for incoming@patchwork.ozlabs.org; Sun, 27 Jan 2013 13:14:54 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzWkZ-0006gB-Ef for qemu-devel@nongnu.org; Sun, 27 Jan 2013 13:14:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TzWkV-0008Ia-VI for qemu-devel@nongnu.org; Sun, 27 Jan 2013 13:14:39 -0500 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:42274) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TzWkV-0008ID-EY for qemu-devel@nongnu.org; Sun, 27 Jan 2013 13:14:35 -0500 Received: from /spool/local by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 28 Jan 2013 04:09:09 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 28 Jan 2013 04:09:08 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 0EB292BB004E for ; Mon, 28 Jan 2013 05:14:28 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r0RIERki49152234 for ; Mon, 28 Jan 2013 05:14:27 +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 r0RIERO6029941 for ; Mon, 28 Jan 2013 05:14:27 +1100 Received: from localhost.localdomain ([9.77.178.29]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r0RIEMrh029919; Mon, 28 Jan 2013 05:14:25 +1100 From: Lei Li To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2013 02:14:19 +0800 Message-Id: <1359310460-23564-2-git-send-email-lilei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1359310460-23564-1-git-send-email-lilei@linux.vnet.ibm.com> References: <1359310460-23564-1-git-send-email-lilei@linux.vnet.ibm.com> MIME-Version: 1.0 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13012718-6102-0000-0000-000002EBECC0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.145 Cc: aliguori@us.ibm.com, Lei Li , mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com Subject: [Qemu-devel] =?utf-8?q?=5BPATCH_1/2=5D_qga=3A_add_guest-get-time_?= =?utf-8?q?command?= 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 --- include/qapi/qmp/qerror.h | 3 +++ qga/commands-posix.c | 30 ++++++++++++++++++++++++++++++ qga/qapi-schema.json | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 0 deletions(-) diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h index 6c0a18d..0baf1a4 100644 --- a/include/qapi/qmp/qerror.h +++ b/include/qapi/qmp/qerror.h @@ -129,6 +129,9 @@ void assert_no_error(Error *err); #define QERR_FEATURE_DISABLED \ ERROR_CLASS_GENERIC_ERROR, "The feature '%s' is not enabled" +#define QERR_GET_TIME_FAILED \ + ERROR_CLASS_GENERIC_ERROR, "Failed to get time" + #define QERR_INVALID_BLOCK_FORMAT \ ERROR_CLASS_GENERIC_ERROR, "Invalid block format '%s'" diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 0ad73f3..2fef2b6 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -119,6 +119,36 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) /* succeded */ } +static TimeInfo *get_host_time(Error **errp) +{ + int ret; + qemu_timeval tq; + TimeInfo *time_info; + + ret = qemu_gettimeofday(&tq); + if (ret < 0) { + error_set_errno(errp, errno, QERR_GET_TIME_FAILED); + return NULL; + } + + time_info = g_malloc0(sizeof(TimeInfo)); + time_info->seconds = tq.tv_sec; + time_info->microseconds = tq.tv_usec; + + return time_info; +} + +struct TimeInfo *qmp_guest_get_time(Error **errp) +{ + TimeInfo *time_info = get_host_time(errp); + + if (!time_info) { + return NULL; + } + + return time_info; +} + typedef struct GuestFileHandle { uint64_t id; FILE *fh; diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index d91d903..d067fa5 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -83,6 +83,44 @@ { 'command': 'guest-ping' } ## +# @TimeInfo +# +# Time Information. It is relative to the Epoch of 1970-01-01. +# +# @seconds: "seconds" time unit. +# +# @microseconds: "microseconds" time unit. +# +# @utc-offset: Information about utc offset. Represented as: +# ±[mmmm] based at a minimum on minutes, with +# negative values are west and positive values +# are east of UTC. The bounds of @utc-offset is +# at most 24 hours away from UTC. +# +# Since: 1.4 +## +{ 'type': 'TimeInfo', + 'data': { 'seconds': 'int', 'microseconds': 'int', + 'utc-offset': 'int' } } + +## +# @guest-get-time: +# +# Get the information about host time in UTC and the +# UTC offset. +# +# This command tries to get the host time which is +# presumably correct, since we need to be able to +# resynchronize guest clock to host's in guest. +# +# Returns: @TimeInfo on success. +# +# Since 1.4 +## +{ 'command': 'guest-get-time', + 'returns': 'TimeInfo' } + +## # @GuestAgentCommandInfo: # # Information about guest agent commands.