mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +00:00
conf: Replace read access to def->maxvcpus with accessor
Finalize the refactor by adding the 'virDomainDefGetVCpusMax' getter and reusing it accross libvirt.
This commit is contained in:
parent
c970c4a5ea
commit
d1dda68777
@ -1304,6 +1304,13 @@ virDomainDefHasVcpusOffline(const virDomainDef *def)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
virDomainDefGetVcpusMax(const virDomainDef *def)
|
||||||
|
{
|
||||||
|
return def->maxvcpus;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
virDomainDiskDefPtr
|
virDomainDiskDefPtr
|
||||||
virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
|
virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
|
||||||
{
|
{
|
||||||
@ -14983,7 +14990,8 @@ virDomainDefParseXML(xmlDocPtr xml,
|
|||||||
|
|
||||||
for (i = 0; i < def->cputune.nvcpusched; i++) {
|
for (i = 0; i < def->cputune.nvcpusched; i++) {
|
||||||
if (virDomainThreadSchedParse(nodes[i],
|
if (virDomainThreadSchedParse(nodes[i],
|
||||||
0, def->maxvcpus - 1,
|
0,
|
||||||
|
virDomainDefGetVcpusMax(def) - 1,
|
||||||
"vcpus",
|
"vcpus",
|
||||||
&def->cputune.vcpusched[i]) < 0)
|
&def->cputune.vcpusched[i]) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -15060,7 +15068,7 @@ virDomainDefParseXML(xmlDocPtr xml,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (def->cpu->sockets &&
|
if (def->cpu->sockets &&
|
||||||
def->maxvcpus >
|
virDomainDefGetVcpusMax(def) >
|
||||||
def->cpu->sockets * def->cpu->cores * def->cpu->threads) {
|
def->cpu->sockets * def->cpu->cores * def->cpu->threads) {
|
||||||
virReportError(VIR_ERR_XML_DETAIL, "%s",
|
virReportError(VIR_ERR_XML_DETAIL, "%s",
|
||||||
_("Maximum CPUs greater than topology limit"));
|
_("Maximum CPUs greater than topology limit"));
|
||||||
@ -15072,14 +15080,14 @@ virDomainDefParseXML(xmlDocPtr xml,
|
|||||||
if (virDomainNumaDefCPUParseXML(def->numa, ctxt) < 0)
|
if (virDomainNumaDefCPUParseXML(def->numa, ctxt) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virDomainNumaGetCPUCountTotal(def->numa) > def->maxvcpus) {
|
if (virDomainNumaGetCPUCountTotal(def->numa) > virDomainDefGetVcpusMax(def)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Number of CPUs in <numa> exceeds the"
|
_("Number of CPUs in <numa> exceeds the"
|
||||||
" <vcpu> count"));
|
" <vcpu> count"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virDomainNumaGetMaxCPUID(def->numa) >= def->maxvcpus) {
|
if (virDomainNumaGetMaxCPUID(def->numa) >= virDomainDefGetVcpusMax(def)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("CPU IDs in <numa> exceed the <vcpu> count"));
|
_("CPU IDs in <numa> exceed the <vcpu> count"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -17556,10 +17564,10 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
|
|||||||
dst->vcpus, src->vcpus);
|
dst->vcpus, src->vcpus);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (src->maxvcpus != dst->maxvcpus) {
|
if (virDomainDefGetVcpusMax(src) != virDomainDefGetVcpusMax(dst)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("Target domain vCPU max %d does not match source %d"),
|
_("Target domain vCPU max %d does not match source %d"),
|
||||||
dst->maxvcpus, src->maxvcpus);
|
virDomainDefGetVcpusMax(dst), virDomainDefGetVcpusMax(src));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21530,7 +21538,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
|
|||||||
}
|
}
|
||||||
if (virDomainDefHasVcpusOffline(def))
|
if (virDomainDefHasVcpusOffline(def))
|
||||||
virBufferAsprintf(buf, " current='%u'", def->vcpus);
|
virBufferAsprintf(buf, " current='%u'", def->vcpus);
|
||||||
virBufferAsprintf(buf, ">%u</vcpu>\n", def->maxvcpus);
|
virBufferAsprintf(buf, ">%u</vcpu>\n", virDomainDefGetVcpusMax(def));
|
||||||
|
|
||||||
if (def->niothreadids > 0) {
|
if (def->niothreadids > 0) {
|
||||||
virBufferAsprintf(buf, "<iothreads>%u</iothreads>\n",
|
virBufferAsprintf(buf, "<iothreads>%u</iothreads>\n",
|
||||||
|
@ -2345,6 +2345,7 @@ struct _virDomainDef {
|
|||||||
|
|
||||||
int virDomainDefSetVcpusMax(virDomainDefPtr def, unsigned int vcpus);
|
int virDomainDefSetVcpusMax(virDomainDefPtr def, unsigned int vcpus);
|
||||||
bool virDomainDefHasVcpusOffline(const virDomainDef *def);
|
bool virDomainDefHasVcpusOffline(const virDomainDef *def);
|
||||||
|
unsigned int virDomainDefGetVcpusMax(const virDomainDef *def);
|
||||||
|
|
||||||
unsigned long long virDomainDefGetMemoryInitial(const virDomainDef *def);
|
unsigned long long virDomainDefGetMemoryInitial(const virDomainDef *def);
|
||||||
void virDomainDefSetMemoryTotal(virDomainDefPtr def, unsigned long long size);
|
void virDomainDefSetMemoryTotal(virDomainDefPtr def, unsigned long long size);
|
||||||
|
@ -217,6 +217,7 @@ virDomainDefGetDefaultEmulator;
|
|||||||
virDomainDefGetMemoryActual;
|
virDomainDefGetMemoryActual;
|
||||||
virDomainDefGetMemoryInitial;
|
virDomainDefGetMemoryInitial;
|
||||||
virDomainDefGetSecurityLabelDef;
|
virDomainDefGetSecurityLabelDef;
|
||||||
|
virDomainDefGetVcpusMax;
|
||||||
virDomainDefHasDeviceAddress;
|
virDomainDefHasDeviceAddress;
|
||||||
virDomainDefHasMemoryHotplug;
|
virDomainDefHasMemoryHotplug;
|
||||||
virDomainDefHasVcpusOffline;
|
virDomainDefHasVcpusOffline;
|
||||||
|
@ -643,8 +643,8 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
|
|||||||
else
|
else
|
||||||
libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_PV);
|
libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_PV);
|
||||||
|
|
||||||
b_info->max_vcpus = def->maxvcpus;
|
b_info->max_vcpus = virDomainDefGetVcpusMax(def);
|
||||||
if (libxl_cpu_bitmap_alloc(ctx, &b_info->avail_vcpus, def->maxvcpus))
|
if (libxl_cpu_bitmap_alloc(ctx, &b_info->avail_vcpus, b_info->max_vcpus))
|
||||||
return -1;
|
return -1;
|
||||||
libxl_bitmap_set_none(&b_info->avail_vcpus);
|
libxl_bitmap_set_none(&b_info->avail_vcpus);
|
||||||
for (i = 0; i < def->vcpus; i++)
|
for (i = 0; i < def->vcpus; i++)
|
||||||
|
@ -2159,8 +2159,8 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) && vm->def->maxvcpus < max)
|
if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) && virDomainDefGetVcpusMax(vm->def) < max)
|
||||||
max = vm->def->maxvcpus;
|
max = virDomainDefGetVcpusMax(vm->def);
|
||||||
|
|
||||||
if (nvcpus > max) {
|
if (nvcpus > max) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
@ -2297,7 +2297,10 @@ libxlDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
|
|||||||
def = vm->newDef ? vm->newDef : vm->def;
|
def = vm->newDef ? vm->newDef : vm->def;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus;
|
if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
|
||||||
|
ret = virDomainDefGetVcpusMax(def);
|
||||||
|
else
|
||||||
|
ret = def->vcpus;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (vm)
|
if (vm)
|
||||||
@ -4699,7 +4702,7 @@ libxlDomainGetPerCPUStats(libxlDriverPrivatePtr driver,
|
|||||||
if (nparams == 0 && ncpus != 0)
|
if (nparams == 0 && ncpus != 0)
|
||||||
return LIBXL_NB_TOTAL_CPU_STAT_PARAM;
|
return LIBXL_NB_TOTAL_CPU_STAT_PARAM;
|
||||||
else if (nparams == 0)
|
else if (nparams == 0)
|
||||||
return vm->def->maxvcpus;
|
return virDomainDefGetVcpusMax(vm->def);
|
||||||
|
|
||||||
cfg = libxlDriverConfigGet(driver);
|
cfg = libxlDriverConfigGet(driver);
|
||||||
if ((vcpuinfo = libxl_list_vcpu(cfg->ctx, vm->def->id, &maxcpu,
|
if ((vcpuinfo = libxl_list_vcpu(cfg->ctx, vm->def->id, &maxcpu,
|
||||||
|
@ -1035,8 +1035,8 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla
|
|||||||
_("current vcpu count must equal maximum"));
|
_("current vcpu count must equal maximum"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (vm->def->maxvcpus > 0) {
|
if (virDomainDefGetVcpusMax(vm->def)) {
|
||||||
if (openvzDomainSetVcpusInternal(vm, vm->def->maxvcpus) < 0) {
|
if (openvzDomainSetVcpusInternal(vm, virDomainDefGetVcpusMax(vm->def)) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Could not set number of vCPUs"));
|
_("Could not set number of vCPUs"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1133,8 +1133,8 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
|
|||||||
vm->def->id = vm->pid;
|
vm->def->id = vm->pid;
|
||||||
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
|
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
|
||||||
|
|
||||||
if (vm->def->maxvcpus > 0) {
|
if (virDomainDefGetVcpusMax(vm->def) > 0) {
|
||||||
if (openvzDomainSetVcpusInternal(vm, vm->def->maxvcpus) < 0) {
|
if (openvzDomainSetVcpusInternal(vm, virDomainDefGetVcpusMax(vm->def)) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Could not set number of vCPUs"));
|
_("Could not set number of vCPUs"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -7963,7 +7963,7 @@ qemuBuildSmpArgStr(const virDomainDef *def,
|
|||||||
|
|
||||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SMP_TOPOLOGY)) {
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SMP_TOPOLOGY)) {
|
||||||
if (virDomainDefHasVcpusOffline(def))
|
if (virDomainDefHasVcpusOffline(def))
|
||||||
virBufferAsprintf(&buf, ",maxcpus=%u", def->maxvcpus);
|
virBufferAsprintf(&buf, ",maxcpus=%u", virDomainDefGetVcpusMax(def));
|
||||||
/* sockets, cores, and threads are either all zero
|
/* sockets, cores, and threads are either all zero
|
||||||
* or all non-zero, thus checking one of them is enough */
|
* or all non-zero, thus checking one of them is enough */
|
||||||
if (def->cpu && def->cpu->sockets) {
|
if (def->cpu && def->cpu->sockets) {
|
||||||
@ -7971,7 +7971,7 @@ qemuBuildSmpArgStr(const virDomainDef *def,
|
|||||||
virBufferAsprintf(&buf, ",cores=%u", def->cpu->cores);
|
virBufferAsprintf(&buf, ",cores=%u", def->cpu->cores);
|
||||||
virBufferAsprintf(&buf, ",threads=%u", def->cpu->threads);
|
virBufferAsprintf(&buf, ",threads=%u", def->cpu->threads);
|
||||||
} else {
|
} else {
|
||||||
virBufferAsprintf(&buf, ",sockets=%u", def->maxvcpus);
|
virBufferAsprintf(&buf, ",sockets=%u", virDomainDefGetVcpusMax(def));
|
||||||
virBufferAsprintf(&buf, ",cores=%u", 1);
|
virBufferAsprintf(&buf, ",cores=%u", 1);
|
||||||
virBufferAsprintf(&buf, ",threads=%u", 1);
|
virBufferAsprintf(&buf, ",threads=%u", 1);
|
||||||
}
|
}
|
||||||
|
@ -4911,10 +4911,10 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (def)
|
if (def)
|
||||||
maxvcpus = def->maxvcpus;
|
maxvcpus = virDomainDefGetVcpusMax(def);
|
||||||
if (persistentDef) {
|
if (persistentDef) {
|
||||||
if (!maxvcpus || maxvcpus > persistentDef->maxvcpus)
|
if (!maxvcpus || maxvcpus > virDomainDefGetVcpusMax(persistentDef))
|
||||||
maxvcpus = persistentDef->maxvcpus;
|
maxvcpus = virDomainDefGetVcpusMax(persistentDef);
|
||||||
}
|
}
|
||||||
if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) && nvcpus > maxvcpus) {
|
if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) && nvcpus > maxvcpus) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
@ -5557,7 +5557,7 @@ qemuDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
|
if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
|
||||||
ret = def->maxvcpus;
|
ret = virDomainDefGetVcpusMax(def);
|
||||||
else
|
else
|
||||||
ret = def->vcpus;
|
ret = def->vcpus;
|
||||||
}
|
}
|
||||||
@ -19078,7 +19078,7 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
|
|||||||
&record->nparams,
|
&record->nparams,
|
||||||
maxparams,
|
maxparams,
|
||||||
"vcpu.maximum",
|
"vcpu.maximum",
|
||||||
(unsigned) dom->def->maxvcpus) < 0)
|
virDomainDefGetVcpusMax(dom->def)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(cpuinfo, dom->def->vcpus) < 0)
|
if (VIR_ALLOC_N(cpuinfo, dom->def->vcpus) < 0)
|
||||||
|
@ -3869,7 +3869,7 @@ qemuValidateCpuMax(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
|
|||||||
if (!maxCpus)
|
if (!maxCpus)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (def->maxvcpus > maxCpus) {
|
if (virDomainDefGetVcpusMax(def) > maxCpus) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
"%s", _("Maximum CPUs greater than specified machine type limit"));
|
"%s", _("Maximum CPUs greater than specified machine type limit"));
|
||||||
return false;
|
return false;
|
||||||
|
@ -2313,7 +2313,10 @@ testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
|
|||||||
if (!(def = virDomainObjGetOneDef(vm, flags)))
|
if (!(def = virDomainObjGetOneDef(vm, flags)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus;
|
if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
|
||||||
|
ret = virDomainDefGetVcpusMax(def);
|
||||||
|
else
|
||||||
|
ret = def->vcpus;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
@ -2356,19 +2359,19 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
|
|||||||
if (virDomainObjGetDefs(privdom, flags, &def, &persistentDef) < 0)
|
if (virDomainObjGetDefs(privdom, flags, &def, &persistentDef) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (def && def->maxvcpus < nrCpus) {
|
if (def && virDomainDefGetVcpusMax(def) < nrCpus) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
_("requested cpu amount exceeds maximum (%d > %d)"),
|
_("requested cpu amount exceeds maximum (%d > %d)"),
|
||||||
nrCpus, def->maxvcpus);
|
nrCpus, virDomainDefGetVcpusMax(def));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (persistentDef &&
|
if (persistentDef &&
|
||||||
!(flags & VIR_DOMAIN_VCPU_MAXIMUM) &&
|
!(flags & VIR_DOMAIN_VCPU_MAXIMUM) &&
|
||||||
persistentDef->maxvcpus < nrCpus) {
|
virDomainDefGetVcpusMax(persistentDef) < nrCpus) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
_("requested cpu amount exceeds maximum (%d > %d)"),
|
_("requested cpu amount exceeds maximum (%d > %d)"),
|
||||||
nrCpus, persistentDef->maxvcpus);
|
nrCpus, virDomainDefGetVcpusMax(persistentDef));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1899,11 +1899,11 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags
|
|||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("current vcpu count must equal maximum"));
|
_("current vcpu count must equal maximum"));
|
||||||
}
|
}
|
||||||
rc = gVBoxAPI.UIMachine.SetCPUCount(machine, def->maxvcpus);
|
rc = gVBoxAPI.UIMachine.SetCPUCount(machine, virDomainDefGetVcpusMax(def));
|
||||||
if (NS_FAILED(rc)) {
|
if (NS_FAILED(rc)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("could not set the number of virtual CPUs to: %u, rc=%08x"),
|
_("could not set the number of virtual CPUs to: %u, rc=%08x"),
|
||||||
def->maxvcpus, (unsigned)rc);
|
virDomainDefGetVcpusMax(def), (unsigned)rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = gVBoxAPI.UIMachine.SetCPUProperty(machine, CPUPropertyType_PAE,
|
rc = gVBoxAPI.UIMachine.SetCPUProperty(machine, CPUPropertyType_PAE,
|
||||||
|
@ -3071,6 +3071,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe
|
|||||||
bool scsi_present[4] = { false, false, false, false };
|
bool scsi_present[4] = { false, false, false, false };
|
||||||
int scsi_virtualDev[4] = { -1, -1, -1, -1 };
|
int scsi_virtualDev[4] = { -1, -1, -1, -1 };
|
||||||
bool floppy_present[2] = { false, false };
|
bool floppy_present[2] = { false, false };
|
||||||
|
unsigned int maxvcpus;
|
||||||
|
|
||||||
if (ctx->formatFileName == NULL) {
|
if (ctx->formatFileName == NULL) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -3186,15 +3187,16 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe
|
|||||||
"'current'"));
|
"'current'"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (def->maxvcpus <= 0 || (def->maxvcpus % 2 != 0 && def->maxvcpus != 1)) {
|
maxvcpus = virDomainDefGetVcpusMax(def);
|
||||||
|
if (maxvcpus == 0 || (maxvcpus % 2 != 0 && maxvcpus != 1)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Expecting domain XML entry 'vcpu' to be an unsigned "
|
_("Expecting domain XML entry 'vcpu' to be 1 or a "
|
||||||
"integer (1 or a multiple of 2) but found %d"),
|
"multiple of 2 but found %d"),
|
||||||
def->maxvcpus);
|
maxvcpus);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virBufferAsprintf(&buffer, "numvcpus = \"%d\"\n", def->maxvcpus);
|
virBufferAsprintf(&buffer, "numvcpus = \"%d\"\n", maxvcpus);
|
||||||
|
|
||||||
/* def:cpumask -> vmx:sched.cpu.affinity */
|
/* def:cpumask -> vmx:sched.cpu.affinity */
|
||||||
if (def->cpumask && virBitmapSize(def->cpumask) > 0) {
|
if (def->cpumask && virBitmapSize(def->cpumask) > 0) {
|
||||||
@ -3207,11 +3209,11 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe
|
|||||||
while ((bit = virBitmapNextSetBit(def->cpumask, bit)) >= 0)
|
while ((bit = virBitmapNextSetBit(def->cpumask, bit)) >= 0)
|
||||||
++sched_cpu_affinity_length;
|
++sched_cpu_affinity_length;
|
||||||
|
|
||||||
if (sched_cpu_affinity_length < def->maxvcpus) {
|
if (sched_cpu_affinity_length < maxvcpus) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Expecting domain XML attribute 'cpuset' of entry "
|
_("Expecting domain XML attribute 'cpuset' of entry "
|
||||||
"'vcpu' to contain at least %d CPU(s)"),
|
"'vcpu' to contain at least %d CPU(s)"),
|
||||||
def->maxvcpus);
|
maxvcpus);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1372,7 +1372,7 @@ vzDomainGetVcpusFlags(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
|
if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
|
||||||
ret = privdom->def->maxvcpus;
|
ret = virDomainDefGetVcpusMax(privdom->def);
|
||||||
else
|
else
|
||||||
ret = privdom->def->vcpus;
|
ret = privdom->def->vcpus;
|
||||||
|
|
||||||
|
@ -695,7 +695,8 @@ xenXMDomainSetVcpusFlags(virConnectPtr conn,
|
|||||||
/* Can't specify a current larger than stored maximum; but
|
/* Can't specify a current larger than stored maximum; but
|
||||||
* reducing maximum can silently reduce current. */
|
* reducing maximum can silently reduce current. */
|
||||||
if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM))
|
if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM))
|
||||||
max = entry->def->maxvcpus;
|
max = virDomainDefGetVcpusMax(entry->def);
|
||||||
|
|
||||||
if (vcpus > max) {
|
if (vcpus > max) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
_("requested vcpus is greater than max allowable"
|
_("requested vcpus is greater than max allowable"
|
||||||
@ -760,8 +761,10 @@ xenXMDomainGetVcpusFlags(virConnectPtr conn,
|
|||||||
if (!(entry = virHashLookup(priv->configCache, filename)))
|
if (!(entry = virHashLookup(priv->configCache, filename)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = ((flags & VIR_DOMAIN_VCPU_MAXIMUM) ? entry->def->maxvcpus
|
if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
|
||||||
: entry->def->vcpus);
|
ret = virDomainDefGetVcpusMax(entry->def);
|
||||||
|
else
|
||||||
|
ret = entry->def->vcpus;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
xenUnifiedUnlock(priv);
|
xenUnifiedUnlock(priv);
|
||||||
|
@ -504,8 +504,8 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def,
|
|||||||
else
|
else
|
||||||
(*record)->memory_dynamic_max = (*record)->memory_static_max;
|
(*record)->memory_dynamic_max = (*record)->memory_static_max;
|
||||||
|
|
||||||
if (def->maxvcpus) {
|
if (virDomainDefGetVcpusMax(def) > 0) {
|
||||||
(*record)->vcpus_max = (int64_t) def->maxvcpus;
|
(*record)->vcpus_max = (int64_t) virDomainDefGetVcpusMax(def);
|
||||||
(*record)->vcpus_at_startup = (int64_t) def->vcpus;
|
(*record)->vcpus_at_startup = (int64_t) def->vcpus;
|
||||||
}
|
}
|
||||||
if (def->onPoweroff)
|
if (def->onPoweroff)
|
||||||
|
@ -508,7 +508,7 @@ xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def)
|
|||||||
if (xenConfigGetULong(conf, "vcpu_avail", &count, -1) < 0)
|
if (xenConfigGetULong(conf, "vcpu_avail", &count, -1) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
def->vcpus = MIN(count_one_bits_l(count), def->maxvcpus);
|
def->vcpus = MIN(count_one_bits_l(count), virDomainDefGetVcpusMax(def));
|
||||||
if (xenConfigGetString(conf, "cpus", &str, NULL) < 0)
|
if (xenConfigGetString(conf, "cpus", &str, NULL) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -1528,7 +1528,7 @@ xenFormatCPUAllocation(virConfPtr conf, virDomainDefPtr def)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *cpus = NULL;
|
char *cpus = NULL;
|
||||||
|
|
||||||
if (xenConfigSetInt(conf, "vcpus", def->maxvcpus) < 0)
|
if (xenConfigSetInt(conf, "vcpus", virDomainDefGetVcpusMax(def)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
|
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
|
||||||
|
@ -1176,8 +1176,8 @@ xenParseSxpr(const struct sexpr *root,
|
|||||||
if (virDomainDefSetVcpusMax(def, sexpr_int(root, "domain/vcpus")) < 0)
|
if (virDomainDefSetVcpusMax(def, sexpr_int(root, "domain/vcpus")) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
def->vcpus = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail"));
|
def->vcpus = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail"));
|
||||||
if (!def->vcpus || def->maxvcpus < def->vcpus)
|
if (!def->vcpus || virDomainDefGetVcpusMax(def) < def->vcpus)
|
||||||
def->vcpus = def->maxvcpus;
|
def->vcpus = virDomainDefGetVcpusMax(def);
|
||||||
|
|
||||||
tmp = sexpr_node(root, "domain/on_poweroff");
|
tmp = sexpr_node(root, "domain/on_poweroff");
|
||||||
if (tmp != NULL) {
|
if (tmp != NULL) {
|
||||||
@ -2237,7 +2237,7 @@ xenFormatSxpr(virConnectPtr conn,
|
|||||||
virBufferAsprintf(&buf, "(memory %llu)(maxmem %llu)",
|
virBufferAsprintf(&buf, "(memory %llu)(maxmem %llu)",
|
||||||
VIR_DIV_UP(def->mem.cur_balloon, 1024),
|
VIR_DIV_UP(def->mem.cur_balloon, 1024),
|
||||||
VIR_DIV_UP(virDomainDefGetMemoryActual(def), 1024));
|
VIR_DIV_UP(virDomainDefGetMemoryActual(def), 1024));
|
||||||
virBufferAsprintf(&buf, "(vcpus %u)", def->maxvcpus);
|
virBufferAsprintf(&buf, "(vcpus %u)", virDomainDefGetVcpusMax(def));
|
||||||
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
|
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
|
||||||
either 32, or 64 on a platform where long is big enough. */
|
either 32, or 64 on a platform where long is big enough. */
|
||||||
if (virDomainDefHasVcpusOffline(def))
|
if (virDomainDefHasVcpusOffline(def))
|
||||||
@ -2321,7 +2321,7 @@ xenFormatSxpr(virConnectPtr conn,
|
|||||||
else
|
else
|
||||||
virBufferEscapeSexpr(&buf, "(kernel '%s')", def->os.loader->path);
|
virBufferEscapeSexpr(&buf, "(kernel '%s')", def->os.loader->path);
|
||||||
|
|
||||||
virBufferAsprintf(&buf, "(vcpus %u)", def->maxvcpus);
|
virBufferAsprintf(&buf, "(vcpus %u)", virDomainDefGetVcpusMax(def));
|
||||||
if (virDomainDefHasVcpusOffline(def))
|
if (virDomainDefHasVcpusOffline(def))
|
||||||
virBufferAsprintf(&buf, "(vcpu_avail %lu)",
|
virBufferAsprintf(&buf, "(vcpu_avail %lu)",
|
||||||
(1UL << def->vcpus) - 1);
|
(1UL << def->vcpus) - 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user