提交 56bd7edc 编写于 作者: J Jiri Denemark

qemu: Pass migratable host CPU model to virCPUUpdate

We already know from QEMU which CPU features will block migration. Let's
use this information to make a migratable copy of the host CPU model and
use it for updating guest CPU specification. This will allow us to drop
feature filtering from virCPUUpdate where it was just a hack.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
上级 1fe517c6
...@@ -384,6 +384,8 @@ struct _virQEMUCapsHostCPUData { ...@@ -384,6 +384,8 @@ struct _virQEMUCapsHostCPUData {
qemuMonitorCPUModelInfoPtr info; qemuMonitorCPUModelInfoPtr info;
/* Host CPU definition reported in domain capabilities. */ /* Host CPU definition reported in domain capabilities. */
virCPUDefPtr reported; virCPUDefPtr reported;
/* Migratable host CPU definition used for updating guest CPU. */
virCPUDefPtr migratable;
}; };
/* /*
...@@ -2136,6 +2138,10 @@ virQEMUCapsHostCPUDataCopy(virQEMUCapsHostCPUDataPtr dst, ...@@ -2136,6 +2138,10 @@ virQEMUCapsHostCPUDataCopy(virQEMUCapsHostCPUDataPtr dst,
!(dst->reported = virCPUDefCopy(src->reported))) !(dst->reported = virCPUDefCopy(src->reported)))
return -1; return -1;
if (src->migratable &&
!(dst->migratable = virCPUDefCopy(src->migratable)))
return -1;
return 0; return 0;
} }
...@@ -2145,6 +2151,7 @@ virQEMUCapsHostCPUDataClear(virQEMUCapsHostCPUDataPtr cpuData) ...@@ -2145,6 +2151,7 @@ virQEMUCapsHostCPUDataClear(virQEMUCapsHostCPUDataPtr cpuData)
{ {
qemuMonitorCPUModelInfoFree(cpuData->info); qemuMonitorCPUModelInfoFree(cpuData->info);
virCPUDefFree(cpuData->reported); virCPUDefFree(cpuData->reported);
virCPUDefFree(cpuData->migratable);
memset(cpuData, 0, sizeof(*cpuData)); memset(cpuData, 0, sizeof(*cpuData));
} }
...@@ -2483,6 +2490,9 @@ virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps, ...@@ -2483,6 +2490,9 @@ virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps,
switch (cpuType) { switch (cpuType) {
case VIR_QEMU_CAPS_HOST_CPU_REPORTED: case VIR_QEMU_CAPS_HOST_CPU_REPORTED:
return cpuData->reported; return cpuData->reported;
case VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE:
return cpuData->migratable;
} }
return NULL; return NULL;
...@@ -2492,11 +2502,13 @@ virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps, ...@@ -2492,11 +2502,13 @@ virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps,
static void static void
virQEMUCapsSetHostModel(virQEMUCapsPtr qemuCaps, virQEMUCapsSetHostModel(virQEMUCapsPtr qemuCaps,
virDomainVirtType type, virDomainVirtType type,
virCPUDefPtr cpu) virCPUDefPtr reported,
virCPUDefPtr migratable)
{ {
virQEMUCapsHostCPUDataPtr cpuData = virQEMUCapsGetHostCPUData(qemuCaps, type); virQEMUCapsHostCPUDataPtr cpuData = virQEMUCapsGetHostCPUData(qemuCaps, type);
cpuData->reported = cpu; cpuData->reported = reported;
cpuData->migratable = migratable;
} }
...@@ -3348,26 +3360,39 @@ virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps, ...@@ -3348,26 +3360,39 @@ virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps,
} }
static virCPUDefPtr
virQEMUCapsNewHostCPUModel(void)
{
virCPUDefPtr cpu;
if (VIR_ALLOC(cpu) < 0)
return NULL;
cpu->type = VIR_CPU_TYPE_GUEST;
cpu->mode = VIR_CPU_MODE_CUSTOM;
cpu->match = VIR_CPU_MATCH_EXACT;
cpu->fallback = VIR_CPU_FALLBACK_ALLOW;
return cpu;
}
void void
virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
virCapsPtr caps, virCapsPtr caps,
virDomainVirtType type) virDomainVirtType type)
{ {
virCPUDefPtr cpu = NULL; virCPUDefPtr cpu = NULL;
virCPUDefPtr migCPU = NULL;
virCPUDefPtr hostCPU = NULL; virCPUDefPtr hostCPU = NULL;
int rc; int rc;
if (!caps || !virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch)) if (!caps || !virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch))
return; return;
if (VIR_ALLOC(cpu) < 0) if (!(cpu = virQEMUCapsNewHostCPUModel()))
goto error; goto error;
cpu->type = VIR_CPU_TYPE_GUEST;
cpu->mode = VIR_CPU_MODE_CUSTOM;
cpu->match = VIR_CPU_MATCH_EXACT;
cpu->fallback = VIR_CPU_FALLBACK_ALLOW;
if ((rc = virQEMUCapsInitCPUModel(qemuCaps, type, cpu, false)) < 0) { if ((rc = virQEMUCapsInitCPUModel(qemuCaps, type, cpu, false)) < 0) {
goto error; goto error;
} else if (rc == 1) { } else if (rc == 1) {
...@@ -3381,7 +3406,20 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, ...@@ -3381,7 +3406,20 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
goto error; goto error;
} }
virQEMUCapsSetHostModel(qemuCaps, type, cpu); if (!(migCPU = virQEMUCapsNewHostCPUModel()))
goto error;
if ((rc = virQEMUCapsInitCPUModel(qemuCaps, type, migCPU, true)) < 0) {
goto error;
} else if (rc == 1) {
VIR_DEBUG("CPU migratability not provided by QEMU");
virCPUDefFree(migCPU);
if (!(migCPU = virCPUCopyMigratable(qemuCaps->arch, cpu)))
goto error;
}
virQEMUCapsSetHostModel(qemuCaps, type, cpu, migCPU);
cleanup: cleanup:
virCPUDefFree(hostCPU); virCPUDefFree(hostCPU);
...@@ -3389,6 +3427,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps, ...@@ -3389,6 +3427,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
error: error:
virCPUDefFree(cpu); virCPUDefFree(cpu);
virCPUDefFree(migCPU);
virResetLastError(); virResetLastError();
goto cleanup; goto cleanup;
} }
......
...@@ -453,6 +453,8 @@ int virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps, ...@@ -453,6 +453,8 @@ int virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
typedef enum { typedef enum {
/* Host CPU definition reported in domain capabilities. */ /* Host CPU definition reported in domain capabilities. */
VIR_QEMU_CAPS_HOST_CPU_REPORTED, VIR_QEMU_CAPS_HOST_CPU_REPORTED,
/* Migratable host CPU definition used for updating guest CPU. */
VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE,
} virQEMUCapsHostCPUType; } virQEMUCapsHostCPUType;
virCPUDefPtr virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps, virCPUDefPtr virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps,
......
...@@ -5311,7 +5311,7 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def, ...@@ -5311,7 +5311,7 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
if (virCPUUpdate(def->os.arch, def->cpu, if (virCPUUpdate(def->os.arch, def->cpu,
virQEMUCapsGetHostModel(qemuCaps, def->virtType, virQEMUCapsGetHostModel(qemuCaps, def->virtType,
VIR_QEMU_CAPS_HOST_CPU_REPORTED)) < 0) VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE)) < 0)
goto cleanup; goto cleanup;
if (virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType, if (virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType,
......
...@@ -393,6 +393,7 @@ cpuTestUpdate(const void *arg) ...@@ -393,6 +393,7 @@ cpuTestUpdate(const void *arg)
const struct data *data = arg; const struct data *data = arg;
int ret = -1; int ret = -1;
virCPUDefPtr host = NULL; virCPUDefPtr host = NULL;
virCPUDefPtr migHost = NULL;
virCPUDefPtr cpu = NULL; virCPUDefPtr cpu = NULL;
char *result = NULL; char *result = NULL;
...@@ -400,7 +401,10 @@ cpuTestUpdate(const void *arg) ...@@ -400,7 +401,10 @@ cpuTestUpdate(const void *arg)
!(cpu = cpuTestLoadXML(data->arch, data->name))) !(cpu = cpuTestLoadXML(data->arch, data->name)))
goto cleanup; goto cleanup;
if (virCPUUpdate(host->arch, cpu, host) < 0) if (!(migHost = virCPUCopyMigratable(data->arch, host)))
goto cleanup;
if (virCPUUpdate(host->arch, cpu, migHost) < 0)
goto cleanup; goto cleanup;
if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0) if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0)
...@@ -411,6 +415,7 @@ cpuTestUpdate(const void *arg) ...@@ -411,6 +415,7 @@ cpuTestUpdate(const void *arg)
cleanup: cleanup:
virCPUDefFree(host); virCPUDefFree(host);
virCPUDefFree(cpu); virCPUDefFree(cpu);
virCPUDefFree(migHost);
VIR_FREE(result); VIR_FREE(result);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册