]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Show the real cpu shares value in live XML
authorJán Tomko <jtomko@redhat.com>
Tue, 4 Mar 2014 12:56:24 +0000 (13:56 +0100)
committerJán Tomko <jtomko@redhat.com>
Wed, 26 Mar 2014 09:10:13 +0000 (10:10 +0100)
Currently, the Linux kernel treats values of '0' and '1' as
the minimum of 2. Values larger than the maximum are changed
to the maximum.

Re-reading the shares value after setting it reflects this in
the live domain XML.

src/lxc/lxc_cgroup.c
src/lxc/lxc_driver.c
src/qemu/qemu_cgroup.c
src/qemu/qemu_driver.c

index 2bf0c720348b402c6c959f2f4108906e759faf98..02960d67a4cd828cc6962cfcb121a84cedfd6e81 100644 (file)
@@ -38,9 +38,16 @@ static int virLXCCgroupSetupCpuTune(virDomainDefPtr def,
                                     virCgroupPtr cgroup)
 {
     int ret = -1;
-    if (def->cputune.sharesSpecified &&
-        virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0)
-        goto cleanup;
+
+    if (def->cputune.sharesSpecified) {
+        unsigned long long val;
+        if (virCgroupSetCpuShares(cgroup, def->cputune.shares) < 0)
+            goto cleanup;
+
+        if (virCgroupGetCpuShares(cgroup, &val) < 0)
+            goto cleanup;
+        def->cputune.shares = val;
+    }
 
     if (def->cputune.quota != 0 &&
         virCgroupSetCpuCfsQuota(cgroup, def->cputune.quota) < 0)
index c416190ee3799ae9d36d5a5f0a5aa700d0a5fad9..05464cbf207027d2bb8252c58af12a59acc0f868 100644 (file)
@@ -1898,10 +1898,14 @@ lxcDomainSetSchedulerParametersFlags(virDomainPtr dom,
 
         if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
             if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+                unsigned long long val;
                 if (virCgroupSetCpuShares(priv->cgroup, params[i].value.ul) < 0)
                     goto cleanup;
 
-                vm->def->cputune.shares = params[i].value.ul;
+                if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
+                    goto cleanup;
+
+                vm->def->cputune.shares = val;
                 vm->def->cputune.sharesSpecified = true;
             }
 
index 8a31ae23ada919ec9c1855f84ee76035a9bc5df2..ce1639388f8bdf232a6cd655f237fabc831b34b4 100644 (file)
@@ -655,9 +655,15 @@ qemuSetupCpuCgroup(virDomainObjPtr vm)
        }
     }
 
-    if (vm->def->cputune.sharesSpecified &&
-        virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares) < 0)
-        return -1;
+    if (vm->def->cputune.sharesSpecified) {
+        unsigned long long val;
+        if (virCgroupSetCpuShares(priv->cgroup, vm->def->cputune.shares) < 0)
+            return -1;
+
+        if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
+            return -1;
+        vm->def->cputune.shares = val;
+    }
 
     return 0;
 }
index fca313b66b6e1fb7cd10355367ce5a91c7d1859d..6d62519d721e0c4e0c07047fa37c76258246312a 100644 (file)
@@ -9085,9 +9085,14 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
 
         if (STREQ(param->field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
             if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+                unsigned long long val;
                 if (virCgroupSetCpuShares(priv->cgroup, value_ul) < 0)
                     goto cleanup;
-                vm->def->cputune.shares = value_ul;
+
+                if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
+                    goto cleanup;
+
+                vm->def->cputune.shares = val;
                 vm->def->cputune.sharesSpecified = true;
             }