mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
snapshot: simplify indentation of cpu features
Auto-indent makes life a bit easier; this patch also drops unused arguments and replaces a misspelled flag name with two entry points instead, so that callers don't have to worry about how much spacing is present when embedding cpu elements. * src/conf/cpu_conf.h (virCPUFormatFlags): Delete. (virCPUDefFormat): Drop unused argument. (virCPUDefFormatBuf): Alter signature. (virCPUDefFormatBufFull): New prototype. * src/conf/cpu_conf.c (virCPUDefFormatBuf): Split... (virCPUDefFormatBufFull): ...into new function. (virCPUDefFormat): Adjust caller. * src/conf/domain_conf.c (virDomainDefFormatInternal): Likewise. * src/conf/capabilities.c (virCapabilitiesFormatXML): Likewise. * src/cpu/cpu.c (cpuBaselineXML): Likewise. * tests/cputest.c (cpuTestCompareXML): Likewise.
This commit is contained in:
parent
9a220665e7
commit
4eedfd075e
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* capabilities.c: hypervisor capabilities
|
* 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
|
* Copyright (C) 2006-2008 Daniel P. Berrange
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
@ -681,8 +681,9 @@ virCapabilitiesFormatXML(virCapsPtr caps)
|
|||||||
virBufferAddLit(&xml, " </features>\n");
|
virBufferAddLit(&xml, " </features>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
virCPUDefFormatBuf(&xml, caps->host.cpu, " ",
|
virBufferAdjustIndent(&xml, 6);
|
||||||
VIR_CPU_FORMAT_EMBEDED);
|
virCPUDefFormatBuf(&xml, caps->host.cpu);
|
||||||
|
virBufferAdjustIndent(&xml, -6);
|
||||||
|
|
||||||
virBufferAddLit(&xml, " </cpu>\n");
|
virBufferAddLit(&xml, " </cpu>\n");
|
||||||
|
|
||||||
|
@ -305,13 +305,11 @@ error:
|
|||||||
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
virCPUDefFormat(virCPUDefPtr def,
|
virCPUDefFormat(virCPUDefPtr def)
|
||||||
const char *indent,
|
|
||||||
unsigned int flags)
|
|
||||||
{
|
{
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
if (virCPUDefFormatBuf(&buf, def, indent, flags) < 0)
|
if (virCPUDefFormatBufFull(&buf, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virBufferError(&buf))
|
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, "<cpu match='%s'>\n", match);
|
||||||
|
} else {
|
||||||
|
virBufferAddLit(buf, "<cpu>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (def->arch)
|
||||||
|
virBufferAsprintf(buf, " <arch>%s</arch>\n", def->arch);
|
||||||
|
|
||||||
|
virBufferAdjustIndent(buf, 2);
|
||||||
|
if (virCPUDefFormatBuf(buf, def) < 0)
|
||||||
|
return -1;
|
||||||
|
virBufferAdjustIndent(buf, -2);
|
||||||
|
|
||||||
|
virBufferAddLit(buf, "</cpu>\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
virCPUDefFormatBuf(virBufferPtr buf,
|
virCPUDefFormatBuf(virBufferPtr buf,
|
||||||
virCPUDefPtr def,
|
virCPUDefPtr def)
|
||||||
const char *indent,
|
|
||||||
unsigned int flags)
|
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
if (!def)
|
if (!def)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (indent == NULL)
|
|
||||||
indent = "";
|
|
||||||
|
|
||||||
if (!def->model && def->nfeatures) {
|
if (!def->model && def->nfeatures) {
|
||||||
virCPUReportError(VIR_ERR_INTERNAL_ERROR,
|
virCPUReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("Non-empty feature list specified without CPU model"));
|
"%s", _("Non-empty feature list specified without CPU model"));
|
||||||
return -1;
|
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<cpu match='%s'>\n", indent, match);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
virBufferAsprintf(buf, "%s<cpu>\n", indent);
|
|
||||||
|
|
||||||
if (def->arch)
|
|
||||||
virBufferAsprintf(buf, "%s <arch>%s</arch>\n", indent, def->arch);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (def->model)
|
if (def->model)
|
||||||
virBufferAsprintf(buf, "%s <model>%s</model>\n", indent, def->model);
|
virBufferAsprintf(buf, "<model>%s</model>\n", def->model);
|
||||||
|
|
||||||
if (def->vendor) {
|
if (def->vendor) {
|
||||||
virBufferAsprintf(buf, "%s <vendor>%s</vendor>\n",
|
virBufferAsprintf(buf, "<vendor>%s</vendor>\n", def->vendor);
|
||||||
indent, def->vendor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def->sockets && def->cores && def->threads) {
|
if (def->sockets && def->cores && def->threads) {
|
||||||
virBufferAsprintf(buf, "%s <topology", indent);
|
virBufferAddLit(buf, "<topology");
|
||||||
virBufferAsprintf(buf, " sockets='%u'", def->sockets);
|
virBufferAsprintf(buf, " sockets='%u'", def->sockets);
|
||||||
virBufferAsprintf(buf, " cores='%u'", def->cores);
|
virBufferAsprintf(buf, " cores='%u'", def->cores);
|
||||||
virBufferAsprintf(buf, " threads='%u'", def->threads);
|
virBufferAsprintf(buf, " threads='%u'", def->threads);
|
||||||
@ -399,18 +406,14 @@ virCPUDefFormatBuf(virBufferPtr buf,
|
|||||||
_("Unexpected CPU feature policy %d"), feature->policy);
|
_("Unexpected CPU feature policy %d"), feature->policy);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
virBufferAsprintf(buf, "%s <feature policy='%s' name='%s'/>\n",
|
virBufferAsprintf(buf, "<feature policy='%s' name='%s'/>\n",
|
||||||
indent, policy, feature->name);
|
policy, feature->name);
|
||||||
}
|
} else {
|
||||||
else {
|
virBufferAsprintf(buf, "<feature name='%s'/>\n",
|
||||||
virBufferAsprintf(buf, "%s <feature name='%s'/>\n",
|
feature->name);
|
||||||
indent, feature->name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(flags & VIR_CPU_FORMAT_EMBEDED))
|
|
||||||
virBufferAsprintf(buf, "%s</cpu>\n", indent);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,25 +95,19 @@ virCPUDefParseXML(const xmlNodePtr node,
|
|||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
enum virCPUType mode);
|
enum virCPUType mode);
|
||||||
|
|
||||||
enum virCPUFormatFlags {
|
|
||||||
VIR_CPU_FORMAT_EMBEDED = (1 << 0) /* embed into existing <cpu/> element
|
|
||||||
* in host capabilities */
|
|
||||||
};
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
virCPUDefIsEqual(virCPUDefPtr src,
|
virCPUDefIsEqual(virCPUDefPtr src,
|
||||||
virCPUDefPtr dst);
|
virCPUDefPtr dst);
|
||||||
|
|
||||||
char *
|
char *
|
||||||
virCPUDefFormat(virCPUDefPtr def,
|
virCPUDefFormat(virCPUDefPtr def);
|
||||||
const char *indent,
|
|
||||||
unsigned int flags);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
virCPUDefFormatBuf(virBufferPtr buf,
|
virCPUDefFormatBuf(virBufferPtr buf,
|
||||||
virCPUDefPtr def,
|
virCPUDefPtr def);
|
||||||
const char *indent,
|
int
|
||||||
unsigned int flags);
|
virCPUDefFormatBufFull(virBufferPtr buf,
|
||||||
|
virCPUDefPtr def);
|
||||||
|
|
||||||
int
|
int
|
||||||
virCPUDefAddFeature(virCPUDefPtr cpu,
|
virCPUDefAddFeature(virCPUDefPtr cpu,
|
||||||
|
@ -10825,8 +10825,10 @@ virDomainDefFormatInternal(virDomainDefPtr def,
|
|||||||
virBufferAddLit(buf, " </features>\n");
|
virBufferAddLit(buf, " </features>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virCPUDefFormatBuf(buf, def->cpu, " ", 0) < 0)
|
virBufferAdjustIndent(buf, 2);
|
||||||
|
if (virCPUDefFormatBufFull(buf, def->cpu) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
virBufferAdjustIndent(buf, -2);
|
||||||
|
|
||||||
virBufferAsprintf(buf, " <clock offset='%s'",
|
virBufferAsprintf(buf, " <clock offset='%s'",
|
||||||
virDomainClockOffsetTypeToString(def->clock.offset));
|
virDomainClockOffsetTypeToString(def->clock.offset));
|
||||||
|
@ -320,7 +320,7 @@ cpuBaselineXML(const char **xmlCPUs,
|
|||||||
if (!(cpu = cpuBaseline(cpus, ncpus, models, nmodels)))
|
if (!(cpu = cpuBaseline(cpus, ncpus, models, nmodels)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
cpustr = virCPUDefFormat(cpu, "", 0);
|
cpustr = virCPUDefFormat(cpu);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (cpus) {
|
if (cpus) {
|
||||||
|
@ -176,7 +176,7 @@ cpuTestCompareXML(const char *arch,
|
|||||||
if (virtTestLoadFile(xml, &expected) < 0)
|
if (virtTestLoadFile(xml, &expected) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(actual = virCPUDefFormat(cpu, NULL, 0)))
|
if (!(actual = virCPUDefFormat(cpu)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (STRNEQ(expected, actual)) {
|
if (STRNEQ(expected, actual)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user