[PATCH v3 4/4] cputune_event: queue the event for cputune updates

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

 



Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/qemu/qemu_cgroup.c | 18 +++++++++++-
 src/qemu/qemu_driver.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 43d14d4..43b5340 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -34,6 +34,7 @@
 #include "virscsi.h"
 #include "virstring.h"
 #include "virfile.h"
+#include "virtypedparam.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -676,6 +677,10 @@ static int
 qemuSetupCpuCgroup(virDomainObjPtr vm)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
+    virObjectEventPtr event = NULL;
+    virTypedParameterPtr eventParams;
+    int eventNparams = 0;
+    int eventMaxparams = 0;
 
     if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
        if (vm->def->cputune.sharesSpecified) {
@@ -694,7 +699,18 @@ qemuSetupCpuCgroup(virDomainObjPtr vm)
 
         if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
             return -1;
-        vm->def->cputune.shares = val;
+        if (vm->def->cputune.shares != val) {
+            vm->def->cputune.shares = val;
+            if (virTypedParamsAddULLong(&eventParams, &eventNparams,
+                                        &eventMaxparams, "shares",
+                                        val) < 0)
+                return -1;
+
+            event = virDomainEventCputuneNewFromObj(vm, eventParams, eventNparams);
+        }
+
+        if (event)
+            qemuDomainEventQueue(vm->privateData, event);
     }
 
     return 0;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 73edda3..615ccf9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4467,6 +4467,12 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
     virBitmapPtr pcpumap = NULL;
     virQEMUDriverConfigPtr cfg = NULL;
     virCapsPtr caps = NULL;
+    virObjectEventPtr event = NULL;
+    char paramField[VIR_TYPED_PARAM_FIELD_LENGTH] = "";
+    char *str = NULL;
+    virTypedParameterPtr eventParams = NULL;
+    int eventNparams = 0;
+    int eventMaxparams = 0;
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -4574,6 +4580,18 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
 
         if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
             goto cleanup;
+
+        if (snprintf(paramField, VIR_TYPED_PARAM_FIELD_LENGTH,
+                     "vcpu%d", vcpu) < 0) {
+            goto cleanup;
+        }
+
+        str = virBitmapFormat(pcpumap);
+        if (virTypedParamsAddString(&eventParams, &eventNparams,
+                                    &eventMaxparams, paramField, str) < 0)
+            goto cleanup;
+
+        event = virDomainEventCputuneNewFromDom(dom, eventParams, eventNparams);
     }
 
     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
@@ -4609,6 +4627,9 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
         virCgroupFree(&cgroup_vcpu);
     if (vm)
         virObjectUnlock(vm);
+    if (event)
+        qemuDomainEventQueue(driver, event);
+    VIR_FREE(str);
     virBitmapFree(pcpumap);
     virObjectUnref(caps);
     virObjectUnref(cfg);
@@ -4733,6 +4754,12 @@ qemuDomainPinEmulator(virDomainPtr dom,
     virBitmapPtr pcpumap = NULL;
     virQEMUDriverConfigPtr cfg = NULL;
     virCapsPtr caps = NULL;
+    virObjectEventPtr event = NULL;
+    char * str = NULL;
+    virTypedParameterPtr eventParams = NULL;
+    int eventNparams = 0;
+    int eventMaxparams = 0;
+
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -4838,6 +4865,13 @@ qemuDomainPinEmulator(virDomainPtr dom,
 
         if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
             goto cleanup;
+
+        str = virBitmapFormat(pcpumap);
+        if (virTypedParamsAddString(&eventParams, &eventNparams,
+                                    &eventMaxparams, "emulatorpin", str) < 0)
+            goto cleanup;
+
+        event = virDomainEventCputuneNewFromDom(dom, eventParams, eventNparams);
     }
 
     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
@@ -4867,6 +4901,9 @@ qemuDomainPinEmulator(virDomainPtr dom,
  cleanup:
     if (cgroup_emulator)
         virCgroupFree(&cgroup_emulator);
+    if (event)
+        qemuDomainEventQueue(driver, event);
+    VIR_FREE(str);
     virBitmapFree(pcpumap);
     virObjectUnref(caps);
     if (vm)
@@ -9079,6 +9116,10 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
     virQEMUDriverConfigPtr cfg = NULL;
     virCapsPtr caps = NULL;
     qemuDomainObjPrivatePtr priv;
+    virObjectEventPtr event = NULL;
+    virTypedParameterPtr eventParams = NULL;
+    int eventNparams = 0;
+    int eventMaxNparams = 0;
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
@@ -9149,6 +9190,11 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
 
                 vm->def->cputune.shares = val;
                 vm->def->cputune.sharesSpecified = true;
+
+                if (virTypedParamsAddULLong(&eventParams, &eventNparams,
+                                            &eventMaxNparams, "shares",
+                                            val) < 0)
+                    goto cleanup;
             }
 
             if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
@@ -9166,6 +9212,11 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                     goto cleanup;
 
                 vm->def->cputune.period = value_ul;
+
+                if (virTypedParamsAddULLong(&eventParams, &eventNparams,
+                                            &eventMaxNparams, "period",
+                                            value_ul) < 0)
+                    goto cleanup;
             }
 
             if (flags & VIR_DOMAIN_AFFECT_CONFIG)
@@ -9180,6 +9231,11 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                     goto cleanup;
 
                 vm->def->cputune.quota = value_l;
+
+                if (virTypedParamsAddLLong(&eventParams, &eventNparams,
+                                           &eventMaxNparams, "quota",
+                                           value_l) < 0)
+                    goto cleanup;
             }
 
             if (flags & VIR_DOMAIN_AFFECT_CONFIG)
@@ -9195,6 +9251,11 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                     goto cleanup;
 
                 vm->def->cputune.emulator_period = value_ul;
+
+                if (virTypedParamsAddULLong(&eventParams, &eventNparams,
+                                            &eventMaxNparams, "emulator_period",
+                                            value_ul) < 0)
+                    goto cleanup;
             }
 
             if (flags & VIR_DOMAIN_AFFECT_CONFIG)
@@ -9210,6 +9271,11 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                     goto cleanup;
 
                 vm->def->cputune.emulator_quota = value_l;
+
+                if (virTypedParamsAddLLong(&eventParams, &eventNparams,
+                                           &eventMaxNparams, "emulator_quota",
+                                           value_l) < 0)
+                    goto cleanup;
             }
 
             if (flags & VIR_DOMAIN_AFFECT_CONFIG)
@@ -9220,6 +9286,12 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
     if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
         goto cleanup;
 
+    if (eventNparams) {
+        event = virDomainEventCputuneNewFromDom(dom, eventParams, eventNparams);
+        eventNparams = 0;
+        if (event)
+            qemuDomainEventQueue(driver, event);
+    }
 
     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
         rc = virDomainSaveConfig(cfg->configDir, vmdef);
@@ -9236,6 +9308,8 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
     virDomainDefFree(vmdef);
     if (vm)
         virObjectUnlock(vm);
+    if (eventNparams)
+        virTypedParamsFree(eventParams, eventNparams);
     virObjectUnref(caps);
     virObjectUnref(cfg);
     return ret;
-- 
1.8.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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]