qemu: Properly set //cpu/@migratable default value for running domains

Since active domains which do not have the attribute already set were
not started by libvirt that probed for CPU migratable property, we need
to check this property on reconnect and update the domain definition
accordingly.

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

Reported-by: Mark Mielke <mark.mielke@gmail.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Jiri Denemark 2020-07-15 17:54:07 +02:00
parent 4872ad27aa
commit 1031db3600

View File

@ -7772,6 +7772,52 @@ qemuProcessRefreshDisks(virQEMUDriverPtr driver,
}
static int
qemuProcessRefreshCPUMigratability(virQEMUDriverPtr driver,
virDomainObjPtr vm,
qemuDomainAsyncJob asyncJob)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainDefPtr def = vm->def;
bool migratable;
int rc;
if (def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH)
return 0;
/* If the cpu.migratable capability is present, the migratable attribute
* is set correctly. */
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_CPU_MIGRATABLE))
return 0;
if (!ARCH_IS_X86(def->os.arch))
return 0;
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
return -1;
rc = qemuMonitorGetCPUMigratable(priv->mon, &migratable);
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
return -1;
if (rc == 1)
migratable = false;
/* Libvirt 6.5.0 would set migratable='off' for running domains even though
* the actual default used by QEMU was 'on'. */
if (def->cpu->migratable == VIR_TRISTATE_SWITCH_OFF && migratable) {
VIR_DEBUG("Fixing CPU migratable attribute");
def->cpu->migratable = VIR_TRISTATE_SWITCH_ON;
}
if (def->cpu->migratable == VIR_TRISTATE_SWITCH_ABSENT)
def->cpu->migratable = virTristateSwitchFromBool(migratable);
return 0;
}
static int
qemuProcessRefreshCPU(virQEMUDriverPtr driver,
virDomainObjPtr vm)
@ -7787,6 +7833,9 @@ qemuProcessRefreshCPU(virQEMUDriverPtr driver,
if (!vm->def->cpu)
return 0;
if (qemuProcessRefreshCPUMigratability(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
return -1;
if (!(host = virQEMUDriverGetHostCPU(driver))) {
virResetLastError();
return 0;