From: Hyman Huang(黄勇) <yong.huang(a)smartx.com>
Implement qemuDomainCancelVcpuDirtyLimit to cancel
vcpu dirty page rate upper limit.
Signed-off-by: Hyman Huang(黄勇) <yong.huang(a)smartx.com>
---
src/qemu/qemu_driver.c | 47 ++++++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor.c | 11 +++++++++
src/qemu/qemu_monitor.h | 4 +++
src/qemu/qemu_monitor_json.c | 41 +++++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 4 +++
5 files changed, 107 insertions(+)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f7ff3b7098..c4ffacd88c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20019,6 +20019,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;
+
+ if (virDomainCancelVcpuDirtyLimitEnsureACL(domain->conn, vm->def))
+ goto cleanup;
+
+ 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 (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0)
+ goto cleanup;
+
+ 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:
+ virDomainObjEndJob(vm);
+
+ cleanup:
+ virDomainObjEndAPI(&vm);
+ return ret;
+}
+
static virHypervisorDriver qemuHypervisorDriver = {
.name = QEMU_DRIVER_NAME,
.connectURIProbe = qemuConnectURIProbe,
@@ -20269,6 +20315,7 @@ static virHypervisorDriver qemuHypervisorDriver = {
.domainSetLaunchSecurityState = qemuDomainSetLaunchSecurityState, /* 8.0.0 */
.domainFDAssociate = qemuDomainFDAssociate, /* 9.0.0 */
.domainSetVcpuDirtyLimit = qemuDomainSetVcpuDirtyLimit, /* 9.6.0 */
+ .domainCancelVcpuDirtyLimit = qemuDomainCancelVcpuDirtyLimit, /* 9.6.0 */
};
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index a8a6a6e4e2..13cb4f1e79 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4530,3 +4530,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 1828bb202a..cbfd4fdaaf 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1601,3 +1601,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 f8406c1857..c0a79dfa97 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8998,3 +8998,44 @@ qemuMonitorJSONQueryVcpuDirtyLimit(qemuMonitor *mon,
return qemuMonitorJSONExtractVcpuDirtyLimitInfo(data, info);
}
+
+/**
+ * qemuMonitorJSONCancelVcpuDirtyLimit:
+ * @mon: monitor object
+ * @vcpu: virtual cpu index to be cancelled, -1 means all virtual cpus
+ *
+ * Returns -1 on failure.
+ */
+int
+qemuMonitorJSONCancelVcpuDirtyLimit(qemuMonitor *mon,
+ int vcpu)
+{
+ g_autoptr(virJSONValue) cmd = NULL;
+ g_autoptr(virJSONValue) reply = NULL;
+
+ if (vcpu < -1)
+ return -1;
+
+ 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;
+ }
+ }
+
+ 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 bd8131508b..0549627c81 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -834,3 +834,7 @@ qemuMonitorJSONSetVcpuDirtyLimit(qemuMonitor *mon,
int
qemuMonitorJSONQueryVcpuDirtyLimit(qemuMonitor *mon,
qemuMonitorVcpuDirtyLimitInfo *info);
+
+int
+qemuMonitorJSONCancelVcpuDirtyLimit(qemuMonitor *mon,
+ int vcpu);
--
2.38.5