qemu: Invert condition nesting in qemuDomainDefValidate()

While at the moment we're only performing a single check that is
connected to vCPU hotplugging, we're going to introduce a second
one soon. Move the topology check underneath the capability check
to make that easier; since, after this change, the 'topologycpus'
variable doesn't need to have function scope, we move its
declaration to the inner scope as well.

The comments around the check are modified in order to explain
the different QEMU versions involved.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
Andrea Bolognani 2017-12-14 15:29:28 +01:00
parent bbf6573e94
commit 54acfac4a5
1 changed files with 11 additions and 6 deletions

View File

@ -3299,7 +3299,6 @@ qemuDomainDefValidate(const virDomainDef *def,
{ {
virQEMUDriverPtr driver = opaque; virQEMUDriverPtr driver = opaque;
virQEMUCapsPtr qemuCaps = NULL; virQEMUCapsPtr qemuCaps = NULL;
unsigned int topologycpus;
int ret = -1; int ret = -1;
if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache,
@ -3359,11 +3358,17 @@ qemuDomainDefValidate(const virDomainDef *def,
} }
} }
/* qemu as of 2.5.0 rejects SMP topologies that don't match the cpu count */ /* QEMU 2.7 (detected via the availability of query-hotpluggable-cpus)
if (virDomainDefGetVcpusTopology(def, &topologycpus) == 0 && * enforces stricter rules than previous versions when it comes to guest
topologycpus != virDomainDefGetVcpusMax(def)) { * CPU topology. Verify known constraints are respected */
/* 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)) { unsigned int topologycpus;
/* Starting from QEMU 2.5, max vCPU count and overall vCPU topology
* must agree. We only actually enforce this with QEMU 2.7+, due
* to the capability check above */
if (virDomainDefGetVcpusTopology(def, &topologycpus) == 0 &&
topologycpus != virDomainDefGetVcpusMax(def)) {
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;