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 235a187..3783582 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20875,6 +20875,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,
@@ -21124,6 +21170,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 ab4ba2f..7274624 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4442,3 +4442,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 bd5dd2b..c8c3547 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1551,3 +1551,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 1d4c6f5..261a467 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8768,3 +8768,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 388d5b0..7b65f14 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -827,3 +827,7 @@ qemuMonitorJSONSetVcpuDirtyLimit(qemuMonitor *mon,
int
qemuMonitorJSONQueryVcpuDirtyLimit(qemuMonitor *mon,
qemuMonitorVcpuDirtyLimitInfo *info);
+
+int
+qemuMonitorJSONCancelVcpuDirtyLimit(qemuMonitor *mon,
+ int vcpu);
--
1.8.3.1