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