7548c0
From b96501e90f7b3fbea1427ab6adeade7d8e707d07 Mon Sep 17 00:00:00 2001
7548c0
Message-Id: <b96501e90f7b3fbea1427ab6adeade7d8e707d07@dist-git>
7548c0
From: Pavel Hrdina <phrdina@redhat.com>
7548c0
Date: Thu, 21 Jan 2021 10:24:05 -0300
7548c0
Subject: [PATCH] vircgroupv2: use defines for cpu period and quota limits
7548c0
7548c0
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
7548c0
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
7548c0
(cherry picked from commit 98a09ca48ed4fc011abf2aa290e02ce1b8f1bb5f)
7548c0
7548c0
https://bugzilla.redhat.com/1915733
7548c0
7548c0
Signed-off-by: Daniel Henrique Barboza <dbarboza@redhat.com>
7548c0
Message-Id: <20210121132406.337681-4-dbarboza@redhat.com>
7548c0
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
7548c0
---
7548c0
 src/util/vircgroupv2.c | 25 +++++++++++++------------
7548c0
 1 file changed, 13 insertions(+), 12 deletions(-)
7548c0
7548c0
diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
7548c0
index 1d8c599f6a..92ae3ec839 100644
7548c0
--- a/src/util/vircgroupv2.c
7548c0
+++ b/src/util/vircgroupv2.c
7548c0
@@ -1476,12 +1476,12 @@ virCgroupV2SetCpuCfsPeriod(virCgroupPtr group,
7548c0
     g_autofree char *str = NULL;
7548c0
     char *tmp;
7548c0
 
7548c0
-    /* The cfs_period should be greater or equal than 1ms, and less or equal
7548c0
-     * than 1s.
7548c0
-     */
7548c0
-    if (cfs_period < 1000 || cfs_period > 1000000) {
7548c0
+    if (cfs_period < VIR_CGROUP_CPU_PERIOD_MIN ||
7548c0
+        cfs_period > VIR_CGROUP_CPU_PERIOD_MAX) {
7548c0
         virReportError(VIR_ERR_INVALID_ARG,
7548c0
-                       _("cfs_period '%llu' must be in range (1000, 1000000)"),
7548c0
+                       _("cfs_period '%llu' must be in range (%llu, %llu)"),
7548c0
+                       VIR_CGROUP_CPU_PERIOD_MIN,
7548c0
+                       VIR_CGROUP_CPU_PERIOD_MAX,
7548c0
                        cfs_period);
7548c0
         return -1;
7548c0
     }
7548c0
@@ -1537,17 +1537,18 @@ static int
7548c0
 virCgroupV2SetCpuCfsQuota(virCgroupPtr group,
7548c0
                           long long cfs_quota)
7548c0
 {
7548c0
-    /* The cfs_quota should be greater or equal than 1ms */
7548c0
     if (cfs_quota >= 0 &&
7548c0
-        (cfs_quota < 1000 ||
7548c0
-         cfs_quota > ULLONG_MAX / 1000)) {
7548c0
+        (cfs_quota < VIR_CGROUP_CPU_QUOTA_MIN ||
7548c0
+         cfs_quota > VIR_CGROUP_CPU_QUOTA_MAX)) {
7548c0
         virReportError(VIR_ERR_INVALID_ARG,
7548c0
-                       _("cfs_quota '%lld' must be in range (1000, %llu)"),
7548c0
-                       cfs_quota, ULLONG_MAX / 1000);
7548c0
+                       _("cfs_quota '%lld' must be in range (%llu, %llu)"),
7548c0
+                       cfs_quota,
7548c0
+                       VIR_CGROUP_CPU_QUOTA_MIN,
7548c0
+                       VIR_CGROUP_CPU_QUOTA_MAX);
7548c0
         return -1;
7548c0
     }
7548c0
 
7548c0
-    if (cfs_quota == ULLONG_MAX / 1000) {
7548c0
+    if (cfs_quota == VIR_CGROUP_CPU_QUOTA_MAX) {
7548c0
         return virCgroupSetValueStr(group,
7548c0
                                     VIR_CGROUP_CONTROLLER_CPU,
7548c0
                                     "cpu.max", "max");
7548c0
@@ -1572,7 +1573,7 @@ virCgroupV2GetCpuCfsQuota(virCgroupPtr group,
7548c0
     }
7548c0
 
7548c0
     if (STREQLEN(str, "max", 3)) {
7548c0
-        *cfs_quota = ULLONG_MAX / 1000;
7548c0
+        *cfs_quota = VIR_CGROUP_CPU_QUOTA_MAX;
7548c0
         return 0;
7548c0
     }
7548c0
 
7548c0
-- 
7548c0
2.30.0
7548c0