From cd51b90fbf593090b2c82d767f874aae9aebb74e Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Fri, 25 Nov 2016 20:03:12 +0100 Subject: [PATCH] qemu: Don't return unusable virttype in domain capabilities If a user asked for a KVM domain capabilities when KVM is not available, we would happily return data we got when probing through TCG and pretended they were relevant for KVM. Let's just report KVM is not supported to avoid confusion. Signed-off-by: Jiri Denemark --- src/qemu/qemu_driver.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 26ebf763f0..6a26549237 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -18719,6 +18719,7 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn, virQEMUDriverPtr driver = conn->privateData; virQEMUCapsPtr qemuCaps = NULL; int virttype = VIR_DOMAIN_VIRT_NONE; + virDomainVirtType capsType; virDomainCapsPtr domCaps = NULL; int arch = virArchFromHost(); /* virArch */ virQEMUDriverConfigPtr cfg = NULL; @@ -18797,11 +18798,19 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn, machine = virQEMUCapsGetDefaultMachine(qemuCaps); } - if (virttype == VIR_DOMAIN_VIRT_NONE) { - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) - virttype = VIR_DOMAIN_VIRT_KVM; - else - virttype = VIR_DOMAIN_VIRT_QEMU; + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) + capsType = VIR_DOMAIN_VIRT_KVM; + else + capsType = VIR_DOMAIN_VIRT_QEMU; + + if (virttype == VIR_DOMAIN_VIRT_NONE) + virttype = capsType; + + if (virttype == VIR_DOMAIN_VIRT_KVM && capsType == VIR_DOMAIN_VIRT_QEMU) { + virReportError(VIR_ERR_INVALID_ARG, + _("KVM is not supported by '%s' on this host"), + emulatorbin); + goto cleanup; } if (!(domCaps = virDomainCapsNew(emulatorbin, machine, arch, virttype)))