qemu: honour parseOpaque instead of refetching caps

The use of the parseOpaque parameter was mistakenly removed in

  commit 4a4132b462
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Tue Dec 3 10:49:49 2019 +0000

    conf: don't use passed in caps in post parse method

causing the method to re-fetch qemuCaps that were already just
fetched and put into parseOpaque.

This is inefficient when parsing incoming XML, but for live
XML this is more serious as it means we use the capabilities
for the current QEMU binary on disk, rather than the running
QEMU.

That commit, however, did have a useful side effect of fixing
a crasher bug in the qemu post parse callback introduced by

  commit 5e939cea89
  Author: Jiri Denemark <jdenemar@redhat.com>
  Date:   Thu Sep 26 18:42:02 2019 +0200

    qemu: Store default CPU in domain XML

The qemuDomainDefSetDefaultCPU() method in that patch did not
allow for the possibility that qemuCaps would be NULL and thus
resulted in a SEGV.

This shows a risk in letting each check in the post parse
callback look for qemuCaps == NULL. The safer option is to
check once upfront and immediately stop (postpone) further
validation.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2019-12-10 11:35:43 +00:00
parent 87a8b81d40
commit 8d157c13cc

View File

@ -4853,16 +4853,18 @@ static int
qemuDomainDefPostParse(virDomainDefPtr def, qemuDomainDefPostParse(virDomainDefPtr def,
unsigned int parseFlags, unsigned int parseFlags,
void *opaque, void *opaque,
void *parseOpaque G_GNUC_UNUSED) void *parseOpaque)
{ {
virQEMUDriverPtr driver = opaque; virQEMUDriverPtr driver = opaque;
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
g_autoptr(virQEMUCaps) qemuCaps = NULL; virQEMUCapsPtr qemuCaps = parseOpaque;
if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache, /* Note that qemuCaps may be NULL when this function is called. This
def->emulator))) { * function shall not fail in that case. It will be re-run on VM startup
* with the capabilities populated.
*/
if (!qemuCaps)
return 1; return 1;
}
if (def->os.bootloader || def->os.bootloaderArgs) { if (def->os.bootloader || def->os.bootloaderArgs) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",