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 | 58 ++++++++++++++++++++++++++++++--
2 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 5801ca0f86..ad5755cfed 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -5107,6 +5107,22 @@ typedef enum {
VIR_DOMAIN_DIRTYRATE_QUERY = 1 << 1, /* query domain's dirtyrate */
} virDomainDirtyRateFlags;
+/**
+ * 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 a0616eae2c..ca7d8d23c0 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -9659,12 +9659,61 @@ qemuMonitorJSONCalculateDirtyRate(qemuMonitorPtr mon,
}
+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;
+}
+
+
int
qemuMonitorJSONQueryDirtyRate(qemuMonitorPtr mon,
virDomainDirtyRateInfoPtr info)
{
g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL;
+ virJSONValuePtr data = NULL;
if (!(cmd = qemuMonitorJSONMakeCommand("query-dirty-rate", NULL)))
return -1;
@@ -9675,6 +9724,11 @@ qemuMonitorJSONQueryDirtyRate(qemuMonitorPtr mon,
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
return -1;
- /* TODO: extract dirtyrate data from reply and store in virDomainDirtyRateInfoPtr */
- return 0;
+ if (!(data = virJSONValueObjectGetObject(reply, "return"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-dirty-rate reply was missing 'return'
data"));
+ return -1;
+ }
+
+ return qemuMonitorJSONExtractDirtyRateInfo(data, info);
}
--
2.23.0