qemu: Use correct host model for updating guest cpu

When a user requested a domain XML description with
VIR_DOMAIN_XML_UPDATE_CPU flag, libvirt would use the host CPU
definition from host capabilities rather than the one which will
actually be used once the domain is started.

https://bugzilla.redhat.com/show_bug.cgi?id=1481309

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2017-06-30 17:05:22 +02:00
parent 43a90eb7e8
commit 7e874326a3

View File

@ -4561,6 +4561,7 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver,
int ret = -1;
virDomainDefPtr copy = NULL;
virCapsPtr caps = NULL;
virQEMUCapsPtr qemuCaps = NULL;
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
@ -4579,7 +4580,14 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver,
def->cpu &&
(def->cpu->mode != VIR_CPU_MODE_CUSTOM ||
def->cpu->model)) {
if (virCPUUpdate(def->os.arch, def->cpu, caps->host.cpu) < 0)
if (!(qemuCaps = virQEMUCapsCacheLookupCopy(driver->qemuCapsCache,
def->emulator,
def->os.machine)))
goto cleanup;
if (virCPUUpdate(def->os.arch, def->cpu,
virQEMUCapsGetHostModel(qemuCaps, def->virtType,
VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE)) < 0)
goto cleanup;
}
@ -4697,6 +4705,7 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver,
cleanup:
virDomainDefFree(copy);
virObjectUnref(caps);
virObjectUnref(qemuCaps);
return ret;
}