]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: setcpus: Report better errors
authorPeter Krempa <pkrempa@redhat.com>
Wed, 3 Aug 2016 10:57:23 +0000 (12:57 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 16 Aug 2016 08:54:23 +0000 (10:54 +0200)
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

index 5a7733c542d38eff3e22172371e7dfe97fb0efa2..3708146c8e19615e32587c6a7fe95046897b6811 100644 (file)
@@ -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++) {