[libvirt] [PATCH 15/27] qemu: setcpus: Report better errors

Peter Krempa pkrempa at redhat.com
Fri Aug 5 13:56:11 UTC 2016


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.
---
 src/qemu/qemu_driver.c | 43 ++++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b22728e..dd6cfe0 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: %d > %d"),
+                           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: %d > %d"),
+                           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++) {
-- 
2.9.2




More information about the libvir-list mailing list