cpu_conf: Drop updateCPU from virCPUDefFormat

In the past we updated host-model CPUs with host CPU data by adding a
model and features, but keeping the host-model mode. And since the CPU
model is not normally formatted for host-model CPU defs, we had to pass
the updateCPU flag to the formatting code to be able to properly output
updated host-model CPUs. Libvirt doesn't do this anymore, host-model
CPUs are turned into custom mode CPUs once updated with host CPU data
and thus there's no reason for keeping the hacks inside CPU XML
formatters.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2017-06-30 15:47:23 +02:00
parent c3d265424d
commit 4fd179f518
16 changed files with 31 additions and 42 deletions

View File

@ -1441,7 +1441,7 @@ bhyveConnectBaselineCPU(virConnectPtr conn,
virCPUExpandFeatures(cpus[0]->arch, cpu) < 0) virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
goto cleanup; goto cleanup;
cpustr = virCPUDefFormat(cpu, NULL, false); cpustr = virCPUDefFormat(cpu, NULL);
cleanup: cleanup:
virCPUDefListFree(cpus); virCPUDefListFree(cpus);

View File

@ -984,7 +984,7 @@ virCapabilitiesFormatXML(virCapsPtr caps)
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</features>\n"); virBufferAddLit(&buf, "</features>\n");
} }
virCPUDefFormatBuf(&buf, caps->host.cpu, false); virCPUDefFormatBuf(&buf, caps->host.cpu);
for (i = 0; i < caps->host.nPagesSize; i++) { for (i = 0; i < caps->host.nPagesSize; i++) {
virBufferAsprintf(&buf, "<pages unit='KiB' size='%u'/>\n", virBufferAsprintf(&buf, "<pages unit='KiB' size='%u'/>\n",

View File

@ -574,12 +574,11 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
char * char *
virCPUDefFormat(virCPUDefPtr def, virCPUDefFormat(virCPUDefPtr def,
virDomainNumaPtr numa, virDomainNumaPtr numa)
bool updateCPU)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
if (virCPUDefFormatBufFull(&buf, def, numa, updateCPU) < 0) if (virCPUDefFormatBufFull(&buf, def, numa) < 0)
goto cleanup; goto cleanup;
if (virBufferCheckError(&buf) < 0) if (virBufferCheckError(&buf) < 0)
@ -596,8 +595,7 @@ virCPUDefFormat(virCPUDefPtr def,
int int
virCPUDefFormatBufFull(virBufferPtr buf, virCPUDefFormatBufFull(virBufferPtr buf,
virCPUDefPtr def, virCPUDefPtr def,
virDomainNumaPtr numa, virDomainNumaPtr numa)
bool updateCPU)
{ {
int ret = -1; int ret = -1;
virBuffer attributeBuf = VIR_BUFFER_INITIALIZER; virBuffer attributeBuf = VIR_BUFFER_INITIALIZER;
@ -619,9 +617,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
virBufferAsprintf(&attributeBuf, " mode='%s'", tmp); virBufferAsprintf(&attributeBuf, " mode='%s'", tmp);
} }
if (def->model && if (def->model && def->mode == VIR_CPU_MODE_CUSTOM) {
(def->mode == VIR_CPU_MODE_CUSTOM ||
updateCPU)) {
if (!(tmp = virCPUMatchTypeToString(def->match))) { if (!(tmp = virCPUMatchTypeToString(def->match))) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected CPU match policy %d"), _("Unexpected CPU match policy %d"),
@ -642,7 +638,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
if (def->type == VIR_CPU_TYPE_HOST && def->arch) if (def->type == VIR_CPU_TYPE_HOST && def->arch)
virBufferAsprintf(&childrenBuf, "<arch>%s</arch>\n", virBufferAsprintf(&childrenBuf, "<arch>%s</arch>\n",
virArchToString(def->arch)); virArchToString(def->arch));
if (virCPUDefFormatBuf(&childrenBuf, def, updateCPU) < 0) if (virCPUDefFormatBuf(&childrenBuf, def) < 0)
goto cleanup; goto cleanup;
if (virDomainNumaDefCPUFormat(&childrenBuf, numa) < 0) if (virDomainNumaDefCPUFormat(&childrenBuf, numa) < 0)
@ -677,8 +673,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
int int
virCPUDefFormatBuf(virBufferPtr buf, virCPUDefFormatBuf(virBufferPtr buf,
virCPUDefPtr def, virCPUDefPtr def)
bool updateCPU)
{ {
size_t i; size_t i;
bool formatModel; bool formatModel;
@ -688,8 +683,7 @@ virCPUDefFormatBuf(virBufferPtr buf,
return 0; return 0;
formatModel = (def->mode == VIR_CPU_MODE_CUSTOM || formatModel = (def->mode == VIR_CPU_MODE_CUSTOM ||
def->mode == VIR_CPU_MODE_HOST_MODEL || def->mode == VIR_CPU_MODE_HOST_MODEL);
updateCPU);
formatFallback = (def->type == VIR_CPU_TYPE_GUEST && formatFallback = (def->type == VIR_CPU_TYPE_GUEST &&
(def->mode == VIR_CPU_MODE_HOST_MODEL || (def->mode == VIR_CPU_MODE_HOST_MODEL ||
(def->mode == VIR_CPU_MODE_CUSTOM && def->model))); (def->mode == VIR_CPU_MODE_CUSTOM && def->model)));

View File

@ -195,18 +195,15 @@ virCPUDefIsEqual(virCPUDefPtr src,
char * char *
virCPUDefFormat(virCPUDefPtr def, virCPUDefFormat(virCPUDefPtr def,
virDomainNumaPtr numa, virDomainNumaPtr numa);
bool updateCPU);
int int
virCPUDefFormatBuf(virBufferPtr buf, virCPUDefFormatBuf(virBufferPtr buf,
virCPUDefPtr def, virCPUDefPtr def);
bool updateCPU);
int int
virCPUDefFormatBufFull(virBufferPtr buf, virCPUDefFormatBufFull(virBufferPtr buf,
virCPUDefPtr def, virCPUDefPtr def,
virDomainNumaPtr numa, virDomainNumaPtr numa);
bool updateCPU);
int int
virCPUDefAddFeature(virCPUDefPtr cpu, virCPUDefAddFeature(virCPUDefPtr cpu,

View File

@ -413,7 +413,7 @@ virDomainCapsCPUFormat(virBufferPtr buf,
virBufferAddLit(buf, "supported='yes'>\n"); virBufferAddLit(buf, "supported='yes'>\n");
virBufferAdjustIndent(buf, 2); virBufferAdjustIndent(buf, 2);
virCPUDefFormatBuf(buf, cpu->hostModel, false); virCPUDefFormatBuf(buf, cpu->hostModel);
virBufferAdjustIndent(buf, -2); virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</mode>\n"); virBufferAddLit(buf, "</mode>\n");

View File

@ -25744,8 +25744,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
virBufferAddLit(buf, "</features>\n"); virBufferAddLit(buf, "</features>\n");
} }
if (virCPUDefFormatBufFull(buf, def->cpu, def->numa, if (virCPUDefFormatBufFull(buf, def->cpu, def->numa) < 0)
!!(flags & VIR_DOMAIN_DEF_FORMAT_UPDATE_CPU)) < 0)
goto error; goto error;
virBufferAsprintf(buf, "<clock offset='%s'", virBufferAsprintf(buf, "<clock offset='%s'",

View File

@ -6471,7 +6471,7 @@ libxlConnectBaselineCPU(virConnectPtr conn,
virCPUExpandFeatures(cpus[0]->arch, cpu) < 0) virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
goto cleanup; goto cleanup;
cpustr = virCPUDefFormat(cpu, NULL, false); cpustr = virCPUDefFormat(cpu, NULL);
cleanup: cleanup:
virCPUDefListFree(cpus); virCPUDefListFree(cpus);

View File

@ -1945,7 +1945,7 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf,
virBufferEscapeString(buf, "<channelTargetDir path='%s'/>\n", virBufferEscapeString(buf, "<channelTargetDir path='%s'/>\n",
priv->channelTargetDir); priv->channelTargetDir);
virCPUDefFormatBufFull(buf, priv->origCPU, NULL, false); virCPUDefFormatBufFull(buf, priv->origCPU, NULL);
if (priv->chardevStdioLogd) if (priv->chardevStdioLogd)
virBufferAddLit(buf, "<chardevStdioLogd/>\n"); virBufferAddLit(buf, "<chardevStdioLogd/>\n");
@ -9811,7 +9811,7 @@ qemuDomainSaveCookieFormat(virBufferPtr buf,
qemuDomainSaveCookiePtr cookie = (qemuDomainSaveCookiePtr) obj; qemuDomainSaveCookiePtr cookie = (qemuDomainSaveCookiePtr) obj;
if (cookie->cpu && if (cookie->cpu &&
virCPUDefFormatBufFull(buf, cookie->cpu, NULL, false) < 0) virCPUDefFormatBufFull(buf, cookie->cpu, NULL) < 0)
return -1; return -1;
return 0; return 0;

View File

@ -13031,7 +13031,7 @@ qemuConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
virCPUExpandFeatures(cpus[0]->arch, cpu) < 0) virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
goto cleanup; goto cleanup;
cpustr = virCPUDefFormat(cpu, NULL, false); cpustr = virCPUDefFormat(cpu, NULL);
cleanup: cleanup:
virCPUDefListFree(cpus); virCPUDefListFree(cpus);

View File

@ -771,7 +771,7 @@ qemuMigrationCookieXMLFormat(virQEMUDriverPtr driver,
qemuMigrationCookieStatisticsXMLFormat(buf, mig->jobInfo); qemuMigrationCookieStatisticsXMLFormat(buf, mig->jobInfo);
if (mig->flags & QEMU_MIGRATION_COOKIE_CPU && mig->cpu) if (mig->flags & QEMU_MIGRATION_COOKIE_CPU && mig->cpu)
virCPUDefFormatBufFull(buf, mig->cpu, NULL, false); virCPUDefFormatBufFull(buf, mig->cpu, NULL);
virBufferAdjustIndent(buf, -2); virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</qemu-migration>\n"); virBufferAddLit(buf, "</qemu-migration>\n");

View File

@ -1552,7 +1552,7 @@ testConnectBaselineCPU(virConnectPtr conn ATTRIBUTE_UNUSED,
virCPUExpandFeatures(cpus[0]->arch, cpu) < 0) virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
goto cleanup; goto cleanup;
cpustr = virCPUDefFormat(cpu, NULL, false); cpustr = virCPUDefFormat(cpu, NULL);
cleanup: cleanup:
virCPUDefListFree(cpus); virCPUDefListFree(cpus);

View File

@ -964,7 +964,7 @@ vzConnectBaselineCPU(virConnectPtr conn,
virCPUExpandFeatures(cpus[0]->arch, cpu) < 0) virCPUExpandFeatures(cpus[0]->arch, cpu) < 0)
goto cleanup; goto cleanup;
cpustr = virCPUDefFormat(cpu, NULL, false); cpustr = virCPUDefFormat(cpu, NULL);
cleanup: cleanup:
virCPUDefListFree(cpus); virCPUDefListFree(cpus);

View File

@ -150,8 +150,7 @@ cpuTestLoadMultiXML(virArch arch,
static int static int
cpuTestCompareXML(virArch arch, cpuTestCompareXML(virArch arch,
virCPUDef *cpu, virCPUDef *cpu,
const char *name, const char *name)
bool updateCPU)
{ {
char *xml = NULL; char *xml = NULL;
char *actual = NULL; char *actual = NULL;
@ -161,7 +160,7 @@ cpuTestCompareXML(virArch arch,
abs_srcdir, virArchToString(arch), name) < 0) abs_srcdir, virArchToString(arch), name) < 0)
goto cleanup; goto cleanup;
if (!(actual = virCPUDefFormat(cpu, NULL, updateCPU))) if (!(actual = virCPUDefFormat(cpu, NULL)))
goto cleanup; goto cleanup;
if (virTestCompareToFile(actual, xml) < 0) if (virTestCompareToFile(actual, xml) < 0)
@ -281,7 +280,7 @@ cpuTestGuestCPU(const void *arg)
} }
result = virBufferContentAndReset(&buf); result = virBufferContentAndReset(&buf);
if (cpuTestCompareXML(data->arch, cpu, result, false) < 0) if (cpuTestCompareXML(data->arch, cpu, result) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
@ -355,7 +354,7 @@ cpuTestBaseline(const void *arg)
if (virAsprintf(&result, "%s-%s", data->name, suffix) < 0) if (virAsprintf(&result, "%s-%s", data->name, suffix) < 0)
goto cleanup; goto cleanup;
if (cpuTestCompareXML(data->arch, baseline, result, false) < 0) if (cpuTestCompareXML(data->arch, baseline, result) < 0)
goto cleanup; goto cleanup;
for (i = 0; i < ncpus; i++) { for (i = 0; i < ncpus; i++) {
@ -409,7 +408,7 @@ cpuTestUpdate(const void *arg)
if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0) if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0)
goto cleanup; goto cleanup;
ret = cpuTestCompareXML(data->arch, cpu, result, true); ret = cpuTestCompareXML(data->arch, cpu, result);
cleanup: cleanup:
virCPUDefFree(host); virCPUDefFree(host);
@ -501,7 +500,7 @@ cpuTestCPUID(bool guest, const void *arg)
guest ? "guest" : "host") < 0) guest ? "guest" : "host") < 0)
goto cleanup; goto cleanup;
ret = cpuTestCompareXML(data->arch, cpu, result, false); ret = cpuTestCompareXML(data->arch, cpu, result);
cleanup: cleanup:
VIR_FREE(hostFile); VIR_FREE(hostFile);
@ -716,7 +715,7 @@ cpuTestJSONCPUID(const void *arg)
if (virQEMUCapsInitCPUModel(qemuCaps, VIR_DOMAIN_VIRT_KVM, cpu, false) != 0) if (virQEMUCapsInitCPUModel(qemuCaps, VIR_DOMAIN_VIRT_KVM, cpu, false) != 0)
goto cleanup; goto cleanup;
ret = cpuTestCompareXML(data->arch, cpu, result, false); ret = cpuTestCompareXML(data->arch, cpu, result);
cleanup: cleanup:
qemuMonitorCPUModelInfoFree(model); qemuMonitorCPUModelInfoFree(model);

View File

@ -1,3 +1,3 @@
<cpu mode='host-model' match='exact'> <cpu mode='host-model'>
<model fallback='allow'>power8</model> <model fallback='allow'>power8</model>
</cpu> </cpu>

View File

@ -1,3 +1,3 @@
<cpu mode='host-model' match='exact'> <cpu mode='host-model'>
<model fallback='allow'>power7+</model> <model fallback='allow'>power7+</model>
</cpu> </cpu>

View File

@ -1,3 +1,3 @@
<cpu mode='host-model' match='exact'> <cpu mode='host-model'>
<model fallback='allow'>power6</model> <model fallback='allow'>power6</model>
</cpu> </cpu>