Decouple CPU XML formatting from domain XML public API flags

The virCPUDefFormat* methods were relying on the VIR_DOMAIN_XML_*
flag definitions. It is not desirable for low level internal
functions to be coupled to flags for the public API, since they
may need to be called from several different contexts where the
flags would not be appropriate.
This commit is contained in:
Daniel P. Berrange 2015-01-06 11:54:32 +00:00
parent 2b8090b701
commit e34473c1da
6 changed files with 19 additions and 19 deletions

View File

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

View File

@ -532,11 +532,11 @@ virCPUDefParseXML(xmlNodePtr node,
char *
virCPUDefFormat(virCPUDefPtr def,
unsigned int flags)
bool updateCPU)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
if (virCPUDefFormatBufFull(&buf, def, flags) < 0)
if (virCPUDefFormatBufFull(&buf, def, updateCPU) < 0)
goto cleanup;
if (virBufferCheckError(&buf) < 0)
@ -553,7 +553,7 @@ virCPUDefFormat(virCPUDefPtr def,
int
virCPUDefFormatBufFull(virBufferPtr buf,
virCPUDefPtr def,
unsigned int flags)
bool updateCPU)
{
if (!def)
return 0;
@ -573,7 +573,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
if (def->model &&
(def->mode == VIR_CPU_MODE_CUSTOM ||
(flags & VIR_DOMAIN_XML_UPDATE_CPU))) {
updateCPU)) {
if (!(tmp = virCPUMatchTypeToString(def->match))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unexpected CPU match policy %d"),
@ -589,7 +589,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
if (def->arch)
virBufferAsprintf(buf, "<arch>%s</arch>\n",
virArchToString(def->arch));
if (virCPUDefFormatBuf(buf, def, flags) < 0)
if (virCPUDefFormatBuf(buf, def, updateCPU) < 0)
return -1;
virBufferAdjustIndent(buf, -2);
@ -601,7 +601,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
int
virCPUDefFormatBuf(virBufferPtr buf,
virCPUDefPtr def,
unsigned int flags)
bool updateCPU)
{
size_t i;
bool formatModel;
@ -612,7 +612,7 @@ virCPUDefFormatBuf(virBufferPtr buf,
formatModel = (def->mode == VIR_CPU_MODE_CUSTOM ||
def->mode == VIR_CPU_MODE_HOST_MODEL ||
(flags & VIR_DOMAIN_XML_UPDATE_CPU));
updateCPU);
formatFallback = (def->type == VIR_CPU_TYPE_GUEST &&
(def->mode == VIR_CPU_MODE_HOST_MODEL ||
(def->mode == VIR_CPU_MODE_CUSTOM && def->model)));

View File

@ -158,16 +158,16 @@ virCPUDefIsEqual(virCPUDefPtr src,
char *
virCPUDefFormat(virCPUDefPtr def,
unsigned int flags);
bool updateCPU);
int
virCPUDefFormatBuf(virBufferPtr buf,
virCPUDefPtr def,
unsigned int flags);
bool updateCPU);
int
virCPUDefFormatBufFull(virBufferPtr buf,
virCPUDefPtr def,
unsigned int flags);
bool updateCPU);
int
virCPUDefAddFeature(virCPUDefPtr cpu,

View File

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

View File

@ -472,7 +472,7 @@ cpuBaselineXML(const char **xmlCPUs,
if (!(cpu = cpuBaseline(cpus, ncpus, models, nmodels, flags)))
goto error;
cpustr = virCPUDefFormat(cpu, 0);
cpustr = virCPUDefFormat(cpu, false);
cleanup:
if (cpus) {

View File

@ -153,7 +153,7 @@ static int
cpuTestCompareXML(const char *arch,
virCPUDef *cpu,
const char *name,
unsigned int flags)
bool updateCPU)
{
char *xml = NULL;
char *expected = NULL;
@ -167,7 +167,7 @@ cpuTestCompareXML(const char *arch,
if (virtTestLoadFile(xml, &expected) < 0)
goto cleanup;
if (!(actual = virCPUDefFormat(cpu, flags)))
if (!(actual = virCPUDefFormat(cpu, updateCPU)))
goto cleanup;
if (STRNEQ(expected, actual)) {
@ -303,7 +303,7 @@ cpuTestGuestData(const void *arg)
}
result = virBufferContentAndReset(&buf);
ret = cpuTestCompareXML(data->arch, guest, result, 0);
ret = cpuTestCompareXML(data->arch, guest, result, false);
cleanup:
VIR_FREE(result);
@ -351,7 +351,7 @@ cpuTestBaseline(const void *arg)
if (virAsprintf(&result, "%s-%s", data->name, suffix) < 0)
goto cleanup;
if (cpuTestCompareXML(data->arch, baseline, result, 0) < 0)
if (cpuTestCompareXML(data->arch, baseline, result, false) < 0)
goto cleanup;
for (i = 0; i < ncpus; i++) {
@ -403,8 +403,7 @@ cpuTestUpdate(const void *arg)
if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0)
goto cleanup;
ret = cpuTestCompareXML(data->arch, cpu, result,
VIR_DOMAIN_XML_UPDATE_CPU);
ret = cpuTestCompareXML(data->arch, cpu, result, true);
cleanup:
virCPUDefFree(host);