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