Implement qemuDomainQueryDirtyRate which query domain's memory
dirty rate calling qmp "query-dirty-rate".
Signed-off-by: Hao Wang <wanghao232(a)huawei.com>
Signed-off-by: Zhou Yimin <zhouyimin(a)huawei.com>
Reviewed-by: Chuan Zheng <zhengchuan(a)huawei.com>
---
src/qemu/qemu_migration.c | 23 +++++++++++
src/qemu/qemu_migration.h | 5 +++
src/qemu/qemu_monitor.c | 12 ++++++
src/qemu/qemu_monitor.h | 4 ++
src/qemu/qemu_monitor_json.c | 77 ++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 4 ++
6 files changed, 125 insertions(+)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 226fe5395e..373896e408 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -5916,3 +5916,26 @@ qemuDomainCalculateDirtyRate(virQEMUDriverPtr driver,
return ret;
}
+
+
+int
+qemuDomainQueryDirtyRate(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainDirtyRateInfoPtr info)
+{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ int ret;
+
+ if (!virDomainObjIsActive(vm)) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ "%s", _("domain is not running"));
+ return -1;
+ }
+
+ qemuDomainObjEnterMonitor(driver, vm);
+ ret = qemuMonitorQueryDirtyRate(priv->mon, info);
+ if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ ret = -1;
+
+ return ret;
+}
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 6b1f4a8eea..a894c3c527 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -263,3 +263,8 @@ int
qemuDomainCalculateDirtyRate(virQEMUDriverPtr driver,
virDomainObjPtr vm,
int sec);
+
+int
+qemuDomainQueryDirtyRate(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainDirtyRateInfoPtr info);
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 51bc9182f3..b8c428fca8 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4725,3 +4725,15 @@ qemuMonitorCalculateDirtyRate(qemuMonitorPtr mon,
return qemuMonitorJSONCalculateDirtyRate(mon, sec);
}
+
+
+int
+qemuMonitorQueryDirtyRate(qemuMonitorPtr mon,
+ virDomainDirtyRateInfoPtr info)
+{
+ VIR_DEBUG("info=%p", info);
+
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONQueryDirtyRate(mon, info);
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index a11a5dc21c..9814fe0218 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1520,3 +1520,7 @@ qemuMonitorTransactionBackup(virJSONValuePtr actions,
int
qemuMonitorCalculateDirtyRate(qemuMonitorPtr mon,
int sec);
+
+int
+qemuMonitorQueryDirtyRate(qemuMonitorPtr mon,
+ virDomainDirtyRateInfoPtr info);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index bb85513aa6..ba301029b0 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -9474,3 +9474,80 @@ qemuMonitorJSONCalculateDirtyRate(qemuMonitorPtr mon,
return 0;
}
+
+
+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) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unknown dirty rate status: %s"), status);
+ 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 (virJSONValueObjectGetNumberInt(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;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ return -1;
+
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ return -1;
+
+ 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);
+}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index cc59d2c078..27ced5cd5e 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -709,3 +709,7 @@ qemuMonitorJSONGetCPUMigratable(qemuMonitorPtr mon,
int
qemuMonitorJSONCalculateDirtyRate(qemuMonitorPtr mon,
int sec);
+
+int
+qemuMonitorJSONQueryDirtyRate(qemuMonitorPtr mon,
+ virDomainDirtyRateInfoPtr info);
--
2.23.0