qemu: Reuse virDomainDeGetVcpusTopology to calculate total vcpu count

Rather than multiplying sockets, cores, and threads use the new helper
for getting the vcpu count resulting from the topology.
This commit is contained in:
Peter Krempa 2016-10-10 15:57:54 +02:00
parent da0d82d15f
commit 043ba4a40a
2 changed files with 14 additions and 18 deletions

View File

@ -2401,7 +2401,7 @@ qemuDomainDefValidate(const virDomainDef *def,
{ {
virQEMUDriverPtr driver = opaque; virQEMUDriverPtr driver = opaque;
virQEMUCapsPtr qemuCaps = NULL; virQEMUCapsPtr qemuCaps = NULL;
size_t topologycpus; unsigned int topologycpus;
int ret = -1; int ret = -1;
if (!(qemuCaps = virQEMUCapsCacheLookup(caps, if (!(qemuCaps = virQEMUCapsCacheLookup(caps,
@ -2443,15 +2443,13 @@ qemuDomainDefValidate(const virDomainDef *def,
} }
/* qemu as of 2.5.0 rejects SMP topologies that don't match the cpu count */ /* qemu as of 2.5.0 rejects SMP topologies that don't match the cpu count */
if (def->cpu && def->cpu->sockets) { if (virDomainDefGetVcpusTopology(def, &topologycpus) == 0 &&
topologycpus = def->cpu->sockets * def->cpu->cores * def->cpu->threads; topologycpus != virDomainDefGetVcpusMax(def)) {
if (topologycpus != virDomainDefGetVcpusMax(def)) { /* presence of query-hotpluggable-cpus should be a good enough witness */
/* presence of query-hotpluggable-cpus should be a good enough witness */ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS)) {
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("CPU topology doesn't match maximum vcpu count"));
_("CPU topology doesn't match maximum vcpu count")); goto cleanup;
goto cleanup;
}
} }
} }

View File

@ -4718,6 +4718,7 @@ qemuDomainSetVcpusMax(virQEMUDriverPtr driver,
unsigned int nvcpus) unsigned int nvcpus)
{ {
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
unsigned int topologycpus;
int ret = -1; int ret = -1;
if (def) { if (def) {
@ -4733,16 +4734,13 @@ qemuDomainSetVcpusMax(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
if (persistentDef->cpu && persistentDef->cpu->sockets) { if (virDomainDefGetVcpusTopology(persistentDef, &topologycpus) == 0 &&
nvcpus != topologycpus) {
/* allow setting a valid vcpu count for the topology so an invalid /* allow setting a valid vcpu count for the topology so an invalid
* setting may be corrected via this API */ * setting may be corrected via this API */
if (nvcpus != persistentDef->cpu->sockets * virReportError(VIR_ERR_INVALID_ARG, "%s",
persistentDef->cpu->cores * _("CPU topology doesn't match the desired vcpu count"));
persistentDef->cpu->threads) { goto cleanup;
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("CPU topology doesn't match the desired vcpu count"));
goto cleanup;
}
} }
/* ordering information may become invalid, thus clear it */ /* ordering information may become invalid, thus clear it */