qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/2] qga: add guest-get-time command


From: Lei Li
Subject: [Qemu-devel] [PATCH 1/2] qga: add guest-get-time command
Date: Mon, 28 Jan 2013 02:11:11 +0800

Signed-off-by: Lei Li <address@hidden>
---
 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.
-- 
1.7.7.6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]