render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
6ae9ed
From 2d4e8abbe6a54d8472ac867ace641e5987b08495 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <2d4e8abbe6a54d8472ac867ace641e5987b08495@dist-git>
6ae9ed
From: Peter Krempa <pkrempa@redhat.com>
6ae9ed
Date: Wed, 24 Aug 2016 16:11:14 -0400
6ae9ed
Subject: [PATCH] qemu: driver: Extract setting of live vcpu count
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1097930
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1224341
6ae9ed
6ae9ed
The live code does ugly things. Contain it in a separate function.
6ae9ed
6ae9ed
(cherry picked from commit 2fa7db93de99df54adcf3948a16ee98fb5c11e59)
6ae9ed
---
6ae9ed
 src/qemu/qemu_driver.c | 121 +++++++++++++++++++++++++++----------------------
6ae9ed
 1 file changed, 68 insertions(+), 53 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
6ae9ed
index 520a628..224c5d4 100644
6ae9ed
--- a/src/qemu/qemu_driver.c
6ae9ed
+++ b/src/qemu/qemu_driver.c
6ae9ed
@@ -4798,6 +4798,72 @@ qemuDomainSetVcpusMax(virQEMUDriverPtr driver,
6ae9ed
 
6ae9ed
 
6ae9ed
 static int
6ae9ed
+qemuDomainSetVcpusLive(virQEMUDriverPtr driver,
6ae9ed
+                       virQEMUDriverConfigPtr cfg,
6ae9ed
+                       virDomainObjPtr vm,
6ae9ed
+                       unsigned int nvcpus)
6ae9ed
+{
6ae9ed
+    qemuDomainObjPrivatePtr priv = vm->privateData;
6ae9ed
+    size_t i;
6ae9ed
+    virCgroupPtr cgroup_temp = NULL;
6ae9ed
+    char *mem_mask = NULL;
6ae9ed
+    char *all_nodes_str = NULL;
6ae9ed
+    virBitmapPtr all_nodes = NULL;
6ae9ed
+    virErrorPtr err = NULL;
6ae9ed
+    int ret = -1;
6ae9ed
+
6ae9ed
+    if (virNumaIsAvailable() &&
6ae9ed
+        virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
6ae9ed
+        if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0,
6ae9ed
+                               false, &cgroup_temp) < 0)
6ae9ed
+            goto cleanup;
6ae9ed
+
6ae9ed
+        if (!(all_nodes = virNumaGetHostNodeset()))
6ae9ed
+            goto cleanup;
6ae9ed
+
6ae9ed
+        if (!(all_nodes_str = virBitmapFormat(all_nodes)))
6ae9ed
+            goto cleanup;
6ae9ed
+
6ae9ed
+        if (virCgroupGetCpusetMems(cgroup_temp, &mem_mask) < 0 ||
6ae9ed
+            virCgroupSetCpusetMems(cgroup_temp, all_nodes_str) < 0)
6ae9ed
+            goto cleanup;
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    if (nvcpus > virDomainDefGetVcpus(vm->def)) {
6ae9ed
+        for (i = virDomainDefGetVcpus(vm->def); i < nvcpus; i++) {
6ae9ed
+            if (qemuDomainHotplugAddVcpu(driver, vm, i) < 0)
6ae9ed
+                goto cleanup;
6ae9ed
+        }
6ae9ed
+    } else {
6ae9ed
+        for (i = virDomainDefGetVcpus(vm->def) - 1; i >= nvcpus; i--) {
6ae9ed
+            if (qemuDomainHotplugDelVcpu(driver, vm, i) < 0)
6ae9ed
+                goto cleanup;
6ae9ed
+        }
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
6ae9ed
+        goto cleanup;
6ae9ed
+
6ae9ed
+    ret = 0;
6ae9ed
+
6ae9ed
+ cleanup:
6ae9ed
+    if (mem_mask) {
6ae9ed
+        err = virSaveLastError();
6ae9ed
+        virCgroupSetCpusetMems(cgroup_temp, mem_mask);
6ae9ed
+        virSetError(err);
6ae9ed
+        virFreeError(err);
6ae9ed
+        VIR_FREE(mem_mask);
6ae9ed
+    }
6ae9ed
+
6ae9ed
+    VIR_FREE(all_nodes_str);
6ae9ed
+    virBitmapFree(all_nodes);
6ae9ed
+    virCgroupFree(&cgroup_temp);
6ae9ed
+
6ae9ed
+    return ret;
6ae9ed
+}
6ae9ed
+
6ae9ed
+
6ae9ed
+static int
6ae9ed
 qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
6ae9ed
                         unsigned int flags)
