render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
6ae9ed
From f76acdb6a03b2a572a552713be49366494d6ae2b Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <f76acdb6a03b2a572a552713be49366494d6ae2b@dist-git>
6ae9ed
From: Peter Krempa <pkrempa@redhat.com>
6ae9ed
Date: Wed, 24 Aug 2016 16:11:15 -0400
6ae9ed
Subject: [PATCH] qemu: driver: Split out regular vcpu hotplug code into a
6ae9ed
 function
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1097930
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1224341
6ae9ed
6ae9ed
All other modes of qemuDomainSetVcpusFlags have helpers so finish the
6ae9ed
work by splitting the regular code into a new function.
6ae9ed
6ae9ed
This patch also touches up the coding (spacing) style.
6ae9ed
6ae9ed
(cherry picked from commit c6f26fc207a31fd069779ebdd400196249c9784a)
6ae9ed
---
6ae9ed
 src/qemu/qemu_driver.c | 100 ++++++++++++++++++++++++++-----------------------
6ae9ed
 1 file changed, 53 insertions(+), 47 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
6ae9ed
index 224c5d4..1b433f8 100644
6ae9ed
--- a/src/qemu/qemu_driver.c
6ae9ed
+++ b/src/qemu/qemu_driver.c
6ae9ed
@@ -4864,7 +4864,53 @@ qemuDomainSetVcpusLive(virQEMUDriverPtr driver,
6ae9ed
 
6ae9ed
 
6ae9ed
 static int
6ae9ed
-qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
6ae9ed
+qemuDomainSetVcpusInternal(virQEMUDriverPtr driver,
6ae9ed
+                           virDomainObjPtr vm,
6ae9ed
+                           virDomainDefPtr def,
6ae9ed
+                           virDomainDefPtr persistentDef,
6ae9ed
+                           unsigned int nvcpus)
6ae9ed
+{
6ae9ed
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
6ae9ed
+    int ret = -1;
6ae9ed
+
6ae9ed
+    if (def && 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 cleanup;
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    if (persistentDef && 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 cleanup;
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    if (def && qemuDomainSetVcpusLive(driver, cfg, vm, nvcpus) < 0)
6ae9ed
+        goto cleanup;
6ae9ed
+
6ae9ed
+    if (persistentDef) {
6ae9ed
+        if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)
6ae9ed
+            goto cleanup;
6ae9ed
+
6ae9ed
+        if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
6ae9ed
+            goto cleanup;
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    ret = 0;
6ae9ed
+
6ae9ed
+ cleanup:
6ae9ed
+    virObjectUnref(cfg);
6ae9ed
+    return ret;
6ae9ed
+}
6ae9ed
+
6ae9ed
+
6ae9ed
+static int
6ae9ed
+qemuDomainSetVcpusFlags(virDomainPtr dom,
6ae9ed
+                        unsigned int nvcpus,
6ae9ed
                         unsigned int flags)
6ae9ed
 {
6ae9ed
     virQEMUDriverPtr driver = dom->conn->privateData;
6ae9ed
@@ -4872,7 +4918,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
6ae9ed
     virDomainDefPtr def;
6ae9ed
     virDomainDefPtr persistentDef;
6ae9ed
     int ret = -1;
6ae9ed
-    virQEMUDriverConfigPtr cfg = NULL;
6ae9ed
 
6ae9ed
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
6ae9ed
                   VIR_DOMAIN_AFFECT_CONFIG |
6ae9ed
@@ -4882,70 +4927,31 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
6ae9ed
     if (!(vm = qemuDomObjFromDomain(dom)))
6ae9ed
         goto cleanup;
6ae9ed
 
6ae9ed
-    cfg = virQEMUDriverGetConfig(driver);
6ae9ed
-
6ae9ed
     if (virDomainSetVcpusFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
6ae9ed
         goto cleanup;
6ae9ed
 
6ae9ed
     if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
6ae9ed
         goto cleanup;
6ae9ed
 
6ae9ed
-    if (flags & VIR_DOMAIN_VCPU_GUEST) {
6ae9ed
-        ret = qemuDomainSetVcpusAgent(vm, nvcpus);
6ae9ed
-        goto endjob;
6ae9ed
-    }
6ae9ed
-
6ae9ed
     if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
6ae9ed
         goto endjob;
6ae9ed
 
6ae9ed
-    if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
6ae9ed
+    if (flags & VIR_DOMAIN_VCPU_GUEST)
6ae9ed
+        ret = qemuDomainSetVcpusAgent(vm, nvcpus);
6ae9ed
+    else if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
6ae9ed
         ret = qemuDomainSetVcpusMax(driver, def, persistentDef, nvcpus);
6ae9ed
-        goto endjob;
6ae9ed
-    }
6ae9ed
-
6ae9ed
-    if (def) {
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 (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 && qemuDomainSetVcpusLive(driver, cfg, vm, nvcpus) < 0)
6ae9ed
-        goto endjob;
6ae9ed
-
6ae9ed
-    if (persistentDef) {
6ae9ed
-        if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)
6ae9ed
-            goto endjob;
6ae9ed
-
6ae9ed
-        if (virDomainSaveConfig(cfg->configDir, driver->caps,
6ae9ed
-                                persistentDef) < 0)
6ae9ed
-            goto endjob;
6ae9ed
-    }
6ae9ed
-
6ae9ed
-    ret = 0;
6ae9ed
+    else
6ae9ed
+        ret = qemuDomainSetVcpusInternal(driver, vm, def, persistentDef, nvcpus);
6ae9ed
 
6ae9ed
  endjob:
6ae9ed
     qemuDomainObjEndJob(driver, vm);
6ae9ed
 
6ae9ed
  cleanup:
6ae9ed
     virDomainObjEndAPI(&vm;;
6ae9ed
-    virObjectUnref(cfg);
6ae9ed
     return ret;
6ae9ed
 }
6ae9ed
 
6ae9ed
+
6ae9ed
 static int
6ae9ed
 qemuDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
6ae9ed
 {
6ae9ed
-- 
6ae9ed
2.10.0
6ae9ed