Blob Blame History Raw
From f613684014782419a1e4951443658403193f458f Mon Sep 17 00:00:00 2001
Message-Id: <f613684014782419a1e4951443658403193f458f@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 24 Aug 2016 16:11:12 -0400
Subject: [PATCH] qemu: setcpus: Report better errors

https://bugzilla.redhat.com/show_bug.cgi?id=1097930
https://bugzilla.redhat.com/show_bug.cgi?id=1224341

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.

(cherry picked from commit e96041ff1ac270b719e43bf0e3d5a224fe61c26a)
---
 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 1011bb8..4e703ae 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4770,7 +4770,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;
@@ -4806,6 +4805,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,
@@ -4823,20 +4850,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.10.0