From: Jiri Denemark Date: Fri, 10 Jun 2016 15:16:21 +0000 (+0200) Subject: qemu: Enable KVM when probing capabilities X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=25ba9c31f50fd021afb3565ac7dd8062dd689ceb;p=libvirt.git qemu: Enable KVM when probing capabilities CPU related capabilities may differ depending on accelerator used when probing. Let's use KVM if available when probing QEMU and fall back to TCG. The created capabilities already contain all we need to distinguish whether KVM or TCG was used: - KVM was used when probing capabilities: QEMU_CAPS_KVM is set QEMU_CAPS_ENABLE_KVM is not set - TCG was used and QEMU supports KVM, but it failed (e.g., missing kernel module or wrong /dev/kvm permissions) QEMU_CAPS_KVM is not set QEMU_CAPS_ENABLE_KVM is set - KVM was not used and QEMU does not support it QEMU_CAPS_KVM is not set QEMU_CAPS_ENABLE_KVM is not set Signed-off-by: Jiri Denemark --- diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f224bad632..3d62fc520f 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4028,6 +4028,25 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps, } +int +virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED, + qemuMonitorPtr mon) +{ + int ret = -1; + + if (qemuMonitorSetCapabilities(mon) < 0) { + VIR_DEBUG("Failed to set monitor capabilities %s", + virGetLastErrorMessage()); + ret = 0; + goto cleanup; + } + + ret = 0; + cleanup: + return ret; +} + + typedef struct _virQEMUCapsInitQMPCommand virQEMUCapsInitQMPCommand; typedef virQEMUCapsInitQMPCommand *virQEMUCapsInitQMPCommandPtr; struct _virQEMUCapsInitQMPCommand { @@ -4151,13 +4170,21 @@ virQEMUCapsInitQMPCommandNew(char *binary, * 1 when probing QEMU failed */ static int -virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPCommandPtr cmd) +virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPCommandPtr cmd, + bool forceTCG) { virDomainXMLOptionPtr xmlopt = NULL; + const char *machine; int status = 0; int ret = -1; - VIR_DEBUG("Try to probe capabilities of '%s' via QMP", cmd->binary); + if (forceTCG) + machine = "none,accel=tcg"; + else + machine = "none,accel=kvm:tcg"; + + VIR_DEBUG("Try to probe capabilities of '%s' via QMP, machine %s", + cmd->binary, machine); /* * We explicitly need to use -daemonize here, rather than @@ -4171,7 +4198,7 @@ virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPCommandPtr cmd) "-no-user-config", "-nodefaults", "-nographic", - "-machine", "none", + "-machine", machine, "-qmp", cmd->monarg, "-pidfile", cmd->pidfile, "-daemonize", @@ -4240,7 +4267,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, runUid, runGid, qmperr))) goto cleanup; - if ((rc = virQEMUCapsInitQMPCommandRun(cmd)) != 0) { + if ((rc = virQEMUCapsInitQMPCommandRun(cmd, false)) != 0) { if (rc == 1) ret = 0; goto cleanup; @@ -4249,6 +4276,18 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, if (virQEMUCapsInitQMPMonitor(qemuCaps, cmd->mon) < 0) goto cleanup; + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) { + virQEMUCapsInitQMPCommandAbort(cmd); + if ((rc = virQEMUCapsInitQMPCommandRun(cmd, true)) != 0) { + if (rc == 1) + ret = 0; + goto cleanup; + } + + if (virQEMUCapsInitQMPMonitorTCG(qemuCaps, cmd->mon) < 0) + goto cleanup; + } + ret = 0; cleanup: diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 5255815876..cfd00663bf 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -400,9 +400,6 @@ typedef virQEMUCapsCache *virQEMUCapsCachePtr; virQEMUCapsPtr virQEMUCapsNew(void); -int virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps, - qemuMonitorPtr mon); - int virQEMUCapsProbeQMP(virQEMUCapsPtr qemuCaps, qemuMonitorPtr mon); diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index f8ee47efdf..38b971e0e0 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -57,6 +57,14 @@ char *virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps, time_t selfCTime, unsigned long selfVersion); +int +virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps, + qemuMonitorPtr mon); + +int +virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps, + qemuMonitorPtr mon); + void virQEMUCapsSetArch(virQEMUCapsPtr qemuCaps, virArch arch); diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c index 10cfa43768..fe41fc496b 100644 --- a/tests/qemucapabilitiestest.c +++ b/tests/qemucapabilitiestest.c @@ -61,6 +61,11 @@ testQemuCaps(const void *opaque) qemuMonitorTestGetMonitor(mon)) < 0) goto cleanup; + if (virQEMUCapsGet(capsActual, QEMU_CAPS_KVM) && + virQEMUCapsInitQMPMonitorTCG(capsActual, + qemuMonitorTestGetMonitor(mon)) < 0) + goto cleanup; + if (!(actual = virQEMUCapsFormatCache(capsActual, 0, 0))) goto cleanup;