From: Ján Tomko Date: Tue, 4 Mar 2014 12:56:24 +0000 (+0100) Subject: Show the real cpu shares value in live XML X-Git-Tag: v1.2.3-rc1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97814d8ab3;p=thirdparty%2Flibvirt.git Show the real cpu shares value in live XML 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. --- diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 2bf0c72034..02960d67a4 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -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) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index c416190ee3..05464cbf20 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -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; } diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 8a31ae23ad..ce1639388f 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -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; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index fca313b66b..6d62519d72 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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; }