From: Hyman Huang(黄勇) <huangy81@xxxxxxxxxxxxxxx> Implement qemuDomainSetVcpuDirtyLimit which set dirty page rate limit. Signed-off-by: Hyman Huang(黄勇) <huangy81@xxxxxxxxxxxxxxx> --- src/qemu/qemu_driver.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor.c | 12 +++++++++++ src/qemu/qemu_monitor.h | 5 +++++ src/qemu/qemu_monitor_json.c | 38 +++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 5 +++++ 5 files changed, 107 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 333225d..8c95f24 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20701,6 +20701,52 @@ qemuDomainStartDirtyRateCalc(virDomainPtr dom, return ret; } +static int +qemuDomainSetVcpuDirtyLimit(virDomainPtr domain, + int vcpu, + unsigned long long rate, + 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 dirty page rate limit")); + goto cleanup; + } + + if (qemuDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) + goto cleanup; + + if (virDomainSetVcpuDirtyLimitEnsureACL(domain->conn, vm->def) < 0) + goto endjob; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + qemuDomainObjEnterMonitor(vm); + if (flags & VIR_DOMAIN_DIRTYLIMIT_VCPU) { + VIR_DEBUG("Set vcpu[%d] dirty page rate limit %lld", vcpu, rate); + ret = qemuMonitorSetVcpuDirtyLimit(priv->mon, vcpu, rate); + } else { + VIR_DEBUG("Set all vcpus dirty page rate limit %lld of vm", rate); + ret = qemuMonitorSetVcpuDirtyLimit(priv->mon, -1, rate); + } + qemuDomainObjExitMonitor(vm); + + endjob: + qemuDomainObjEndJob(vm); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} static virHypervisorDriver qemuHypervisorDriver = { .name = QEMU_DRIVER_NAME, @@ -20950,6 +20996,7 @@ static virHypervisorDriver qemuHypervisorDriver = { .domainGetMessages = qemuDomainGetMessages, /* 7.1.0 */ .domainStartDirtyRateCalc = qemuDomainStartDirtyRateCalc, /* 7.2.0 */ .domainSetLaunchSecurityState = qemuDomainSetLaunchSecurityState, /* 8.0.0 */ + .domainSetVcpuDirtyLimit = qemuDomainSetVcpuDirtyLimit, /* 8.7.0 */ }; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 4739810..dee2904 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4297,3 +4297,15 @@ qemuMonitorGetMigrationBlockers(qemuMonitor *mon, return qemuMonitorJSONGetMigrationBlockers(mon, blockers); } + +int +qemuMonitorSetVcpuDirtyLimit(qemuMonitor *mon, + int vcpu, + unsigned long long rate) +{ + VIR_DEBUG("set vcpu %d dirty page rate limit %lld", vcpu, rate); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONSetVcpuDirtyLimit(mon, vcpu, rate); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 78e2ebf..83bcf14 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1481,3 +1481,8 @@ qemuMonitorMigrateRecover(qemuMonitor *mon, int qemuMonitorGetMigrationBlockers(qemuMonitor *mon, char ***blockers); + +int +qemuMonitorSetVcpuDirtyLimit(qemuMonitor *mon, + int vcpu, + unsigned long long rate); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index d664e82..fc50604 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -8574,3 +8574,41 @@ qemuMonitorJSONMigrateRecover(qemuMonitor *mon, return qemuMonitorJSONCheckError(cmd, reply); } + +int +qemuMonitorJSONSetVcpuDirtyLimit(qemuMonitor *mon, + int vcpu, + unsigned long long rate) +{ + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; + + if (vcpu >= 0) { + /* set vcpu dirty page rate limit */ + if (!(cmd = qemuMonitorJSONMakeCommand("set-vcpu-dirty-limit", + "i:cpu-index", vcpu, + "U:dirty-rate", rate, + NULL))) { + return -1; + } + } else if (vcpu == -1) { + /* set vm dirty page rate limit */ + if (!(cmd = qemuMonitorJSONMakeCommand("set-vcpu-dirty-limit", + "U:dirty-rate", rate, + 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 5154c19..7b07428 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -812,3 +812,8 @@ qemuMonitorJSONChangeMemoryRequestedSize(qemuMonitor *mon, int qemuMonitorJSONMigrateRecover(qemuMonitor *mon, const char *uri); + +int +qemuMonitorJSONSetVcpuDirtyLimit(qemuMonitor *mon, + int vcpu, + unsigned long long rate); -- 1.8.3.1