提交 3b3b9805 编写于 作者: P Peter Krempa

qemu: cpu hotplug: Move loops to qemuDomainSetVcpusFlags

qemuDomainHotplugVcpus/qemuDomainHotunplugVcpus are complex enough in
regards of adding one CPU. Additionally it will be desired to reuse
those functions later with specific vCPU hotplug.

Move the loops for adding vCPUs into qemuDomainSetVcpusFlags so that the
helpers can be made simpler and more straightforward.
上级 7912d879
...@@ -4694,10 +4694,9 @@ qemuDomainDelCgroupForThread(virCgroupPtr cgroup, ...@@ -4694,10 +4694,9 @@ qemuDomainDelCgroupForThread(virCgroupPtr cgroup,
static int static int
qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver, qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
unsigned int nvcpus) unsigned int vcpu)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
size_t i;
int ret = -1; int ret = -1;
int oldvcpus = virDomainDefGetVcpus(vm->def); int oldvcpus = virDomainDefGetVcpus(vm->def);
int vcpus = oldvcpus; int vcpus = oldvcpus;
...@@ -4709,13 +4708,10 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver, ...@@ -4709,13 +4708,10 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
for (i = vcpus; i < nvcpus; i++) { if (qemuMonitorSetCPU(priv->mon, vcpu, true) < 0)
/* Online new CPU */ goto exit_monitor;
if (qemuMonitorSetCPU(priv->mon, i, true) < 0)
goto exit_monitor;
vcpus++; vcpus++;
}
/* After hotplugging the CPUs we need to re-detect threads corresponding /* After hotplugging the CPUs we need to re-detect threads corresponding
* to the virtual CPUs. Some older versions don't provide the thread ID * to the virtual CPUs. Some older versions don't provide the thread ID
...@@ -4747,36 +4743,34 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver, ...@@ -4747,36 +4743,34 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
&mem_mask, -1) < 0) &mem_mask, -1) < 0)
goto cleanup; goto cleanup;
for (i = oldvcpus; i < nvcpus; i++) { if (priv->cgroup) {
if (priv->cgroup) { cgroup_vcpu =
cgroup_vcpu = qemuDomainAddCgroupForThread(priv->cgroup,
qemuDomainAddCgroupForThread(priv->cgroup, VIR_CGROUP_THREAD_VCPU,
VIR_CGROUP_THREAD_VCPU, vcpu, mem_mask,
i, mem_mask, cpupids[vcpu]);
cpupids[i]); if (!cgroup_vcpu)
if (!cgroup_vcpu) goto cleanup;
goto cleanup; }
}
/* Inherit def->cpuset */
if (vm->def->cpumask) {
if (qemuDomainHotplugAddPin(vm->def->cpumask, i,
&vm->def->cputune.vcpupin,
&vm->def->cputune.nvcpupin) < 0)
goto cleanup;
if (qemuDomainHotplugPinThread(vm->def->cpumask, i, cpupids[i], /* Inherit def->cpuset */
cgroup_vcpu) < 0) if (vm->def->cpumask) {
goto cleanup; if (qemuDomainHotplugAddPin(vm->def->cpumask, vcpu,
} &vm->def->cputune.vcpupin,
virCgroupFree(&cgroup_vcpu); &vm->def->cputune.nvcpupin) < 0)
goto cleanup;
if (qemuProcessSetSchedParams(i, cpupids[i], if (qemuDomainHotplugPinThread(vm->def->cpumask, vcpu, cpupids[vcpu],
vm->def->cputune.nvcpusched, cgroup_vcpu) < 0) {
vm->def->cputune.vcpusched) < 0)
goto cleanup; goto cleanup;
}
} }
if (qemuProcessSetSchedParams(vcpu, cpupids[vcpu],
vm->def->cputune.nvcpusched,
vm->def->cputune.vcpusched) < 0)
goto cleanup;
priv->nvcpupids = ncpupids; priv->nvcpupids = ncpupids;
VIR_FREE(priv->vcpupids); VIR_FREE(priv->vcpupids);
priv->vcpupids = cpupids; priv->vcpupids = cpupids;
...@@ -4790,7 +4784,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver, ...@@ -4790,7 +4784,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
if (virDomainObjIsActive(vm) && if (virDomainObjIsActive(vm) &&
virDomainDefSetVcpus(vm->def, vcpus) < 0) virDomainDefSetVcpus(vm->def, vcpus) < 0)
ret = -1; ret = -1;
virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", ret == 0); virDomainAuditVcpu(vm, oldvcpus, vcpus, "update", ret == 0);
if (cgroup_vcpu) if (cgroup_vcpu)
virCgroupFree(&cgroup_vcpu); virCgroupFree(&cgroup_vcpu);
return ret; return ret;
...@@ -4804,10 +4798,9 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver, ...@@ -4804,10 +4798,9 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
static int static int
qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver, qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
unsigned int nvcpus) unsigned int vcpu)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
size_t i;
int ret = -1; int ret = -1;
int oldvcpus = virDomainDefGetVcpus(vm->def); int oldvcpus = virDomainDefGetVcpus(vm->def);
int vcpus = oldvcpus; int vcpus = oldvcpus;
...@@ -4816,13 +4809,10 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver, ...@@ -4816,13 +4809,10 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
for (i = vcpus - 1; i >= nvcpus; i--) { if (qemuMonitorSetCPU(priv->mon, vcpu, false) < 0)
/* Offline old CPU */ goto exit_monitor;
if (qemuMonitorSetCPU(priv->mon, i, false) < 0)
goto exit_monitor;
vcpus--; vcpus--;
}
/* After hotplugging the CPUs we need to re-detect threads corresponding /* After hotplugging the CPUs we need to re-detect threads corresponding
* to the virtual CPUs. Some older versions don't provide the thread ID * to the virtual CPUs. Some older versions don't provide the thread ID
...@@ -4854,16 +4844,14 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver, ...@@ -4854,16 +4844,14 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
for (i = oldvcpus - 1; i >= nvcpus; i--) { if (qemuDomainDelCgroupForThread(priv->cgroup,
if (qemuDomainDelCgroupForThread(priv->cgroup, VIR_CGROUP_THREAD_VCPU, vcpu) < 0)
VIR_CGROUP_THREAD_VCPU, i) < 0) goto cleanup;
goto cleanup;
/* Free vcpupin setting */ /* Free vcpupin setting */
virDomainPinDel(&vm->def->cputune.vcpupin, virDomainPinDel(&vm->def->cputune.vcpupin,
&vm->def->cputune.nvcpupin, &vm->def->cputune.nvcpupin,
i); vcpu);
}
priv->nvcpupids = ncpupids; priv->nvcpupids = ncpupids;
VIR_FREE(priv->vcpupids); VIR_FREE(priv->vcpupids);
...@@ -4877,7 +4865,7 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver, ...@@ -4877,7 +4865,7 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
if (virDomainObjIsActive(vm) && if (virDomainObjIsActive(vm) &&
virDomainDefSetVcpus(vm->def, vcpus) < 0) virDomainDefSetVcpus(vm->def, vcpus) < 0)
ret = -1; ret = -1;
virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", ret == 0); virDomainAuditVcpu(vm, oldvcpus, vcpus, "update", ret == 0);
return ret; return ret;
exit_monitor: exit_monitor:
...@@ -5020,11 +5008,15 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, ...@@ -5020,11 +5008,15 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
if (def) { if (def) {
if (nvcpus > virDomainDefGetVcpus(def)) { if (nvcpus > virDomainDefGetVcpus(def)) {
if (qemuDomainHotplugAddVcpu(driver, vm, nvcpus) < 0) for (i = virDomainDefGetVcpus(def); i < nvcpus; i++) {
goto endjob; if (qemuDomainHotplugAddVcpu(driver, vm, i) < 0)
goto endjob;
}
} else { } else {
if (qemuDomainHotplugDelVcpu(driver, vm, nvcpus) < 0) for (i = virDomainDefGetVcpus(def) - 1; i >= nvcpus; i--) {
goto endjob; if (qemuDomainHotplugDelVcpu(driver, vm, i) < 0)
goto endjob;
}
} }
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0) if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册