@@ -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'"
@@ -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;
@@ -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.
Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com> --- include/qapi/qmp/qerror.h | 3 +++ qga/commands-posix.c | 30 ++++++++++++++++++++++++++++++ qga/qapi-schema.json | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 0 deletions(-)