mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 14:35:25 +00:00
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:
parent
2b8090b701
commit
e34473c1da
@ -867,7 +867,7 @@ virCapabilitiesFormatXML(virCapsPtr caps)
|
|||||||
virBufferAdjustIndent(&buf, -2);
|
virBufferAdjustIndent(&buf, -2);
|
||||||
virBufferAddLit(&buf, "</features>\n");
|
virBufferAddLit(&buf, "</features>\n");
|
||||||
}
|
}
|
||||||
virCPUDefFormatBuf(&buf, caps->host.cpu, 0);
|
virCPUDefFormatBuf(&buf, caps->host.cpu, false);
|
||||||
|
|
||||||
for (i = 0; i < caps->host.nPagesSize; i++) {
|
for (i = 0; i < caps->host.nPagesSize; i++) {
|
||||||
virBufferAsprintf(&buf, "<pages unit='KiB' size='%u'/>\n",
|
virBufferAsprintf(&buf, "<pages unit='KiB' size='%u'/>\n",
|
||||||
|
@ -532,11 +532,11 @@ virCPUDefParseXML(xmlNodePtr node,
|
|||||||
|
|
||||||
char *
|
char *
|
||||||
virCPUDefFormat(virCPUDefPtr def,
|
virCPUDefFormat(virCPUDefPtr def,
|
||||||
unsigned int flags)
|
bool updateCPU)
|
||||||
{
|
{
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
if (virCPUDefFormatBufFull(&buf, def, flags) < 0)
|
if (virCPUDefFormatBufFull(&buf, def, updateCPU) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virBufferCheckError(&buf) < 0)
|
if (virBufferCheckError(&buf) < 0)
|
||||||
@ -553,7 +553,7 @@ virCPUDefFormat(virCPUDefPtr def,
|
|||||||
int
|
int
|
||||||
virCPUDefFormatBufFull(virBufferPtr buf,
|
virCPUDefFormatBufFull(virBufferPtr buf,
|
||||||
virCPUDefPtr def,
|
virCPUDefPtr def,
|
||||||
unsigned int flags)
|
bool updateCPU)
|
||||||
{
|
{
|
||||||
if (!def)
|
if (!def)
|
||||||
return 0;
|
return 0;
|
||||||
@ -573,7 +573,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
|
|||||||
|
|
||||||
if (def->model &&
|
if (def->model &&
|
||||||
(def->mode == VIR_CPU_MODE_CUSTOM ||
|
(def->mode == VIR_CPU_MODE_CUSTOM ||
|
||||||
(flags & VIR_DOMAIN_XML_UPDATE_CPU))) {
|
updateCPU)) {
|
||||||
if (!(tmp = virCPUMatchTypeToString(def->match))) {
|
if (!(tmp = virCPUMatchTypeToString(def->match))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Unexpected CPU match policy %d"),
|
_("Unexpected CPU match policy %d"),
|
||||||
@ -589,7 +589,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
|
|||||||
if (def->arch)
|
if (def->arch)
|
||||||
virBufferAsprintf(buf, "<arch>%s</arch>\n",
|
virBufferAsprintf(buf, "<arch>%s</arch>\n",
|
||||||
virArchToString(def->arch));
|
virArchToString(def->arch));
|
||||||
if (virCPUDefFormatBuf(buf, def, flags) < 0)
|
if (virCPUDefFormatBuf(buf, def, updateCPU) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
virBufferAdjustIndent(buf, -2);
|
virBufferAdjustIndent(buf, -2);
|
||||||
|
|
||||||
@ -601,7 +601,7 @@ virCPUDefFormatBufFull(virBufferPtr buf,
|
|||||||
int
|
int
|
||||||
virCPUDefFormatBuf(virBufferPtr buf,
|
virCPUDefFormatBuf(virBufferPtr buf,
|
||||||
virCPUDefPtr def,
|
virCPUDefPtr def,
|
||||||
unsigned int flags)
|
bool updateCPU)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
bool formatModel;
|
bool formatModel;
|
||||||
@ -612,7 +612,7 @@ virCPUDefFormatBuf(virBufferPtr buf,
|
|||||||
|
|
||||||
formatModel = (def->mode == VIR_CPU_MODE_CUSTOM ||
|
formatModel = (def->mode == VIR_CPU_MODE_CUSTOM ||
|
||||||
def->mode == VIR_CPU_MODE_HOST_MODEL ||
|
def->mode == VIR_CPU_MODE_HOST_MODEL ||
|
||||||
(flags & VIR_DOMAIN_XML_UPDATE_CPU));
|
updateCPU);
|
||||||
formatFallback = (def->type == VIR_CPU_TYPE_GUEST &&
|
formatFallback = (def->type == VIR_CPU_TYPE_GUEST &&
|
||||||
(def->mode == VIR_CPU_MODE_HOST_MODEL ||
|
(def->mode == VIR_CPU_MODE_HOST_MODEL ||
|
||||||
(def->mode == VIR_CPU_MODE_CUSTOM && def->model)));
|
(def->mode == VIR_CPU_MODE_CUSTOM && def->model)));
|
||||||
|
@ -158,16 +158,16 @@ virCPUDefIsEqual(virCPUDefPtr src,
|
|||||||
|
|
||||||
char *
|
char *
|
||||||
virCPUDefFormat(virCPUDefPtr def,
|
virCPUDefFormat(virCPUDefPtr def,
|
||||||
unsigned int flags);
|
bool updateCPU);
|
||||||
|
|
||||||
int
|
int
|
||||||
virCPUDefFormatBuf(virBufferPtr buf,
|
virCPUDefFormatBuf(virBufferPtr buf,
|
||||||
virCPUDefPtr def,
|
virCPUDefPtr def,
|
||||||
unsigned int flags);
|
bool updateCPU);
|
||||||
int
|
int
|
||||||
virCPUDefFormatBufFull(virBufferPtr buf,
|
virCPUDefFormatBufFull(virBufferPtr buf,
|
||||||
virCPUDefPtr def,
|
virCPUDefPtr def,
|
||||||
unsigned int flags);
|
bool updateCPU);
|
||||||
|
|
||||||
int
|
int
|
||||||
virCPUDefAddFeature(virCPUDefPtr cpu,
|
virCPUDefAddFeature(virCPUDefPtr cpu,
|
||||||
|
@ -19882,7 +19882,8 @@ virDomainDefFormatInternal(virDomainDefPtr def,
|
|||||||
virBufferAddLit(buf, "</features>\n");
|
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;
|
goto error;
|
||||||
|
|
||||||
virBufferAsprintf(buf, "<clock offset='%s'",
|
virBufferAsprintf(buf, "<clock offset='%s'",
|
||||||
|
@ -472,7 +472,7 @@ cpuBaselineXML(const char **xmlCPUs,
|
|||||||
if (!(cpu = cpuBaseline(cpus, ncpus, models, nmodels, flags)))
|
if (!(cpu = cpuBaseline(cpus, ncpus, models, nmodels, flags)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
cpustr = virCPUDefFormat(cpu, 0);
|
cpustr = virCPUDefFormat(cpu, false);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (cpus) {
|
if (cpus) {
|
||||||
|
@ -153,7 +153,7 @@ static int
|
|||||||
cpuTestCompareXML(const char *arch,
|
cpuTestCompareXML(const char *arch,
|
||||||
virCPUDef *cpu,
|
virCPUDef *cpu,
|
||||||
const char *name,
|
const char *name,
|
||||||
unsigned int flags)
|
bool updateCPU)
|
||||||
{
|
{
|
||||||
char *xml = NULL;
|
char *xml = NULL;
|
||||||
char *expected = NULL;
|
char *expected = NULL;
|
||||||
@ -167,7 +167,7 @@ cpuTestCompareXML(const char *arch,
|
|||||||
if (virtTestLoadFile(xml, &expected) < 0)
|
if (virtTestLoadFile(xml, &expected) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(actual = virCPUDefFormat(cpu, flags)))
|
if (!(actual = virCPUDefFormat(cpu, updateCPU)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (STRNEQ(expected, actual)) {
|
if (STRNEQ(expected, actual)) {
|
||||||
@ -303,7 +303,7 @@ cpuTestGuestData(const void *arg)
|
|||||||
}
|
}
|
||||||
result = virBufferContentAndReset(&buf);
|
result = virBufferContentAndReset(&buf);
|
||||||
|
|
||||||
ret = cpuTestCompareXML(data->arch, guest, result, 0);
|
ret = cpuTestCompareXML(data->arch, guest, result, false);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(result);
|
VIR_FREE(result);
|
||||||
@ -351,7 +351,7 @@ cpuTestBaseline(const void *arg)
|
|||||||
if (virAsprintf(&result, "%s-%s", data->name, suffix) < 0)
|
if (virAsprintf(&result, "%s-%s", data->name, suffix) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (cpuTestCompareXML(data->arch, baseline, result, 0) < 0)
|
if (cpuTestCompareXML(data->arch, baseline, result, false) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0; i < ncpus; i++) {
|
for (i = 0; i < ncpus; i++) {
|
||||||
@ -403,8 +403,7 @@ cpuTestUpdate(const void *arg)
|
|||||||
if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0)
|
if (virAsprintf(&result, "%s+%s", data->host, data->name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = cpuTestCompareXML(data->arch, cpu, result,
|
ret = cpuTestCompareXML(data->arch, cpu, result, true);
|
||||||
VIR_DOMAIN_XML_UPDATE_CPU);
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virCPUDefFree(host);
|
virCPUDefFree(host);
|
||||||
|
Loading…
Reference in New Issue
Block a user