Implement qemuMonitorJSONExtractDirtyRateInfo to deal with the return from
qmp "query-dirty-rate", and store them in virDomainDirtyRateInfo.
Signed-off-by: Hao Wang <wanghao232(a)huawei.com>
Reviewed-by: Chuan Zheng <zhengchuan(a)huawei.com>
---
include/libvirt/libvirt-domain.h | 16 +++++++++++
src/qemu/qemu_monitor_json.c | 48 ++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 2d3847b..a4b5fcc 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -4999,6 +4999,22 @@ int virDomainBackupBegin(virDomainPtr domain,
char *virDomainBackupGetXMLDesc(virDomainPtr domain,
unsigned int flags);
+/**
+ * virDomainDirtyRateStatus:
+ *
+ * Details on the cause of a dirtyrate calculation status.
+ */
+
+typedef enum {
+ VIR_DOMAIN_DIRTYRATE_UNSTARTED = 0, /* the dirtyrate calculation has not been started
*/
+ VIR_DOMAIN_DIRTYRATE_MEASURING = 1, /* the dirtyrate calculation is measuring */
+ VIR_DOMAIN_DIRTYRATE_MEASURED = 2, /* the dirtyrate calculation is completed */
+
+# ifdef VIR_ENUM_SENTINELS
+ VIR_DOMAIN_DIRTYRATE_LAST
+# endif
+} virDomainDirtyRateStatus;
+
/**
* virDomainDirtyRateInfo:
*
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 83f169e..d6beb44 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -9415,3 +9415,51 @@ qemuMonitorJSONGetCPUMigratable(qemuMonitorPtr mon,
return virJSONValueGetBoolean(virJSONValueObjectGet(reply, "return"),
migratable);
}
+
+
+VIR_ENUM_DECL(qemuDomainDirtyRateStatus);
+VIR_ENUM_IMPL(qemuDomainDirtyRateStatus,
+ VIR_DOMAIN_DIRTYRATE_LAST,
+ "unstarted",
+ "measuring",
+ "measured");
+
+static int
+qemuMonitorJSONExtractDirtyRateInfo(virJSONValuePtr data,
+ virDomainDirtyRateInfoPtr info)
+{
+ const char *status;
+ int statusID;
+
+ if (!(status = virJSONValueObjectGetString(data, "status"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-dirty-rate reply was missing 'status'
data"));
+ return -1;
+ }
+
+ if ((statusID = qemuDomainDirtyRateStatusTypeFromString(status)) < 0) {
+ return -1;
+ }
+ info->status = statusID;
+
+ if ((info->status == VIR_DOMAIN_DIRTYRATE_MEASURED) &&
+ (virJSONValueObjectGetNumberLong(data, "dirty-rate",
&(info->dirtyRate)) < 0)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-dirty-rate reply was missing 'dirty-rate'
data"));
+ return -1;
+ }
+
+ if (virJSONValueObjectGetNumberLong(data, "start-time",
&(info->startTime)) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-dirty-rate reply was missing 'start-time'
data"));
+ return -1;
+ }
+
+ if (virJSONValueObjectGetNumberLong(data, "calc-time",
&(info->calcTime)) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-dirty-rate reply was missing 'calc-time'
data"));
+ return -1;
+ }
+
+ return 0;
+}
--
2.23.0