mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 18:05:20 +00:00
qemu: vcpupin: Extract live vcpupin setting into a separate function
The function was now beyond maintainability.
This commit is contained in:
parent
adefc561cc
commit
475c530cd3
@ -4972,6 +4972,82 @@ qemuDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuDomainPinVcpuLive(virDomainObjPtr vm,
|
||||||
|
virDomainDefPtr def,
|
||||||
|
int vcpu,
|
||||||
|
virQEMUDriverPtr driver,
|
||||||
|
virQEMUDriverConfigPtr cfg,
|
||||||
|
virBitmapPtr cpumap)
|
||||||
|
{
|
||||||
|
virDomainVcpuInfoPtr vcpuinfo;
|
||||||
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
|
virCgroupPtr cgroup_vcpu = NULL;
|
||||||
|
char *str = NULL;
|
||||||
|
virObjectEventPtr event = NULL;
|
||||||
|
char paramField[VIR_TYPED_PARAM_FIELD_LENGTH] = "";
|
||||||
|
virTypedParameterPtr eventParams = NULL;
|
||||||
|
int eventNparams = 0;
|
||||||
|
int eventMaxparams = 0;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!qemuDomainHasVcpuPids(vm)) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
|
"%s", _("cpu affinity is not supported"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(vcpuinfo = virDomainDefGetVcpu(def, vcpu))) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("vcpu %d is out of range of live cpu count %d"),
|
||||||
|
vcpu, virDomainDefGetVcpusMax(def));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vcpuinfo->online) {
|
||||||
|
/* Configure the corresponding cpuset cgroup before set affinity. */
|
||||||
|
if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
|
||||||
|
if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_VCPU, vcpu,
|
||||||
|
false, &cgroup_vcpu) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
if (qemuSetupCgroupCpusetCpus(cgroup_vcpu, cpumap) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, vcpu), cpumap) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
virBitmapFree(vcpuinfo->cpumask);
|
||||||
|
vcpuinfo->cpumask = cpumap;
|
||||||
|
cpumap = NULL;
|
||||||
|
|
||||||
|
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (snprintf(paramField, VIR_TYPED_PARAM_FIELD_LENGTH,
|
||||||
|
VIR_DOMAIN_TUNABLE_CPU_VCPUPIN, vcpu) < 0) {
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
str = virBitmapFormat(vcpuinfo->cpumask);
|
||||||
|
if (virTypedParamsAddString(&eventParams, &eventNparams,
|
||||||
|
&eventMaxparams, paramField, str) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
event = virDomainEventTunableNewFromObj(vm, eventParams, eventNparams);
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virBitmapFree(cpumap);
|
||||||
|
virCgroupFree(&cgroup_vcpu);
|
||||||
|
VIR_FREE(str);
|
||||||
|
qemuDomainEventQueue(driver, event);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainPinVcpuFlags(virDomainPtr dom,
|
qemuDomainPinVcpuFlags(virDomainPtr dom,
|
||||||
unsigned int vcpu,
|
unsigned int vcpu,
|
||||||
@ -4984,21 +5060,12 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
|
|||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
virDomainDefPtr def;
|
virDomainDefPtr def;
|
||||||
virDomainDefPtr persistentDef;
|
virDomainDefPtr persistentDef;
|
||||||
virCgroupPtr cgroup_vcpu = NULL;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
qemuDomainObjPrivatePtr priv;
|
|
||||||
virBitmapPtr pcpumap = NULL;
|
virBitmapPtr pcpumap = NULL;
|
||||||
virBitmapPtr pcpumaplive = NULL;
|
virBitmapPtr pcpumaplive = NULL;
|
||||||
virBitmapPtr pcpumappersist = NULL;
|
virBitmapPtr pcpumappersist = NULL;
|
||||||
virDomainVcpuInfoPtr vcpuinfolive = NULL;
|
|
||||||
virDomainVcpuInfoPtr vcpuinfopersist = NULL;
|
virDomainVcpuInfoPtr vcpuinfopersist = NULL;
|
||||||
virQEMUDriverConfigPtr cfg = NULL;
|
virQEMUDriverConfigPtr cfg = NULL;
|
||||||
virObjectEventPtr event = NULL;
|
|
||||||
char paramField[VIR_TYPED_PARAM_FIELD_LENGTH] = "";
|
|
||||||
char *str = NULL;
|
|
||||||
virTypedParameterPtr eventParams = NULL;
|
|
||||||
int eventNparams = 0;
|
|
||||||
int eventMaxparams = 0;
|
|
||||||
|
|
||||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||||
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||||
@ -5017,15 +5084,6 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
|
|||||||
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
priv = vm->privateData;
|
|
||||||
|
|
||||||
if (def && !(vcpuinfolive = virDomainDefGetVcpu(def, vcpu))) {
|
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("vcpu %d is out of range of live cpu count %d"),
|
|
||||||
vcpu, virDomainDefGetVcpus(def));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (persistentDef &&
|
if (persistentDef &&
|
||||||
!(vcpuinfopersist = virDomainDefGetVcpu(persistentDef, vcpu))) {
|
!(vcpuinfopersist = virDomainDefGetVcpu(persistentDef, vcpu))) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
@ -5048,44 +5106,12 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (def) {
|
if (def) {
|
||||||
if (!qemuDomainHasVcpuPids(vm)) {
|
if (qemuDomainPinVcpuLive(vm, def, vcpu, driver, cfg, pcpumaplive) < 0) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
pcpumaplive = NULL;
|
||||||
"%s", _("cpu affinity is not supported"));
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vcpuinfolive->online) {
|
|
||||||
/* Configure the corresponding cpuset cgroup before set affinity. */
|
|
||||||
if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
|
|
||||||
if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_VCPU, vcpu,
|
|
||||||
false, &cgroup_vcpu) < 0)
|
|
||||||
goto endjob;
|
|
||||||
if (qemuSetupCgroupCpusetCpus(cgroup_vcpu, pcpumap) < 0)
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, vcpu), pcpumap) < 0)
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
|
|
||||||
virBitmapFree(vcpuinfolive->cpumask);
|
|
||||||
vcpuinfolive->cpumask = pcpumaplive;
|
|
||||||
pcpumaplive = NULL;
|
pcpumaplive = NULL;
|
||||||
|
|
||||||
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
|
|
||||||
goto endjob;
|
|
||||||
|
|
||||||
if (snprintf(paramField, VIR_TYPED_PARAM_FIELD_LENGTH,
|
|
||||||
VIR_DOMAIN_TUNABLE_CPU_VCPUPIN, vcpu) < 0) {
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
|
|
||||||
str = virBitmapFormat(pcpumap);
|
|
||||||
if (virTypedParamsAddString(&eventParams, &eventNparams,
|
|
||||||
&eventMaxparams, paramField, str) < 0)
|
|
||||||
goto endjob;
|
|
||||||
|
|
||||||
event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (persistentDef) {
|
if (persistentDef) {
|
||||||
@ -5103,11 +5129,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
|
|||||||
qemuDomainObjEndJob(driver, vm);
|
qemuDomainObjEndJob(driver, vm);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (cgroup_vcpu)
|
|
||||||
virCgroupFree(&cgroup_vcpu);
|
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
qemuDomainEventQueue(driver, event);
|
|
||||||
VIR_FREE(str);
|
|
||||||
virBitmapFree(pcpumap);
|
virBitmapFree(pcpumap);
|
||||||
virBitmapFree(pcpumaplive);
|
virBitmapFree(pcpumaplive);
|
||||||
virBitmapFree(pcpumappersist);
|
virBitmapFree(pcpumappersist);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user