[libvirt PATCH 1/2] domain_validate: use defines for cpu period and quota limits

Pavel Hrdina phrdina at redhat.com
Fri Feb 19 18:55:28 UTC 2021


Commints <bc760f4d7c4f964fadcb2a73e126b0053e7a9b06> and
<98a09ca48ed4fc011abf2aa290e02ce1b8f1bb5f> fixed the code to use
defines instead of magic numbers but missed this place.

Following commit <ed1ba69f5a8132f8c1e73d2a1f142d70de0b564a> changed
the cpu quota limit to reflect what kernel actually allows so using
the defines fixes XML validations as well.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/conf/domain_validate.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index b47ecba86b..b4e09e21fe 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -23,6 +23,7 @@
 #include "domain_validate.h"
 #include "domain_conf.h"
 #include "snapshot_conf.h"
+#include "vircgroup.h"
 #include "virconftypes.h"
 #include "virlog.h"
 #include "virutil.h"
@@ -1200,10 +1201,13 @@ virDomainDefOSValidate(const virDomainDef *def,
 #define CPUTUNE_VALIDATE_PERIOD(name) \
     do { \
         if (def->cputune.name > 0 && \
-            (def->cputune.name < 1000 || def->cputune.name > 1000000)) { \
+            (def->cputune.name < VIR_CGROUP_CPU_PERIOD_MIN || \
+             def->cputune.name > VIR_CGROUP_CPU_PERIOD_MAX)) { \
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, \
-                           _("Value of cputune '%s' must be in range " \
-                           "[1000, 1000000]"), #name); \
+                           _("Value of cputune '%s' must be in range [%llu, %llu]"), \
+                           #name, \
+                           VIR_CGROUP_CPU_PERIOD_MIN, \
+                           VIR_CGROUP_CPU_PERIOD_MAX); \
             return -1; \
         } \
     } while (0)
@@ -1211,11 +1215,13 @@ virDomainDefOSValidate(const virDomainDef *def,
 #define CPUTUNE_VALIDATE_QUOTA(name) \
     do { \
         if (def->cputune.name > 0 && \
-            (def->cputune.name < 1000 || \
-            def->cputune.name > 18446744073709551LL)) { \
+            (def->cputune.name < VIR_CGROUP_CPU_QUOTA_MIN || \
+             def->cputune.name > VIR_CGROUP_CPU_QUOTA_MAX)) { \
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, \
-                           _("Value of cputune '%s' must be in range " \
-                           "[1000, 18446744073709551]"), #name); \
+                           _("Value of cputune '%s' must be in range [%llu, %llu]"), \
+                           #name, \
+                           VIR_CGROUP_CPU_QUOTA_MIN, \
+                           VIR_CGROUP_CPU_QUOTA_MAX); \
             return -1; \
         } \
     } while (0)
-- 
2.29.2




More information about the libvir-list mailing list