mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 19:02:25 +00:00
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 <jdenemar@redhat.com>
This commit is contained in:
parent
73078906f3
commit
25ba9c31f5
@ -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:
|
||||
|
@ -400,9 +400,6 @@ typedef virQEMUCapsCache *virQEMUCapsCachePtr;
|
||||
|
||||
virQEMUCapsPtr virQEMUCapsNew(void);
|
||||
|
||||
int virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
|
||||
qemuMonitorPtr mon);
|
||||
|
||||
int virQEMUCapsProbeQMP(virQEMUCapsPtr qemuCaps,
|
||||
qemuMonitorPtr mon);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user