Implement qemuDomainStartDirtyRateCalc which calculates domain's memory
dirty rate calling qmp "calc-dirty-rate".
Signed-off-by: Hao Wang <wanghao232(a)huawei.com>
---
src/qemu/qemu_driver.c | 59 ++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor.c | 12 ++++++++
src/qemu/qemu_monitor.h | 4 +++
src/qemu/qemu_monitor_json.c | 22 ++++++++++++++
src/qemu/qemu_monitor_json.h | 4 +++
5 files changed, 101 insertions(+)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 16c5ccae45..8836d9fd16 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20342,6 +20342,64 @@ qemuDomainGetMessages(virDomainPtr dom,
}
+#define MIN_DIRTYRATE_CALC_PERIOD 1 /* supported min dirtyrate calculating time: 1s */
+#define MAX_DIRTYRATE_CALC_PERIOD 60 /* supported max dirtyrate calculating time: 60s */
+
+static int
+qemuDomainStartDirtyRateCalc(virDomainPtr dom,
+ int seconds,
+ unsigned int flags)
+{
+ virQEMUDriverPtr driver = dom->conn->privateData;
+ virDomainObjPtr vm;
+ qemuDomainObjPrivatePtr priv;
+ int ret = -1;
+
+ virCheckFlags(0, -1);
+
+ if (seconds < MIN_DIRTYRATE_CALC_PERIOD ||
+ seconds > MAX_DIRTYRATE_CALC_PERIOD) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("seconds=%d is invalid, please choose value within [%d,
%d]."),
+ seconds,
+ MIN_DIRTYRATE_CALC_PERIOD,
+ MAX_DIRTYRATE_CALC_PERIOD);
+ return -1;
+ }
+
+ if (!(vm = qemuDomainObjFromDomain(dom)))
+ return -1;
+
+ if (virDomainStartDirtyRateCalcEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0)
+ goto cleanup;
+
+ if (!virDomainObjIsActive(vm)) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ "%s", _("domain is not running"));
+ goto endjob;
+ }
+
+ VIR_DEBUG("Calculate dirty rate in next %d seconds", seconds);
+
+ priv = vm->privateData;
+ qemuDomainObjEnterMonitor(driver, vm);
+ ret = qemuMonitorStartDirtyRateCalc(priv->mon, seconds);
+
+ if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ ret = -1;
+
+ endjob:
+ qemuDomainObjEndJob(driver, vm);
+
+ cleanup:
+ virDomainObjEndAPI(&vm);
+ return ret;
+}
+
+
static virHypervisorDriver qemuHypervisorDriver = {
.name = QEMU_DRIVER_NAME,
.connectURIProbe = qemuConnectURIProbe,
@@ -20584,6 +20642,7 @@ static virHypervisorDriver qemuHypervisorDriver = {
.domainAuthorizedSSHKeysGet = qemuDomainAuthorizedSSHKeysGet, /* 6.10.0 */
.domainAuthorizedSSHKeysSet = qemuDomainAuthorizedSSHKeysSet, /* 6.10.0 */
.domainGetMessages = qemuDomainGetMessages, /* 7.1.0 */
+ .domainStartDirtyRateCalc = qemuDomainStartDirtyRateCalc, /* 7.2.0 */
};
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index b4f2641504..ce927687e3 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4742,3 +4742,15 @@ qemuMonitorTransactionBackup(virJSONValuePtr actions,
return qemuMonitorJSONTransactionBackup(actions, device, jobname, target,
bitmap, syncmode);
}
+
+
+int
+qemuMonitorStartDirtyRateCalc(qemuMonitorPtr mon,
+ int seconds)
+{
+ VIR_DEBUG("seconds=%d", seconds);
+
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONStartDirtyRateCalc(mon, seconds);
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index d25c26343a..94813906b4 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1526,3 +1526,7 @@ qemuMonitorTransactionBackup(virJSONValuePtr actions,
const char *target,
const char *bitmap,
qemuMonitorTransactionBackupSyncMode syncmode);
+
+int
+qemuMonitorStartDirtyRateCalc(qemuMonitorPtr mon,
+ int seconds);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index ad62e24cfc..588fcd3a1c 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -9480,3 +9480,25 @@ qemuMonitorJSONGetCPUMigratable(qemuMonitorPtr mon,
return virJSONValueGetBoolean(virJSONValueObjectGet(reply, "return"),
migratable);
}
+
+
+int
+qemuMonitorJSONStartDirtyRateCalc(qemuMonitorPtr mon,
+ int seconds)
+{
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("calc-dirty-rate",
+ "i:calc-time", seconds,
+ NULL)))
+ return -1;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ return -1;
+
+ if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+ return -1;
+
+ return 0;
+}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 3dd1eb24c7..32782cf681 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -711,3 +711,7 @@ int qemuMonitorJSONSetDBusVMStateIdList(qemuMonitorPtr mon,
int
qemuMonitorJSONGetCPUMigratable(qemuMonitorPtr mon,
bool *migratable);
+
+int
+qemuMonitorJSONStartDirtyRateCalc(qemuMonitorPtr mon,
+ int seconds);
--
2.23.0