提交 fd8fd0f9 编写于 作者: H Hu Tao 提交者: Daniel Veillard

refactor virDomainVcpuPinAdd()

上级 1fea5667
......@@ -10963,69 +10963,52 @@ cleanup:
return bitmap;
}
int
virDomainVcpuPinAdd(virDomainDefPtr def,
unsigned char *cpumap,
int maplen,
int vcpu)
int virDomainVcpuPinAdd(virDomainVcpuPinDefPtr *vcpupin_list,
int *nvcpupin,
unsigned char *cpumap,
int maplen,
int vcpu)
{
virDomainVcpuPinDefPtr *vcpupin_list = NULL;
virDomainVcpuPinDefPtr vcpupin = NULL;
char *cpumask = NULL;
if ((cpumask = bitmapFromBytemap(cpumap, maplen)) == NULL)
goto cleanup;
/* No vcpupin exists yet. */
if (!def->cputune.nvcpupin) {
if (VIR_ALLOC(vcpupin) < 0) {
virReportOOMError();
goto cleanup;
}
if (!vcpupin_list)
return -1;
if (VIR_ALLOC(vcpupin_list) < 0) {
virReportOOMError();
VIR_FREE(vcpupin);
goto cleanup;
}
if ((cpumask = bitmapFromBytemap(cpumap, maplen)) == NULL)
return -1;
vcpupin = virDomainVcpuPinFindByVcpu(vcpupin_list,
*nvcpupin,
vcpu);
if (vcpupin) {
vcpupin->vcpuid = vcpu;
vcpupin->cpumask = cpumask;
vcpupin_list[def->cputune.nvcpupin++] = vcpupin;
def->cputune.vcpupin = vcpupin_list;
} else {
if (virDomainVcpuPinIsDuplicate(def->cputune.vcpupin,
def->cputune.nvcpupin,
vcpu)) {
vcpupin = virDomainVcpuPinFindByVcpu(def->cputune.vcpupin,
def->cputune.nvcpupin,
vcpu);
vcpupin->vcpuid = vcpu;
vcpupin->cpumask = cpumask;
} else {
if (VIR_ALLOC(vcpupin) < 0) {
virReportOOMError();
goto cleanup;
}
return 0;
}
/* No existing vcpupin matches vcpu, adding a new one */
if (VIR_ALLOC(vcpupin) < 0) {
virReportOOMError();
VIR_FREE(cpumask);
return -1;
}
vcpupin->vcpuid = vcpu;
vcpupin->cpumask = cpumask;
if (VIR_REALLOC_N(def->cputune.vcpupin, def->cputune.nvcpupin + 1) < 0) {
virReportOOMError();
VIR_FREE(vcpupin);
goto cleanup;
}
vcpupin->vcpuid = vcpu;
vcpupin->cpumask = cpumask;
def->cputune.vcpupin[def->cputune.nvcpupin++] = vcpupin;
}
if (VIR_REALLOC_N(vcpupin_list, *nvcpupin + 1) < 0) {
virReportOOMError();
VIR_FREE(cpumask);
VIR_FREE(vcpupin);
return -1;
}
return 0;
vcpupin_list[(*nvcpupin)++] = vcpupin;
cleanup:
VIR_FREE(cpumask);
return -1;
return 0;
}
int
......
......@@ -1984,7 +1984,8 @@ int virDomainCpuSetParse(const char *str,
char *virDomainCpuSetFormat(char *cpuset,
int maxcpu);
int virDomainVcpuPinAdd(virDomainDefPtr def,
int virDomainVcpuPinAdd(virDomainVcpuPinDefPtr *vcpupin_list,
int *nvcpupin,
unsigned char *cpumap,
int maplen,
int vcpu);
......
......@@ -2454,7 +2454,18 @@ libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap,
goto cleanup;
}
if (virDomainVcpuPinAdd(vm->def, cpumap, maplen, vcpu) < 0) {
if (!vm->def->cputune.vcpupin) {
if (VIR_ALLOC(vm->def->cputune.vcpupin) < 0) {
virReportOOMError();
goto cleanup;
}
vm->def->cputune.nvcpupin = 0;
}
if (virDomainVcpuPinAdd(vm->def->cputune.vcpupin,
&vm->def->cputune.nvcpupin,
cpumap,
maplen,
vcpu) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("failed to update or add vcpupin xml"));
goto cleanup;
......
......@@ -3787,7 +3787,18 @@ qemudDomainPinVcpuFlags(virDomainPtr dom,
goto cleanup;
}
} else {
if (virDomainVcpuPinAdd(vm->def, cpumap, maplen, vcpu) < 0) {
if (!vm->def->cputune.vcpupin) {
if (VIR_ALLOC(vm->def->cputune.vcpupin) < 0) {
virReportOOMError();
goto cleanup;
}
vm->def->cputune.nvcpupin = 0;
}
if (virDomainVcpuPinAdd(vm->def->cputune.vcpupin,
&vm->def->cputune.nvcpupin,
cpumap,
maplen,
vcpu) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to update or add vcpupin xml of "
"a running domain"));
......@@ -3809,7 +3820,18 @@ qemudDomainPinVcpuFlags(virDomainPtr dom,
goto cleanup;
}
} else {
if (virDomainVcpuPinAdd(persistentDef, cpumap, maplen, vcpu) < 0) {
if (!persistentDef->cputune.vcpupin) {
if (VIR_ALLOC(persistentDef->cputune.vcpupin) < 0) {
virReportOOMError();
goto cleanup;
}
persistentDef->cputune.nvcpupin = 0;
}
if (virDomainVcpuPinAdd(persistentDef->cputune.vcpupin,
&persistentDef->cputune.nvcpupin,
cpumap,
maplen,
vcpu) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to update or add vcpupin xml of "
"a persistent domain"));
......
......@@ -2296,7 +2296,18 @@ xenDaemonDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
goto cleanup;
if (ret == 0) {
if (virDomainVcpuPinAdd(def, cpumap, maplen, vcpu) < 0) {
if (!def->cputune.vcpupin) {
if (VIR_ALLOC(def->cputune.vcpupin) < 0) {
virReportOOMError();
goto cleanup;
}
def->cputune.nvcpupin = 0;
}
if (virDomainVcpuPinAdd(def->cputune.vcpupin,
&def->cputune.nvcpupin,
cpumap,
maplen,
vcpu) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("failed to add vcpupin xml entry"));
return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册