[PATCH] Don't call virCgroupSetCpuShares with a zero value

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

 



In the XML parser, a zero in the <shares> element is treated
as if it was omitted completely. No value is written to
the cgroups fs when the domain is started and the OS default
is used.

virDomainSetSchedulerParameters treated 0 as a valid value,
which got changed to '2' by kernel. Treat 0 as 'not specified'
instead, to be consistent with the XML and how other scheduler
parameters deal with a 0 value, making it a no-op on live domains.

Also clarify the documentation.
---
 docs/formatdomain.html.in | 2 +-
 src/lxc/lxc_driver.c      | 2 +-
 src/qemu/qemu_driver.c    | 2 +-
 tools/virsh.pod           | 3 ++-
 4 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index a094524..9749d55 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -508,7 +508,7 @@
       <dt><code>shares</code></dt>
       <dd>
         The optional <code>shares</code> element specifies the proportional
-        weighted share for the domain. If this is omitted, it defaults to
+        weighted share for the domain. If this is omitted or 0, it defaults to
         the OS provided defaults. NB, There is no unit for the value,
         it's a relative measure based on the setting of other VM,
         e.g. A VM configured with value
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index c499182..7ac3691 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1732,7 +1732,7 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
         virTypedParameterPtr param = &params[i];
 
         if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
-            if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+            if (flags & VIR_DOMAIN_AFFECT_LIVE && params[i].value.ul) {
                 if (virCgroupSetCpuShares(priv->cgroup, params[i].value.ul) < 0)
                     goto cleanup;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 45d11cd..eba1e1a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8583,7 +8583,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
         value_l = param->value.l;
 
         if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
-            if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+            if (flags & VIR_DOMAIN_AFFECT_LIVE && value_ul) {
                 if (virCgroupSetCpuShares(priv->cgroup, value_ul) < 0)
                     goto cleanup;
                 vm->def->cputune.shares = value_ul;
diff --git a/tools/virsh.pod b/tools/virsh.pod
index c6a8be3..092b6ae 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1393,7 +1393,8 @@ If I<--current> is specified, affect the current guest state.
 B<Note>: The cpu_shares parameter has a valid value range of 0-262144; Negative
 values are wrapped to positive, and larger values are capped at the maximum.
 Therefore, -1 is a useful shorthand for 262144. On the Linux kernel, the
-values 0 and 1 are automatically converted to a minimal value of 2.
+value 1 is automatically converted to a minimal value of 2. The value 0
+is the same as not specifying that parameter.
 
 B<Note>: The weight and cap parameters are defined only for the
 XEN_CREDIT scheduler and are now I<DEPRECATED>.
-- 
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]