This round focuses on CPU features.
* src/conf/cpu_conf.h (virCPUFormatFlags): Fix typo.
(virCPUDefFormat): Drop unused argument.
(virCPUDefFormatBuf): Alter signature.
* src/conf/cpu_conf.c (virCPUDefFormat, virCPUDefFormatBuf): Alter
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 | 6 +++---
src/conf/cpu_conf.c | 43 ++++++++++++++++++++-----------------------
src/conf/cpu_conf.h | 7 +++----
src/conf/domain_conf.c | 2 +-
src/cpu/cpu.c | 2 +-
tests/cputest.c | 2 +-
6 files changed, 29 insertions(+), 33 deletions(-)
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 2f243ae..7e074fb 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,8 @@ virCapabilitiesFormatXML(virCapsPtr caps)
virBufferAddLit(&xml, " </features>\n");
}
- virCPUDefFormatBuf(&xml, caps->host.cpu, " ",
- VIR_CPU_FORMAT_EMBEDED);
+ virCPUDefFormatBuf(&xml, caps->host.cpu, 4,
+ VIR_CPU_FORMAT_EMBEDDED);
virBufferAddLit(&xml, " </cpu>\n");
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 5cecda2..ce67e78 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -306,12 +306,11 @@ error:
char *
virCPUDefFormat(virCPUDefPtr def,
- const char *indent,
unsigned int flags)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
- if (virCPUDefFormatBuf(&buf, def, indent, flags) < 0)
+ if (virCPUDefFormatBuf(&buf, def, 0, flags) < 0)
goto cleanup;
if (virBufferError(&buf))
@@ -330,7 +329,7 @@ cleanup:
int
virCPUDefFormatBuf(virBufferPtr buf,
virCPUDefPtr def,
- const char *indent,
+ int indent,
unsigned int flags)
{
unsigned int i;
@@ -338,16 +337,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 +352,27 @@ virCPUDefFormatBuf(virBufferPtr buf,
return -1;
}
- virBufferAsprintf(buf, "%s<cpu match='%s'>\n",
indent, match);
+ virBufferAsprintf(buf, "%*s<cpu match='%s'>\n",
indent, "", match);
+ } else {
+ virBufferIndentAddLit(buf, indent, "<cpu>\n");
}
- else
- virBufferAsprintf(buf, "%s<cpu>\n", indent);
if (def->arch)
- virBufferAsprintf(buf, "%s <arch>%s</arch>\n", indent,
def->arch);
+ virBufferAsprintf(buf, "%*s<arch>%s</arch>\n", indent +
2, "",
+ def->arch);
}
if (def->model)
- virBufferAsprintf(buf, "%s <model>%s</model>\n", indent,
def->model);
+ virBufferAsprintf(buf, "%*s<model>%s</model>\n", indent +
2, "",
+ def->model);
if (def->vendor) {
- virBufferAsprintf(buf, "%s <vendor>%s</vendor>\n",
- indent, def->vendor);
+ virBufferAsprintf(buf, "%*s<vendor>%s</vendor>\n", indent +
2, "",
+ def->vendor);
}
if (def->sockets && def->cores && def->threads) {
- virBufferAsprintf(buf, "%s <topology", indent);
+ virBufferIndentAddLit(buf, indent + 2, "<topology");
virBufferAsprintf(buf, " sockets='%u'", def->sockets);
virBufferAsprintf(buf, " cores='%u'", def->cores);
virBufferAsprintf(buf, " threads='%u'", def->threads);
@@ -399,17 +397,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, "%*s<feature policy='%s'
name='%s'/>\n",
+ indent + 2, "", policy, feature->name);
+ } else {
+ virBufferAsprintf(buf, "%*s<feature name='%s'/>\n",
+ indent + 2, "", feature->name);
}
}
- if (!(flags & VIR_CPU_FORMAT_EMBEDED))
- virBufferAsprintf(buf, "%s</cpu>\n", indent);
+ if (!(flags & VIR_CPU_FORMAT_EMBEDDED))
+ virBufferIndentAddLit(buf, indent, "</cpu>\n");
return 0;
}
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 57b85e1..60cfd44 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
@@ -106,13 +106,12 @@ virCPUDefIsEqual(virCPUDefPtr src,
char *
virCPUDefFormat(virCPUDefPtr def,
- const char *indent,
unsigned int flags);
int
virCPUDefFormatBuf(virBufferPtr buf,
virCPUDefPtr def,
- const char *indent,
+ int indent,
unsigned int flags);
int
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9b6b9ca..4b825fb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10721,7 +10721,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
virBufferIndentAddLit(buf, indent, "</features>\n");
}
- if (virCPUDefFormatBuf(buf, def->cpu, " ", 0) < 0) /* XXX indent */
+ if (virCPUDefFormatBuf(buf, def->cpu, indent, 0) < 0)
goto cleanup;
virBufferAsprintf(buf, "%*s<clock offset='%s'", indent,
"",
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 2906be9..72169b4 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, 0);
cleanup:
if (cpus) {
diff --git a/tests/cputest.c b/tests/cputest.c
index b5272c1..e9f5cbb 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, 0)))
goto cleanup;
if (STRNEQ(expected, actual)) {
--
1.7.4.4