Implement qemuDomainQueryDirtyRate which query domain's memory dirty rate
using 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 | 32 ++++++++++++++++++++++++++++++++
src/qemu/qemu_migration.h | 5 +++++
src/qemu/qemu_monitor.c | 12 ++++++++++++
src/qemu/qemu_monitor.h | 4 ++++
src/qemu/qemu_monitor_json.c | 27 +++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 4 ++++
6 files changed, 84 insertions(+)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 25b06ca..b2100d7 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -5644,3 +5644,35 @@ qemuMigrationSrcFetchMirrorStats(virQEMUDriverPtr driver,
virHashFree(blockinfo);
return 0;
}
+
+
+int
+qemuDomainQueryDirtyRate(virDomainPtr dom,
+ virDomainObjPtr vm,
+ virDomainDirtyRateInfoPtr info)
+{
+ virQEMUDriverPtr driver = dom->conn->privateData;
+ qemuDomainObjPrivatePtr priv;
+ int ret = -1;
+
+ if (!virDomainObjIsActive(vm)) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ "%s", _("domain is not running"));
+ return ret;
+ }
+
+ priv = vm->privateData;
+
+ if (qemuDomainObjEnterMonitorAsync(driver, vm, QEMU_ASYNC_JOB_DIRTYRATE) < 0)
+ return ret;
+
+ ret = qemuMonitorQueryDirtyRate(priv->mon, info);
+ if (ret < 0) {
+ virReportError(VIR_ERR_OPERATION_FAILED,
+ "%s", _("get vm's dirty rate failed."));
+ }
+ if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ ret = -1;
+
+ return ret;
+}
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index b6f88d3..a80497d 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -255,3 +255,8 @@ qemuMigrationSrcFetchMirrorStats(virQEMUDriverPtr driver,
virDomainObjPtr vm,
qemuDomainAsyncJob asyncJob,
qemuDomainJobInfoPtr jobInfo);
+
+int
+qemuDomainQueryDirtyRate(virDomainPtr dom,
+ virDomainObjPtr vm,
+ virDomainDirtyRateInfoPtr info);
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 637361d..acbe4a6 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4635,3 +4635,15 @@ qemuMonitorTransactionBackup(virJSONValuePtr actions,
return qemuMonitorJSONTransactionBackup(actions, device, jobname, target,
bitmap, syncmode);
}
+
+
+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 1c1b0c9..cfb425a 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1435,3 +1435,7 @@ qemuMonitorTransactionBackup(virJSONValuePtr actions,
const char *target,
const char *bitmap,
qemuMonitorTransactionBackupSyncMode syncmode);
+
+int
+qemuMonitorQueryDirtyRate(qemuMonitorPtr mon,
+ virDomainDirtyRateInfoPtr info);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index d6beb44..6b5753d 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -9463,3 +9463,30 @@ qemuMonitorJSONExtractDirtyRateInfo(virJSONValuePtr data,
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 84fea25..5800e83 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -694,3 +694,7 @@ int qemuMonitorJSONSetDBusVMStateIdList(qemuMonitorPtr mon,
int
qemuMonitorJSONGetCPUMigratable(qemuMonitorPtr mon,
bool *migratable);
+
+int
+qemuMonitorJSONQueryDirtyRate(qemuMonitorPtr mon,
+ virDomainDirtyRateInfoPtr info);
--
2.23.0