From: Peter Krempa Date: Wed, 3 Aug 2016 10:57:23 +0000 (+0200) Subject: qemu: setcpus: Report better errors X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=e96041ff1ac270b719e43bf0e3d5a224fe61c26a;p=libvirt.git qemu: setcpus: Report better errors Mention whether it was the live or persistent definition which caused an error reported and explicitly error out in case when attempting to set maximum vcpu count for a live domain. --- diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5a7733c542..3708146c8e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4764,7 +4764,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, virDomainDefPtr def; virDomainDefPtr persistentDef; int ret = -1; - unsigned int maxvcpus = 0; virQEMUDriverConfigPtr cfg = NULL; qemuDomainObjPrivatePtr priv; size_t i; @@ -4800,6 +4799,34 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) goto endjob; + if (def) { + if (flags & VIR_DOMAIN_VCPU_MAXIMUM) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("maximum vcpu count of a live domain can't be " + "modified")); + goto endjob; + } + + if (nvcpus > virDomainDefGetVcpusMax(def)) { + virReportError(VIR_ERR_INVALID_ARG, + _("requested vcpus is greater than max allowable" + " vcpus for the live domain: %u > %u"), + nvcpus, virDomainDefGetVcpusMax(def)); + goto endjob; + } + } + + if (persistentDef) { + if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) && + nvcpus > virDomainDefGetVcpusMax(persistentDef)) { + virReportError(VIR_ERR_INVALID_ARG, + _("requested vcpus is greater than max allowable" + " vcpus for the persistent domain: %u > %u"), + nvcpus, virDomainDefGetVcpusMax(persistentDef)); + goto endjob; + } + } + if (def && virNumaIsAvailable() && virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) { if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0, @@ -4817,20 +4844,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, goto endjob; } - if (def) - maxvcpus = virDomainDefGetVcpusMax(def); - if (persistentDef) { - if (!maxvcpus || maxvcpus > virDomainDefGetVcpusMax(persistentDef)) - maxvcpus = virDomainDefGetVcpusMax(persistentDef); - } - if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) && nvcpus > maxvcpus) { - virReportError(VIR_ERR_INVALID_ARG, - _("requested vcpus is greater than max allowable" - " vcpus for the domain: %d > %d"), - nvcpus, maxvcpus); - goto endjob; - } - if (def) { if (nvcpus > virDomainDefGetVcpus(def)) { for (i = virDomainDefGetVcpus(def); i < nvcpus; i++) {