]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroupv2: fix cpu.weight limits check
authorPavel Hrdina <phrdina@redhat.com>
Tue, 17 Jan 2023 09:02:07 +0000 (10:02 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 17 Jan 2023 09:57:50 +0000 (10:57 +0100)
The cgroup v2 cpu.weight limits are different than cgroup v1 cpu.shares
limits.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/util/vircgroup.h
src/util/vircgroupv2.c

index 690f09465c80726bf8b2768c603e0ae1a9daeb5b..adf3850b228367d5057d3aa026ca788e853af957 100644 (file)
@@ -235,6 +235,8 @@ int virCgroupGetCpuShares(virCgroup *group, unsigned long long *shares);
 /* Based on kernel code ((1ULL << MAX_BW_BITS) - 1) where MAX_BW_BITS is
  * (64 - BW_SHIFT) and BW_SHIFT is 20 */
 #define VIR_CGROUP_CPU_QUOTA_MAX 17592186044415LL
+#define VIR_CGROUPV2_WEIGHT_MIN 1LL
+#define VIR_CGROUPV2_WEIGHT_MAX 10000LL
 
 int virCgroupSetCpuCfsPeriod(virCgroup *group, unsigned long long cfs_period);
 int virCgroupGetCpuCfsPeriod(virCgroup *group, unsigned long long *cfs_period);
index b1f562aa528fabaa37052ef525e05bdbca90f4e4..219b9c7f219b42e5d24b3d590a4fd1bb42b8896c 100644 (file)
@@ -1499,13 +1499,13 @@ static int
 virCgroupV2SetCpuShares(virCgroup *group,
                         unsigned long long shares)
 {
-    if (shares < VIR_CGROUP_CPU_SHARES_MIN ||
-        shares > VIR_CGROUP_CPU_SHARES_MAX) {
+    if (shares < VIR_CGROUPV2_WEIGHT_MIN ||
+        shares > VIR_CGROUPV2_WEIGHT_MAX) {
         virReportError(VIR_ERR_INVALID_ARG,
                        _("shares '%llu' must be in range [%llu, %llu]"),
                        shares,
-                       VIR_CGROUP_CPU_SHARES_MIN,
-                       VIR_CGROUP_CPU_SHARES_MAX);
+                       VIR_CGROUPV2_WEIGHT_MIN,
+                       VIR_CGROUPV2_WEIGHT_MAX);
         return -1;
     }