From b1e2f2d84d149e141f86f286a243536243862b55 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 29 Apr 2016 16:01:47 +0200 Subject: [PATCH] qemu: Introduce qemuMonitorGetRTCTime Signed-off-by: Michal Privoznik --- src/qemu/qemu_monitor.c | 11 ++++++++++ src/qemu/qemu_monitor.h | 3 +++ src/qemu/qemu_monitor_json.c | 41 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 3 +++ 4 files changed, 58 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 0170850c89..1f402eeb57 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3726,3 +3726,14 @@ qemuMonitorMigrateStartPostCopy(qemuMonitorPtr mon) return qemuMonitorJSONMigrateStartPostCopy(mon); } + +int +qemuMonitorGetRTCTime(qemuMonitorPtr mon, + struct tm *tm) +{ + VIR_DEBUG("mon=%p", mon); + + QEMU_CHECK_MONITOR_JSON(mon); + + return qemuMonitorJSONGetRTCTime(mon, tm); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 871ebe0bb4..4d8f21fc0b 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -933,4 +933,7 @@ int qemuMonitorMigrateIncoming(qemuMonitorPtr mon, int qemuMonitorMigrateStartPostCopy(qemuMonitorPtr mon); +int qemuMonitorGetRTCTime(qemuMonitorPtr mon, + struct tm *tm); + #endif /* QEMU_MONITOR_H */ diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e0dbda12a1..a48a263965 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6905,3 +6905,44 @@ qemuMonitorJSONMigrateStartPostCopy(qemuMonitorPtr mon) virJSONValueFree(reply); return ret; } + +int +qemuMonitorJSONGetRTCTime(qemuMonitorPtr mon, + struct tm *tm) +{ + int ret = -1; + virJSONValuePtr cmd; + virJSONValuePtr reply = NULL; + virJSONValuePtr data; + + if (!(cmd = qemuMonitorJSONMakeCommand("qom-get", + "s:path", "/machine", + "s:property", "rtc-time", + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + + data = virJSONValueObjectGet(reply, "return"); + + if (virJSONValueObjectGetNumberInt(data, "tm_year", &tm->tm_year) < 0 || + virJSONValueObjectGetNumberInt(data, "tm_mon", &tm->tm_mon) < 0 || + virJSONValueObjectGetNumberInt(data, "tm_mday", &tm->tm_mday) < 0 || + virJSONValueObjectGetNumberInt(data, "tm_hour", &tm->tm_hour) < 0 || + virJSONValueObjectGetNumberInt(data, "tm_min", &tm->tm_min) < 0 || + virJSONValueObjectGetNumberInt(data, "tm_sec", &tm->tm_sec) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("qemu returned malformed time")); + goto cleanup; + } + + ret = 0; + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 1587a036f6..b7aff73eb3 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -483,4 +483,7 @@ int qemuMonitorJSONMigrateIncoming(qemuMonitorPtr mon, int qemuMonitorJSONMigrateStartPostCopy(qemuMonitorPtr mon) ATTRIBUTE_NONNULL(1); +int qemuMonitorJSONGetRTCTime(qemuMonitorPtr mon, + struct tm *tm) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); #endif /* QEMU_MONITOR_JSON_H */ -- GitLab