render / rpms / libvirt

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