diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 2f243ae467..40e297678a 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1,7 +1,7 @@ /* * capabilities.c: hypervisor capabilities * - * Copyright (C) 2006-2008, 2010 Red Hat, Inc. + * Copyright (C) 2006-2008, 2010-2011 Red Hat, Inc. * Copyright (C) 2006-2008 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -681,8 +681,9 @@ virCapabilitiesFormatXML(virCapsPtr caps) virBufferAddLit(&xml, " \n"); } - virCPUDefFormatBuf(&xml, caps->host.cpu, " ", - VIR_CPU_FORMAT_EMBEDED); + virBufferAdjustIndent(&xml, 6); + virCPUDefFormatBuf(&xml, caps->host.cpu); + virBufferAdjustIndent(&xml, -6); virBufferAddLit(&xml, " \n"); diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 5cecda2f2b..41e997ea97 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -305,13 +305,11 @@ error: char * -virCPUDefFormat(virCPUDefPtr def, - const char *indent, - unsigned int flags) +virCPUDefFormat(virCPUDefPtr def) { virBuffer buf = VIR_BUFFER_INITIALIZER; - if (virCPUDefFormatBuf(&buf, def, indent, flags) < 0) + if (virCPUDefFormatBufFull(&buf, def) < 0) goto cleanup; if (virBufferError(&buf)) @@ -327,54 +325,63 @@ cleanup: } +int +virCPUDefFormatBufFull(virBufferPtr buf, + virCPUDefPtr def) +{ + if (!def) + return 0; + + if (def->type == VIR_CPU_TYPE_GUEST && def->model) { + const char *match; + if (!(match = virCPUMatchTypeToString(def->match))) { + virCPUReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected CPU match policy %d"), def->match); + return -1; + } + + virBufferAsprintf(buf, "\n", match); + } else { + virBufferAddLit(buf, "\n"); + } + + if (def->arch) + virBufferAsprintf(buf, " %s\n", def->arch); + + virBufferAdjustIndent(buf, 2); + if (virCPUDefFormatBuf(buf, def) < 0) + return -1; + virBufferAdjustIndent(buf, -2); + + virBufferAddLit(buf, "\n"); + + return 0; +} + int virCPUDefFormatBuf(virBufferPtr buf, - virCPUDefPtr def, - const char *indent, - unsigned int flags) + virCPUDefPtr def) { unsigned int i; if (!def) return 0; - if (indent == NULL) - indent = ""; - if (!def->model && def->nfeatures) { virCPUReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Non-empty feature list specified without CPU model")); return -1; } - if (!(flags & VIR_CPU_FORMAT_EMBEDED)) { - if (def->type == VIR_CPU_TYPE_GUEST && def->model) { - const char *match; - if (!(match = virCPUMatchTypeToString(def->match))) { - virCPUReportError(VIR_ERR_INTERNAL_ERROR, - _("Unexpected CPU match policy %d"), def->match); - return -1; - } - - virBufferAsprintf(buf, "%s\n", indent, match); - } - else - virBufferAsprintf(buf, "%s\n", indent); - - if (def->arch) - virBufferAsprintf(buf, "%s %s\n", indent, def->arch); - } - if (def->model) - virBufferAsprintf(buf, "%s %s\n", indent, def->model); + virBufferAsprintf(buf, "%s\n", def->model); if (def->vendor) { - virBufferAsprintf(buf, "%s %s\n", - indent, def->vendor); + virBufferAsprintf(buf, "%s\n", def->vendor); } if (def->sockets && def->cores && def->threads) { - virBufferAsprintf(buf, "%s sockets); virBufferAsprintf(buf, " cores='%u'", def->cores); virBufferAsprintf(buf, " threads='%u'", def->threads); @@ -399,18 +406,14 @@ virCPUDefFormatBuf(virBufferPtr buf, _("Unexpected CPU feature policy %d"), feature->policy); return -1; } - virBufferAsprintf(buf, "%s \n", - indent, policy, feature->name); - } - else { - virBufferAsprintf(buf, "%s \n", - indent, feature->name); + virBufferAsprintf(buf, "\n", + policy, feature->name); + } else { + virBufferAsprintf(buf, "\n", + feature->name); } } - if (!(flags & VIR_CPU_FORMAT_EMBEDED)) - virBufferAsprintf(buf, "%s\n", indent); - return 0; } diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index 57b85e14f1..4406cba05a 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -95,25 +95,19 @@ virCPUDefParseXML(const xmlNodePtr node, xmlXPathContextPtr ctxt, enum virCPUType mode); -enum virCPUFormatFlags { - VIR_CPU_FORMAT_EMBEDED = (1 << 0) /* embed into existing element - * in host capabilities */ -}; - bool virCPUDefIsEqual(virCPUDefPtr src, virCPUDefPtr dst); char * -virCPUDefFormat(virCPUDefPtr def, - const char *indent, - unsigned int flags); +virCPUDefFormat(virCPUDefPtr def); int virCPUDefFormatBuf(virBufferPtr buf, - virCPUDefPtr def, - const char *indent, - unsigned int flags); + virCPUDefPtr def); +int +virCPUDefFormatBufFull(virBufferPtr buf, + virCPUDefPtr def); int virCPUDefAddFeature(virCPUDefPtr cpu, diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9a46122961..304d1a82aa 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10825,8 +10825,10 @@ virDomainDefFormatInternal(virDomainDefPtr def, virBufferAddLit(buf, " \n"); } - if (virCPUDefFormatBuf(buf, def->cpu, " ", 0) < 0) + virBufferAdjustIndent(buf, 2); + if (virCPUDefFormatBufFull(buf, def->cpu) < 0) goto cleanup; + virBufferAdjustIndent(buf, -2); virBufferAsprintf(buf, " clock.offset)); diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 2906be9a14..b919b6e2e0 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -320,7 +320,7 @@ cpuBaselineXML(const char **xmlCPUs, if (!(cpu = cpuBaseline(cpus, ncpus, models, nmodels))) goto error; - cpustr = virCPUDefFormat(cpu, "", 0); + cpustr = virCPUDefFormat(cpu); cleanup: if (cpus) { diff --git a/tests/cputest.c b/tests/cputest.c index b5272c1624..36b3eb4b8e 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -176,7 +176,7 @@ cpuTestCompareXML(const char *arch, if (virtTestLoadFile(xml, &expected) < 0) goto cleanup; - if (!(actual = virCPUDefFormat(cpu, NULL, 0))) + if (!(actual = virCPUDefFormat(cpu))) goto cleanup; if (STRNEQ(expected, actual)) {