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