6ae9ed
 {
6ae9ed
@@ -4807,13 +4873,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
6ae9ed
     virDomainDefPtr persistentDef;
6ae9ed
     int ret = -1;
6ae9ed
     virQEMUDriverConfigPtr cfg = NULL;
6ae9ed
-    qemuDomainObjPrivatePtr priv;
6ae9ed
-    size_t i;
6ae9ed
-    virCgroupPtr cgroup_temp = NULL;
6ae9ed
-    char *mem_mask = NULL;
6ae9ed
-    char *all_nodes_str = NULL;
6ae9ed
-    virBitmapPtr all_nodes = NULL;
6ae9ed
-    virErrorPtr err = NULL;
6ae9ed
 
6ae9ed
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
6ae9ed
                   VIR_DOMAIN_AFFECT_CONFIG |
6ae9ed
@@ -4828,8 +4887,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
6ae9ed
     if (virDomainSetVcpusFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
6ae9ed
         goto cleanup;
6ae9ed
 
6ae9ed
-    priv = vm->privateData;
6ae9ed
-
6ae9ed
     if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
6ae9ed
         goto cleanup;
6ae9ed
 
6ae9ed
@@ -4866,39 +4923,8 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
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
-                               false, &cgroup_temp) < 0)
6ae9ed
-            goto endjob;
6ae9ed
-
6ae9ed
-        if (!(all_nodes = virNumaGetHostNodeset()))
6ae9ed
-            goto endjob;
6ae9ed
-
6ae9ed
-        if (!(all_nodes_str = virBitmapFormat(all_nodes)))
6ae9ed
-            goto endjob;
6ae9ed
-
6ae9ed
-        if (virCgroupGetCpusetMems(cgroup_temp, &mem_mask) < 0 ||
6ae9ed
-            virCgroupSetCpusetMems(cgroup_temp, all_nodes_str) < 0)
6ae9ed
-            goto endjob;
6ae9ed
-    }
6ae9ed
-
6ae9ed
-    if (def) {
6ae9ed
-        if (nvcpus > virDomainDefGetVcpus(def)) {
6ae9ed
-            for (i = virDomainDefGetVcpus(def); i < nvcpus; i++) {
6ae9ed
-                if (qemuDomainHotplugAddVcpu(driver, vm, i) < 0)
6ae9ed
-                    goto endjob;
6ae9ed
-            }
6ae9ed
-        } else {
6ae9ed
-            for (i = virDomainDefGetVcpus(def) - 1; i >= nvcpus; i--) {
6ae9ed
-                if (qemuDomainHotplugDelVcpu(driver, vm, i) < 0)
6ae9ed
-                    goto endjob;
6ae9ed
-            }
6ae9ed
-        }
6ae9ed
-
6ae9ed
-        if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
6ae9ed
-            goto endjob;
6ae9ed
-    }
6ae9ed
+    if (def && qemuDomainSetVcpusLive(driver, cfg, vm, nvcpus) < 0)
6ae9ed
+        goto endjob;
6ae9ed
 
6ae9ed
     if (persistentDef) {
6ae9ed
         if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)
6ae9ed
@@ -4912,21 +4938,10 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
6ae9ed
     ret = 0;
6ae9ed
 
6ae9ed
  endjob:
6ae9ed
-    if (mem_mask) {
6ae9ed
-        err = virSaveLastError();
6ae9ed
-        virCgroupSetCpusetMems(cgroup_temp, mem_mask);
6ae9ed
-        virSetError(err);
6ae9ed
-        virFreeError(err);
6ae9ed
-    }
6ae9ed
-
6ae9ed
     qemuDomainObjEndJob(driver, vm);
6ae9ed
 
6ae9ed
  cleanup:
6ae9ed
     virDomainObjEndAPI(&vm;;
6ae9ed
-    VIR_FREE(mem_mask);
6ae9ed
-    VIR_FREE(all_nodes_str);
6ae9ed
-    virBitmapFree(all_nodes);
6ae9ed
-    virCgroupFree(&cgroup_temp);
6ae9ed
     virObjectUnref(cfg);
6ae9ed
     return ret;
6ae9ed
 }
6ae9ed
-- 
6ae9ed
2.10.0
6ae9ed