render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
397dc2
From 8d08db00d403ddd17cb51d972842c6d13a122d57 Mon Sep 17 00:00:00 2001
397dc2
Message-Id: <8d08db00d403ddd17cb51d972842c6d13a122d57@dist-git>
397dc2
From: Pavel Hrdina <phrdina@redhat.com>
397dc2
Date: Thu, 4 Mar 2021 12:57:58 +0100
397dc2
Subject: [PATCH] cgroup: use virCgroupSetCpuShares instead of
397dc2
 virCgroupSetupCpuShares
397dc2
MIME-Version: 1.0
397dc2
Content-Type: text/plain; charset=UTF-8
397dc2
Content-Transfer-Encoding: 8bit
397dc2
397dc2
Now that we enforce the cpu.shares range kernel will no longer silently
397dc2
change the value that libvirt configures so there is no need to read
397dc2
the value back to get the actual configuration.
397dc2
397dc2
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
397dc2
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
397dc2
(cherry picked from commit e95489d813cb7cc68b02905ce3ec059bc395b465)
397dc2
397dc2
Conflicts:
397dc2
    src/lxc/lxc_cgroup.c
397dc2
    src/lxc/lxc_driver.c
397dc2
    src/qemu/qemu_cgroup.c
397dc2
    src/qemu/qemu_driver.c
397dc2
        - downstream doesn't have virCgroupSetupCpuShares() function
397dc2
          so we just remove usage of virCgroupGetCpuShares()
397dc2
397dc2
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1798463
397dc2
397dc2
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
397dc2
Message-Id: <a7f8e3c0ce4bc22eccbaa25a434d5e72e74d8a65.1614858616.git.phrdina@redhat.com>
397dc2
Reviewed-by: Ján Tomko <jtomko@redhat.com>
397dc2
---
397dc2
 src/lxc/lxc_cgroup.c   |  5 -----
397dc2
 src/lxc/lxc_driver.c   |  6 +-----
397dc2
 src/qemu/qemu_cgroup.c | 20 --------------------
397dc2
 src/qemu/qemu_driver.c |  8 ++------
397dc2
 4 files changed, 3 insertions(+), 36 deletions(-)
397dc2
397dc2
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
397dc2
index 7f3701593a..f785f50754 100644
397dc2
--- a/src/lxc/lxc_cgroup.c
397dc2
+++ b/src/lxc/lxc_cgroup.c
397dc2
@@ -38,13 +38,8 @@ static int virLXCCgroupSetupCpuTune(virDomainDefPtr def,
397dc2
                                     virCgroupPtr cgroup)
397dc2
 {
397dc2
     if (def->cputune.sharesSpecified) {
397dc2
-        unsigned long long val;
397dc2
         if (virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0)
397dc2
             return -1;
397dc2
-
397dc2
-        if (virCgroupGetCpuShares(cgroup, &val) < 0)
397dc2
-            return -1;
397dc2
-        def->cputune.shares = val;
397dc2
     }
397dc2
 
397dc2
     if (def->cputune.quota != 0 &&
397dc2
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
397dc2
index a8c93dd228..853ddac8b9 100644
397dc2
--- a/src/lxc/lxc_driver.c
397dc2
+++ b/src/lxc/lxc_driver.c
397dc2
@@ -1909,14 +1909,10 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
397dc2
 
397dc2
         if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
397dc2
             if (def) {
397dc2
-                unsigned long long val;
397dc2
                 if (virCgroupSetCpuShares(priv->cgroup, params[i].value.ul) < 0)
397dc2
                     goto endjob;
397dc2
 
397dc2
-                if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
397dc2
-                    goto endjob;
397dc2
-
397dc2
-                def->cputune.shares = val;
397dc2
+                def->cputune.shares = params[i].value.ul;
397dc2
                 def->cputune.sharesSpecified = true;
397dc2
             }
397dc2
 
397dc2
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
397dc2
index 3a62b4ac15..95ea5bed74 100644
397dc2
--- a/src/qemu/qemu_cgroup.c
397dc2
+++ b/src/qemu/qemu_cgroup.c
397dc2
@@ -933,10 +933,6 @@ static int
397dc2
 qemuSetupCpuCgroup(virDomainObjPtr vm)
397dc2
 {
397dc2
     qemuDomainObjPrivatePtr priv = vm->privateData;
397dc2
-    virObjectEventPtr event = NULL;
397dc2
-    virTypedParameterPtr eventParams = NULL;
397dc2
-    int eventNparams = 0;
397dc2
-    int eventMaxparams = 0;
397dc2
 
397dc2
     if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
397dc2
        if (vm->def->cputune.sharesSpecified) {
397dc2
@@ -949,24 +945,8 @@ qemuSetupCpuCgroup(virDomainObjPtr vm)
397dc2
     }
397dc2
 
397dc2
     if (vm->def->cputune.sharesSpecified) {
397dc2
-        unsigned long long val;
397dc2
         if (virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares) < 0)
397dc2
             return -1;
397dc2
-
397dc2
-        if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
397dc2
-            return -1;
397dc2
-        if (vm->def->cputune.shares != val) {
397dc2
-            vm->def->cputune.shares = val;
397dc2
-            if (virTypedParamsAddULLong(&eventParams, &eventNparams,
397dc2
-                                        &eventMaxparams,
397dc2
-                                        VIR_DOMAIN_TUNABLE_CPU_CPU_SHARES,
397dc2
-                                        val) < 0)
397dc2
-                return -1;
397dc2
-
397dc2
-            event = virDomainEventTunableNewFromObj(vm, eventParams, eventNparams);
397dc2
-        }
397dc2
-
397dc2
-        virObjectEventStateQueue(priv->driver->domainEventState, event);
397dc2
     }
397dc2
 
397dc2
     return 0;
397dc2
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
397dc2
index a1103a96dd..3914d3ff68 100644
397dc2
--- a/src/qemu/qemu_driver.c
397dc2
+++ b/src/qemu/qemu_driver.c
397dc2
@@ -10625,20 +10625,16 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
397dc2
 
397dc2
         if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
397dc2
             if (def) {
397dc2
-                unsigned long long val;
397dc2
                 if (virCgroupSetCpuShares(priv->cgroup, value_ul) < 0)
397dc2
                     goto endjob;
397dc2
 
397dc2
-                if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
397dc2
-                    goto endjob;
397dc2
-
397dc2
-                def->cputune.shares = val;
397dc2
+                def->cputune.shares = value_ul;
397dc2
                 def->cputune.sharesSpecified = true;
397dc2
 
397dc2
                 if (virTypedParamsAddULLong(&eventParams, &eventNparams,
397dc2
                                             &eventMaxNparams,
397dc2
                                             VIR_DOMAIN_TUNABLE_CPU_CPU_SHARES,
397dc2
-                                            val) < 0)
397dc2
+                                            value_ul) < 0)
397dc2
                     goto endjob;
397dc2
             }
397dc2
 
397dc2
-- 
397dc2
2.30.0
397dc2