render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
6ae9ed
From f613684014782419a1e4951443658403193f458f Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <f613684014782419a1e4951443658403193f458f@dist-git>
6ae9ed
From: Peter Krempa <pkrempa@redhat.com>
6ae9ed
Date: Wed, 24 Aug 2016 16:11:12 -0400
6ae9ed
Subject: [PATCH] qemu: setcpus: Report better errors
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1097930
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1224341
6ae9ed
6ae9ed
Mention whether it was the live or persistent definition which caused an
6ae9ed
error reported and explicitly error out in case when attempting to set
6ae9ed
maximum vcpu count for a live domain.
6ae9ed
6ae9ed
(cherry picked from commit e96041ff1ac270b719e43bf0e3d5a224fe61c26a)
6ae9ed
---
6ae9ed
 src/qemu/qemu_driver.c | 43 ++++++++++++++++++++++++++++---------------
6ae9ed
 1 file changed, 28 insertions(+), 15 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
6ae9ed
index 1011bb8..4e703ae 100644
6ae9ed
--- a/src/qemu/qemu_driver.c
6ae9ed
+++ b/src/qemu/qemu_driver.c
6ae9ed
@@ -4770,7 +4770,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
6ae9ed
     virDomainDefPtr def;
6ae9ed
     virDomainDefPtr persistentDef;
6ae9ed
     int ret = -1;
6ae9ed
-    unsigned int maxvcpus = 0;
6ae9ed
     virQEMUDriverConfigPtr cfg = NULL;
6ae9ed
     qemuDomainObjPrivatePtr priv;
6ae9ed
     size_t i;
6ae9ed
@@ -4806,6 +4805,34 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
6ae9ed
     if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
6ae9ed
         goto endjob;
6ae9ed
 
6ae9ed
+    if (def) {
6ae9ed
+        if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
6ae9ed
+            virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
6ae9ed
+                           _("maximum vcpu count of a live domain can't be "
6ae9ed
+                             "modified"));
6ae9ed
+            goto endjob;
6ae9ed
+        }
6ae9ed
+
6ae9ed
+        if (nvcpus > virDomainDefGetVcpusMax(def)) {
6ae9ed
+            virReportError(VIR_ERR_INVALID_ARG,
6ae9ed
+                           _("requested vcpus is greater than max allowable"
6ae9ed
+                             " vcpus for the live domain: %u > %u"),
6ae9ed
+                           nvcpus, virDomainDefGetVcpusMax(def));
6ae9ed
+            goto endjob;
6ae9ed
+        }
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    if (persistentDef) {
6ae9ed
+        if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) &&
6ae9ed
+            nvcpus > virDomainDefGetVcpusMax(persistentDef)) {
6ae9ed
+            virReportError(VIR_ERR_INVALID_ARG,
6ae9ed
+                           _("requested vcpus is greater than max allowable"
6ae9ed
+                             " vcpus for the persistent domain: %u > %u"),
6ae9ed
+                           nvcpus, virDomainDefGetVcpusMax(persistentDef));
6ae9ed
+            goto endjob;
6ae9ed
+        }
6ae9ed
+    }
6ae9ed
+
6ae9ed
     if (def && virNumaIsAvailable() &&
6ae9ed
         virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
6ae9ed
         if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0,
6ae9ed
@@ -4823,20 +4850,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
6ae9ed
             goto endjob;
6ae9ed
     }
6ae9ed
 
6ae9ed
-    if (def)
6ae9ed
-        maxvcpus = virDomainDefGetVcpusMax(def);
6ae9ed
-    if (persistentDef) {
6ae9ed
-        if (!maxvcpus || maxvcpus > virDomainDefGetVcpusMax(persistentDef))
6ae9ed
-            maxvcpus = virDomainDefGetVcpusMax(persistentDef);
6ae9ed
-    }
6ae9ed
-    if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) && nvcpus > maxvcpus) {
6ae9ed
-        virReportError(VIR_ERR_INVALID_ARG,
6ae9ed
-                       _("requested vcpus is greater than max allowable"
6ae9ed
-                         " vcpus for the domain: %d > %d"),
6ae9ed
-                       nvcpus, maxvcpus);
6ae9ed
-        goto endjob;
6ae9ed
-    }
6ae9ed
-
6ae9ed
     if (def) {
6ae9ed
         if (nvcpus > virDomainDefGetVcpus(def)) {
6ae9ed
             for (i = virDomainDefGetVcpus(def); i < nvcpus; i++) {
6ae9ed
-- 
6ae9ed
2.10.0
6ae9ed