[PATCH v1 03/10] qemu_driver: Implement qemuDomainSetVcpuDirtyLimit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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      | 13 ++++++++++++
 src/qemu/qemu_monitor.h      |  5 +++++
 src/qemu/qemu_monitor_json.c | 39 ++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  5 +++++
 5 files changed, 109 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 707f4cc..981027a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20766,6 +20766,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,
@@ -21015,6 +21061,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 c2808c7..49477ff 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4417,3 +4417,16 @@ qemuMonitorExtractQueryStats(virJSONValue *info)
 
     return g_steal_pointer(&hash_table);
 }
+
+
+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 63269e1..fade35e 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1529,3 +1529,8 @@ qemuMonitorQueryStats(qemuMonitor *mon,
 
 GHashTable *
 qemuMonitorExtractQueryStats(virJSONValue *info);
+
+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 70fba50..68a8ca6 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8665,3 +8665,42 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon,
 
     return virJSONValueObjectStealArray(reply, "return");
 }
+
+
+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 a53e642..07944c7 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -818,3 +818,8 @@ qemuMonitorJSONQueryStats(qemuMonitor *mon,
                           qemuMonitorQueryStatsTargetType target,
                           char **vcpus,
                           GPtrArray *providers);
+
+int
+qemuMonitorJSONSetVcpuDirtyLimit(qemuMonitor *mon,
+                                 int vcpu,
+                                 unsigned long long rate);
-- 
1.8.3.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux