[PATCH 1/2] qemu: Introduce qemuMonitorGetRTCTime

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

 



Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_monitor.c      | 11 +++++++++++
 src/qemu/qemu_monitor.h      |  3 +++
 src/qemu/qemu_monitor_json.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  3 +++
 4 files changed, 62 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index fe8e89f..d918662 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3856,3 +3856,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 470c729..5e1232b 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -970,4 +970,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 7bb9976..6f12ee1 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6984,3 +6984,48 @@ 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;
+
+    if (!(data = virJSONValueObjectGet(reply, "return"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("qom-get reply was missing return data"));
+        goto cleanup;
+    }
+
+    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 8b5d422..40f290e 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -494,4 +494,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 */
-- 
2.8.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]