Auto-indent makes life a bit easier; this patch also drops unused arguments and fixes a flag name. * src/conf/cpu_conf.h (virCPUFormatFlags): Fix typo. (virCPUDefFormat, virCPUDefFormatBuf): Drop unused arguments. * src/conf/cpu_conf.c (virCPUDefFormat, virCPUDefFormatBuf): Simplify indentation. * src/conf/domain_conf.c (virDomainDefFormatInternal): Adjust caller. * src/conf/capabilities.c (virCapabilitiesFormatXML): Likewise. * src/cpu/cpu.c (cpuBaselineXML): Likewise. * tests/cputest.c (cpuTestCompareXML): Likewise. --- src/conf/capabilities.c | 8 +++++--- src/conf/cpu_conf.c | 42 +++++++++++++++++------------------------- src/conf/cpu_conf.h | 9 +++------ src/conf/domain_conf.c | 4 +++- src/cpu/cpu.c | 2 +- tests/cputest.c | 2 +- 6 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 2f243ae..5f7f768 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,10 @@ virCapabilitiesFormatXML(virCapsPtr caps) virBufferAddLit(&xml, " </features>\n"); } - virCPUDefFormatBuf(&xml, caps->host.cpu, " ", - VIR_CPU_FORMAT_EMBEDED); + /* virCPUDefFormatBuf with EMBEDDED uses indent of 2, we want 4 more */ + virBufferAdjustIndent(&xml, 4); + virCPUDefFormatBuf(&xml, caps->host.cpu, VIR_CPU_FORMAT_EMBEDDED); + virBufferAdjustIndent(&xml, -4); virBufferAddLit(&xml, " </cpu>\n"); diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 5cecda2..49ea392 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 (virCPUDefFormatBuf(&buf, def, 0) < 0) goto cleanup; if (virBufferError(&buf)) @@ -330,7 +328,6 @@ cleanup: int virCPUDefFormatBuf(virBufferPtr buf, virCPUDefPtr def, - const char *indent, unsigned int flags) { unsigned int i; @@ -338,16 +335,13 @@ virCPUDefFormatBuf(virBufferPtr buf, 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 (!(flags & VIR_CPU_FORMAT_EMBEDDED)) { if (def->type == VIR_CPU_TYPE_GUEST && def->model) { const char *match; if (!(match = virCPUMatchTypeToString(def->match))) { @@ -356,25 +350,24 @@ virCPUDefFormatBuf(virBufferPtr buf, return -1; } - virBufferAsprintf(buf, "%s<cpu match='%s'>\n", indent, match); + virBufferAsprintf(buf, "<cpu match='%s'>\n", match); + } else { + virBufferAddLit(buf, "<cpu>\n"); } - else - virBufferAsprintf(buf, "%s<cpu>\n", indent); if (def->arch) - virBufferAsprintf(buf, "%s <arch>%s</arch>\n", indent, def->arch); + virBufferAsprintf(buf, " <arch>%s</arch>\n", def->arch); } if (def->model) - virBufferAsprintf(buf, "%s <model>%s</model>\n", indent, def->model); + virBufferAsprintf(buf, " <model>%s</model>\n", def->model); if (def->vendor) { - virBufferAsprintf(buf, "%s <vendor>%s</vendor>\n", - indent, def->vendor); + virBufferAsprintf(buf, " <vendor>%s</vendor>\n", def->vendor); } if (def->sockets && def->cores && def->threads) { - virBufferAsprintf(buf, "%s <topology", indent); + virBufferAddLit(buf, " <topology"); virBufferAsprintf(buf, " sockets='%u'", def->sockets); virBufferAsprintf(buf, " cores='%u'", def->cores); virBufferAsprintf(buf, " threads='%u'", def->threads); @@ -399,17 +392,16 @@ virCPUDefFormatBuf(virBufferPtr buf, _("Unexpected CPU feature policy %d"), feature->policy); return -1; } - virBufferAsprintf(buf, "%s <feature policy='%s' name='%s'/>\n", - indent, policy, feature->name); - } - else { - virBufferAsprintf(buf, "%s <feature name='%s'/>\n", - indent, feature->name); + virBufferAsprintf(buf, " <feature policy='%s' name='%s'/>\n", + policy, feature->name); + } else { + virBufferAsprintf(buf, " <feature name='%s'/>\n", + feature->name); } } - if (!(flags & VIR_CPU_FORMAT_EMBEDED)) - virBufferAsprintf(buf, "%s</cpu>\n", indent); + if (!(flags & VIR_CPU_FORMAT_EMBEDDED)) + virBufferAddLit(buf, "</cpu>\n"); return 0; } diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index 57b85e1..409bbca 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -96,8 +96,8 @@ virCPUDefParseXML(const xmlNodePtr node, enum virCPUType mode); enum virCPUFormatFlags { - VIR_CPU_FORMAT_EMBEDED = (1 << 0) /* embed into existing <cpu/> element - * in host capabilities */ + VIR_CPU_FORMAT_EMBEDDED = (1 << 0) /* embed into existing <cpu/> element + * in host capabilities */ }; bool @@ -105,14 +105,11 @@ 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); int diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index eb82fa6..40b06f3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10749,8 +10749,10 @@ virDomainDefFormatInternal(virDomainDefPtr def, virBufferAddLit(buf, " </features>\n"); } - if (virCPUDefFormatBuf(buf, def->cpu, " ", 0) < 0) + virBufferAdjustIndent(buf, 2); + if (virCPUDefFormatBuf(buf, def->cpu, 0) < 0) goto cleanup; + virBufferAdjustIndent(buf, -2); virBufferAsprintf(buf, " <clock offset='%s'", virDomainClockOffsetTypeToString(def->clock.offset)); diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 2906be9..b919b6e 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 b5272c1..36b3eb4 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)) { -- 1.7.4.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list