From: Hyman Huang(黄勇) <huangy81(a)chinatelecom.cn>
Implement qemuDomainCancelVcpuDirtyLimit to cancel
vcpu dirty page rate limit.
Signed-off-by: Hyman Huang(黄勇) <huangy81(a)chinatelecom.cn>
---
src/qemu/qemu_driver.c | 47 ++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor.c | 11 +++++++++++
src/qemu/qemu_monitor.h | 4 ++++
src/qemu/qemu_monitor_json.c | 35 +++++++++++++++++++++++++++++++++
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 fbd6a32..06ad9a9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20800,6 +20800,52 @@ qemuDomainSetVcpuDirtyLimit(virDomainPtr domain,
return ret;
}
+static int
+qemuDomainCancelVcpuDirtyLimit(virDomainPtr domain,
+ int vcpu,
+ unsigned int flags)
+{
+ virDomainObj *vm = NULL;
+ qemuDomainObjPrivate *priv;
+ int ret = -1;
+
+ if (!(vm = qemuDomainObjFromDomain(domain)))
+ return -1;
+
+ priv = vm->privateData;
+ if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VCPU_DIRTY_LIMIT)) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+ _("QEMU does not support setting vcpu dirty page rate
limit"));
+ goto cleanup;
+ }
+
+ if (qemuDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
+ goto cleanup;
+
+ if (virDomainCancelVcpuDirtyLimitEnsureACL(domain->conn, vm->def) < 0)
+ goto endjob;
+
+ if (virDomainObjCheckActive(vm) < 0)
+ goto endjob;
+
+ qemuDomainObjEnterMonitor(vm);
+ if (flags & VIR_DOMAIN_DIRTYLIMIT_VCPU) {
+ VIR_DEBUG("Cancel vcpu[%d] dirty page rate limit", vcpu);
+ ret = qemuMonitorCancelVcpuDirtyLimit(priv->mon, vcpu);
+ } else {
+ VIR_DEBUG("Cancel all vcpus dirty page rate limit of vm");
+ ret = qemuMonitorCancelVcpuDirtyLimit(priv->mon, -1);
+ }
+ qemuDomainObjExitMonitor(vm);
+
+ endjob:
+ qemuDomainObjEndJob(vm);
+
+ cleanup:
+ virDomainObjEndAPI(&vm);
+ return ret;
+}
+
static virHypervisorDriver qemuHypervisorDriver = {
.name = QEMU_DRIVER_NAME,
.connectURIProbe = qemuConnectURIProbe,
@@ -21049,6 +21095,7 @@ static virHypervisorDriver qemuHypervisorDriver = {
.domainStartDirtyRateCalc = qemuDomainStartDirtyRateCalc, /* 7.2.0 */
.domainSetLaunchSecurityState = qemuDomainSetLaunchSecurityState, /* 8.0.0 */
.domainSetVcpuDirtyLimit = qemuDomainSetVcpuDirtyLimit, /* 8.7.0 */
+ .domainCancelVcpuDirtyLimit = qemuDomainCancelVcpuDirtyLimit, /* 8.7.0 */
};
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 7480856..67d0171 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4321,3 +4321,14 @@ qemuMonitorQueryVcpuDirtyLimit(qemuMonitor *mon,
return qemuMonitorJSONQueryVcpuDirtyLimit(mon, info);
}
+
+int
+qemuMonitorCancelVcpuDirtyLimit(qemuMonitor *mon,
+ int vcpu)
+{
+ VIR_DEBUG("cancel vcpu %d dirty page rate limit", vcpu);
+
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONCancelVcpuDirtyLimit(mon, vcpu);
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index cf76f43..bad55fc 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1503,3 +1503,7 @@ struct _qemuMonitorVcpuDirtyLimitInfo {
int
qemuMonitorQueryVcpuDirtyLimit(qemuMonitor *mon,
qemuMonitorVcpuDirtyLimitInfo *info);
+
+int
+qemuMonitorCancelVcpuDirtyLimit(qemuMonitor *mon,
+ int vcpu);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 4642a2d..ef86384 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8676,3 +8676,38 @@ qemuMonitorJSONQueryVcpuDirtyLimit(qemuMonitor *mon,
return qemuMonitorJSONExtractVcpuDirtyLimitInfo(data, info);
}
+
+int
+qemuMonitorJSONCancelVcpuDirtyLimit(qemuMonitor *mon,
+ int vcpu)
+{
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+
+ if (vcpu >= 0) {
+ /* cancel vcpu dirty page rate limit */
+ if (!(cmd = qemuMonitorJSONMakeCommand("cancel-vcpu-dirty-limit",
+ "i:cpu-index", vcpu,
+ NULL))) {
+ return -1;
+ }
+ } else if (vcpu == -1) {
+ /* cancel vm dirty page rate limit */
+ if (!(cmd = qemuMonitorJSONMakeCommand("cancel-vcpu-dirty-limit",
+ NULL))) {
+ return -1;
+ }
+ } else {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unexpected vcpu index %d"), vcpu);
+ 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 2852061..12f330e 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -821,3 +821,7 @@ qemuMonitorJSONSetVcpuDirtyLimit(qemuMonitor *mon,
int
qemuMonitorJSONQueryVcpuDirtyLimit(qemuMonitor *mon,
qemuMonitorVcpuDirtyLimitInfo *info);
+
+int
+qemuMonitorJSONCancelVcpuDirtyLimit(qemuMonitor *mon,
+ int vcpu);
--
1.8.3.1