[PATCH 1/2] Treat zero cpu shares as a valid value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently, <cputune><shares>0</shares></cputune> is treated
as if it were not specified.

Treat is as a valid value if it was explicitly specified
and write it to the cgroups.
---
 src/conf/domain_conf.c | 12 +++++++-----
 src/conf/domain_conf.h |  1 +
 src/lxc/lxc_cgroup.c   |  2 +-
 src/lxc/lxc_driver.c   |  2 ++
 src/lxc/lxc_native.c   |  8 +++++---
 src/qemu/qemu_cgroup.c |  2 +-
 src/qemu/qemu_driver.c |  6 +++++-
 src/vmx/vmx.c          |  1 +
 8 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1d5cc14..b5f4e67 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11460,11 +11460,13 @@ virDomainDefParseXML(xmlDocPtr xml,
     }
 
     /* Extract cpu tunables. */
-    if (virXPathULong("string(./cputune/shares[1])", ctxt,
-                      &def->cputune.shares) < -1) {
+    if ((n = virXPathULong("string(./cputune/shares[1])", ctxt,
+                           &def->cputune.shares)) < -1) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("can't parse cputune shares value"));
         goto error;
+    } else if (n == 0) {
+        def->cputune.sharesSpecified = true;
     }
 
     if (virXPathULongLong("string(./cputune/period[1])", ctxt,
@@ -17134,14 +17136,14 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         virBufferAsprintf(buf, " current='%u'", def->vcpus);
     virBufferAsprintf(buf, ">%u</vcpu>\n", def->maxvcpus);
 
-    if (def->cputune.shares ||
+    if (def->cputune.sharesSpecified ||
         (def->cputune.nvcpupin && !virDomainIsAllVcpupinInherited(def)) ||
         def->cputune.period || def->cputune.quota ||
         def->cputune.emulatorpin ||
         def->cputune.emulator_period || def->cputune.emulator_quota)
         virBufferAddLit(buf, "  <cputune>\n");
 
-    if (def->cputune.shares)
+    if (def->cputune.sharesSpecified)
         virBufferAsprintf(buf, "    <shares>%lu</shares>\n",
                           def->cputune.shares);
     if (def->cputune.period)
@@ -17195,7 +17197,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         virBufferAsprintf(buf, "cpuset='%s'/>\n", cpumask);
         VIR_FREE(cpumask);
     }
-    if (def->cputune.shares ||
+    if (def->cputune.sharesSpecified ||
         (def->cputune.nvcpupin && !virDomainIsAllVcpupinInherited(def)) ||
         def->cputune.period || def->cputune.quota ||
         def->cputune.emulatorpin ||
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 2467f65..fed1608 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1999,6 +1999,7 @@ struct _virDomainDef {
 
     struct {
         unsigned long shares;
+        bool sharesSpecified;
         unsigned long long period;
         long long quota;
         unsigned long long emulator_period;
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index 39d955c..876c32e 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -36,7 +36,7 @@ static int virLXCCgroupSetupCpuTune(virDomainDefPtr def,
                                     virCgroupPtr cgroup)
 {
     int ret = -1;
-    if (def->cputune.shares != 0 &&
+    if (def->cputune.sharesSpecified &&
         virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0)
         goto cleanup;
 
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 10e0fbb..26333a7 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1891,10 +1891,12 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
                     goto cleanup;
 
                 vm->def->cputune.shares = params[i].value.ul;
+                vm->def->cputune.sharesSpecified = true;
             }
 
             if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
                 vmdef->cputune.shares = params[i].value.ul;
+                vmdef->cputune.sharesSpecified = true;
             }
         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD)) {
             if (flags & VIR_DOMAIN_AFFECT_LIVE) {
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 663e29c..fc19378 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -677,9 +677,11 @@ lxcSetCpuTune(virDomainDefPtr def, virConfPtr properties)
     virConfValuePtr value;
 
     if ((value = virConfGetValue(properties, "lxc.cgroup.cpu.shares")) &&
-            value->str && virStrToLong_ul(value->str, NULL, 10,
-                                          &def->cputune.shares) < 0)
-        goto error;
+            value->str) {
+        if (virStrToLong_ul(value->str, NULL, 10, &def->cputune.shares) < 0)
+            goto error;
+        def->cputune.sharesSpecified = true;
+    }
 
     if ((value = virConfGetValue(properties,
                                  "lxc.cgroup.cpu.cfs_quota_us")) &&
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index a97f184..57c7302 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -653,7 +653,7 @@ qemuSetupCpuCgroup(virDomainObjPtr vm)
        }
     }
 
-    if (vm->def->cputune.shares &&
+    if (vm->def->cputune.sharesSpecified &&
         virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares) < 0)
         return -1;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e04a328..3c9ddb6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9007,10 +9007,14 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
                 if (virCgroupSetCpuShares(priv->cgroup, value_ul) < 0)
                     goto cleanup;
                 vm->def->cputune.shares = value_ul;
+                vm->def->cputune.sharesSpecified = true;
             }
 
-            if (flags & VIR_DOMAIN_AFFECT_CONFIG)
+            if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
                 vmdef->cputune.shares = value_ul;
+                vmdef->cputune.sharesSpecified = true;
+            }
+
 
         } else if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD)) {
             SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD,
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 8fb2a93..75dcdc6 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1504,6 +1504,7 @@ virVMXParseConfig(virVMXContext *ctx,
                              "found '%s'"), sched_cpu_shares);
             goto cleanup;
         }
+        def->cputune.sharesSpecified = true;
     }
 
     /* def:lifecycle */
-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]