render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
735c6b
From 28bd414db666463dca0a26bbb969fd6bc784ec8e Mon Sep 17 00:00:00 2001
735c6b
Message-Id: <28bd414db666463dca0a26bbb969fd6bc784ec8e@dist-git>
735c6b
From: Pavel Hrdina <phrdina@redhat.com>
735c6b
Date: Tue, 17 Jan 2023 10:02:07 +0100
735c6b
Subject: [PATCH] vircgroupv2: fix cpu.weight limits check
735c6b
735c6b
The cgroup v2 cpu.weight limits are different than cgroup v1 cpu.shares
735c6b
limits.
735c6b
735c6b
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
735c6b
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
735c6b
(cherry picked from commit cf3414a85b8383d71d6ae2a53daf63c331cc2230)
735c6b
735c6b
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2037998
735c6b
735c6b
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
735c6b
---
735c6b
 src/util/vircgroup.h   | 2 ++
735c6b
 src/util/vircgroupv2.c | 8 ++++----
735c6b
 2 files changed, 6 insertions(+), 4 deletions(-)
735c6b
735c6b
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
735c6b
index 690f09465c..adf3850b22 100644
735c6b
--- a/src/util/vircgroup.h
735c6b
+++ b/src/util/vircgroup.h
735c6b
@@ -235,6 +235,8 @@ int virCgroupGetCpuShares(virCgroup *group, unsigned long long *shares);
735c6b
 /* Based on kernel code ((1ULL << MAX_BW_BITS) - 1) where MAX_BW_BITS is
735c6b
  * (64 - BW_SHIFT) and BW_SHIFT is 20 */
735c6b
 #define VIR_CGROUP_CPU_QUOTA_MAX 17592186044415LL
735c6b
+#define VIR_CGROUPV2_WEIGHT_MIN 1LL
735c6b
+#define VIR_CGROUPV2_WEIGHT_MAX 10000LL
735c6b
 
735c6b
 int virCgroupSetCpuCfsPeriod(virCgroup *group, unsigned long long cfs_period);
735c6b
 int virCgroupGetCpuCfsPeriod(virCgroup *group, unsigned long long *cfs_period);
735c6b
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
735c6b
index b1f562aa52..219b9c7f21 100644
735c6b
--- a/src/util/vircgroupv2.c
735c6b
+++ b/src/util/vircgroupv2.c
735c6b
@@ -1499,13 +1499,13 @@ static int
735c6b
 virCgroupV2SetCpuShares(virCgroup *group,
735c6b
                         unsigned long long shares)
735c6b
 {
735c6b
-    if (shares < VIR_CGROUP_CPU_SHARES_MIN ||
735c6b
-        shares > VIR_CGROUP_CPU_SHARES_MAX) {
735c6b
+    if (shares < VIR_CGROUPV2_WEIGHT_MIN ||
735c6b
+        shares > VIR_CGROUPV2_WEIGHT_MAX) {
735c6b
         virReportError(VIR_ERR_INVALID_ARG,
735c6b
                        _("shares '%llu' must be in range [%llu, %llu]"),
735c6b
                        shares,
735c6b
-                       VIR_CGROUP_CPU_SHARES_MIN,
735c6b
-                       VIR_CGROUP_CPU_SHARES_MAX);
735c6b
+                       VIR_CGROUPV2_WEIGHT_MIN,
735c6b
+                       VIR_CGROUPV2_WEIGHT_MAX);
735c6b
         return -1;
735c6b
     }
735c6b
 
735c6b
-- 
735c6b
2.39.1
735c6b