mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
conf: eliminate hardcoded indentation in capabilities xml
There were a lot of changes here, but all very mechanical. For some reason, the virBufferPtr had been named "xml" instead of "buf" in this file, so since the indentation changing touched almost every line using the buffer, I took this chance to change its name for "buf" for consistency with every other file.
This commit is contained in:
parent
d3679928b1
commit
75f0b66c3a
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* capabilities.c: hypervisor capabilities
|
||||
*
|
||||
* Copyright (C) 2006-2008, 2010-2011, 2013 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2014 Red Hat, Inc.
|
||||
* Copyright (C) 2006-2008 Daniel P. Berrange
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
@ -745,7 +745,7 @@ virCapabilitiesDefaultGuestEmulator(virCapsPtr caps,
|
||||
}
|
||||
|
||||
static int
|
||||
virCapabilitiesFormatNUMATopology(virBufferPtr xml,
|
||||
virCapabilitiesFormatNUMATopology(virBufferPtr buf,
|
||||
size_t ncells,
|
||||
virCapsHostNUMACellPtr *cells)
|
||||
{
|
||||
@ -753,21 +753,23 @@ virCapabilitiesFormatNUMATopology(virBufferPtr xml,
|
||||
size_t j;
|
||||
char *siblings;
|
||||
|
||||
virBufferAddLit(xml, " <topology>\n");
|
||||
virBufferAsprintf(xml, " <cells num='%zu'>\n", ncells);
|
||||
virBufferAddLit(buf, "<topology>\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
virBufferAsprintf(buf, "<cells num='%zu'>\n", ncells);
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
for (i = 0; i < ncells; i++) {
|
||||
virBufferAsprintf(xml, " <cell id='%d'>\n", cells[i]->num);
|
||||
virBufferAsprintf(buf, "<cell id='%d'>\n", cells[i]->num);
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
|
||||
/* Print out the numacell memory total if it is available */
|
||||
if (cells[i]->mem)
|
||||
virBufferAsprintf(xml,
|
||||
" <memory unit='KiB'>%llu</memory>\n",
|
||||
virBufferAsprintf(buf, "<memory unit='KiB'>%llu</memory>\n",
|
||||
cells[i]->mem);
|
||||
|
||||
virBufferAsprintf(xml, " <cpus num='%d'>\n", cells[i]->ncpus);
|
||||
virBufferAsprintf(buf, "<cpus num='%d'>\n", cells[i]->ncpus);
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
for (j = 0; j < cells[i]->ncpus; j++) {
|
||||
virBufferAsprintf(xml, " <cpu id='%d'",
|
||||
cells[i]->cpus[j].id);
|
||||
virBufferAsprintf(buf, "<cpu id='%d'", cells[i]->cpus[j].id);
|
||||
|
||||
if (cells[i]->cpus[j].siblings) {
|
||||
if (!(siblings = virBitmapFormat(cells[i]->cpus[j].siblings))) {
|
||||
@ -775,22 +777,24 @@ virCapabilitiesFormatNUMATopology(virBufferPtr xml,
|
||||
return -1;
|
||||
}
|
||||
|
||||
virBufferAsprintf(xml,
|
||||
virBufferAsprintf(buf,
|
||||
" socket_id='%d' core_id='%d' siblings='%s'",
|
||||
cells[i]->cpus[j].socket_id,
|
||||
cells[i]->cpus[j].core_id,
|
||||
siblings);
|
||||
VIR_FREE(siblings);
|
||||
}
|
||||
virBufferAddLit(xml, "/>\n");
|
||||
virBufferAddLit(buf, "/>\n");
|
||||
}
|
||||
|
||||
virBufferAddLit(xml, " </cpus>\n");
|
||||
virBufferAddLit(xml, " </cell>\n");
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</cpus>\n");
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</cell>\n");
|
||||
}
|
||||
virBufferAddLit(xml, " </cells>\n");
|
||||
virBufferAddLit(xml, " </topology>\n");
|
||||
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</cells>\n");
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</topology>\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -805,142 +809,160 @@ virCapabilitiesFormatNUMATopology(virBufferPtr xml,
|
||||
char *
|
||||
virCapabilitiesFormatXML(virCapsPtr caps)
|
||||
{
|
||||
virBuffer xml = VIR_BUFFER_INITIALIZER;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
size_t i, j, k;
|
||||
char host_uuid[VIR_UUID_STRING_BUFLEN];
|
||||
|
||||
virBufferAddLit(&xml, "<capabilities>\n\n");
|
||||
virBufferAddLit(&xml, " <host>\n");
|
||||
virBufferAddLit(&buf, "<capabilities>\n\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
virBufferAddLit(&buf, "<host>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
if (virUUIDIsValid(caps->host.host_uuid)) {
|
||||
virUUIDFormat(caps->host.host_uuid, host_uuid);
|
||||
virBufferAsprintf(&xml, " <uuid>%s</uuid>\n", host_uuid);
|
||||
virBufferAsprintf(&buf, "<uuid>%s</uuid>\n", host_uuid);
|
||||
}
|
||||
virBufferAddLit(&xml, " <cpu>\n");
|
||||
if (caps->host.arch)
|
||||
virBufferAsprintf(&xml, " <arch>%s</arch>\n",
|
||||
virArchToString(caps->host.arch));
|
||||
virBufferAddLit(&buf, "<cpu>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
|
||||
if (caps->host.arch)
|
||||
virBufferAsprintf(&buf, "<arch>%s</arch>\n",
|
||||
virArchToString(caps->host.arch));
|
||||
if (caps->host.nfeatures) {
|
||||
virBufferAddLit(&xml, " <features>\n");
|
||||
virBufferAddLit(&buf, "<features>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
for (i = 0; i < caps->host.nfeatures; i++) {
|
||||
virBufferAsprintf(&xml, " <%s/>\n",
|
||||
virBufferAsprintf(&buf, "<%s/>\n",
|
||||
caps->host.features[i]);
|
||||
}
|
||||
virBufferAddLit(&xml, " </features>\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</features>\n");
|
||||
}
|
||||
virCPUDefFormatBuf(&buf, caps->host.cpu, 0);
|
||||
|
||||
virBufferAdjustIndent(&xml, 6);
|
||||
virCPUDefFormatBuf(&xml, caps->host.cpu, 0);
|
||||
virBufferAdjustIndent(&xml, -6);
|
||||
|
||||
virBufferAddLit(&xml, " </cpu>\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</cpu>\n");
|
||||
|
||||
/* The PM query was successful. */
|
||||
if (caps->host.powerMgmt) {
|
||||
/* The host supports some PM features. */
|
||||
unsigned int pm = caps->host.powerMgmt;
|
||||
virBufferAddLit(&xml, " <power_management>\n");
|
||||
virBufferAddLit(&buf, "<power_management>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
while (pm) {
|
||||
int bit = ffs(pm) - 1;
|
||||
virBufferAsprintf(&xml, " <%s/>\n",
|
||||
virBufferAsprintf(&buf, "<%s/>\n",
|
||||
virCapsHostPMTargetTypeToString(bit));
|
||||
pm &= ~(1U << bit);
|
||||
}
|
||||
virBufferAddLit(&xml, " </power_management>\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</power_management>\n");
|
||||
} else {
|
||||
/* The host does not support any PM feature. */
|
||||
virBufferAddLit(&xml, " <power_management/>\n");
|
||||
virBufferAddLit(&buf, "<power_management/>\n");
|
||||
}
|
||||
|
||||
if (caps->host.offlineMigrate) {
|
||||
virBufferAddLit(&xml, " <migration_features>\n");
|
||||
virBufferAddLit(&buf, "<migration_features>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
if (caps->host.liveMigrate)
|
||||
virBufferAddLit(&xml, " <live/>\n");
|
||||
virBufferAddLit(&buf, "<live/>\n");
|
||||
if (caps->host.nmigrateTrans) {
|
||||
virBufferAddLit(&xml, " <uri_transports>\n");
|
||||
virBufferAddLit(&buf, "<uri_transports>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
for (i = 0; i < caps->host.nmigrateTrans; i++) {
|
||||
virBufferAsprintf(&xml, " <uri_transport>%s</uri_transport>\n",
|
||||
virBufferAsprintf(&buf, "<uri_transport>%s</uri_transport>\n",
|
||||
caps->host.migrateTrans[i]);
|
||||
}
|
||||
virBufferAddLit(&xml, " </uri_transports>\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</uri_transports>\n");
|
||||
}
|
||||
virBufferAddLit(&xml, " </migration_features>\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</migration_features>\n");
|
||||
}
|
||||
|
||||
if (caps->host.nnumaCell &&
|
||||
virCapabilitiesFormatNUMATopology(&xml, caps->host.nnumaCell,
|
||||
virCapabilitiesFormatNUMATopology(&buf, caps->host.nnumaCell,
|
||||
caps->host.numaCell) < 0)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < caps->host.nsecModels; i++) {
|
||||
virBufferAddLit(&xml, " <secmodel>\n");
|
||||
virBufferAsprintf(&xml, " <model>%s</model>\n",
|
||||
virBufferAddLit(&buf, "<secmodel>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
virBufferAsprintf(&buf, "<model>%s</model>\n",
|
||||
caps->host.secModels[i].model);
|
||||
virBufferAsprintf(&xml, " <doi>%s</doi>\n",
|
||||
virBufferAsprintf(&buf, "<doi>%s</doi>\n",
|
||||
caps->host.secModels[i].doi);
|
||||
for (j = 0; j < caps->host.secModels[i].nlabels; j++) {
|
||||
virBufferAsprintf(&xml, " <baselabel type='%s'>%s</baselabel>\n",
|
||||
virBufferAsprintf(&buf, "<baselabel type='%s'>%s</baselabel>\n",
|
||||
caps->host.secModels[i].labels[j].type,
|
||||
caps->host.secModels[i].labels[j].label);
|
||||
}
|
||||
virBufferAddLit(&xml, " </secmodel>\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</secmodel>\n");
|
||||
}
|
||||
|
||||
virBufferAddLit(&xml, " </host>\n\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</host>\n\n");
|
||||
|
||||
|
||||
for (i = 0; i < caps->nguests; i++) {
|
||||
virBufferAddLit(&xml, " <guest>\n");
|
||||
virBufferAsprintf(&xml, " <os_type>%s</os_type>\n",
|
||||
virBufferAddLit(&buf, "<guest>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
virBufferAsprintf(&buf, "<os_type>%s</os_type>\n",
|
||||
caps->guests[i]->ostype);
|
||||
if (caps->guests[i]->arch.id)
|
||||
virBufferAsprintf(&xml, " <arch name='%s'>\n",
|
||||
virBufferAsprintf(&buf, "<arch name='%s'>\n",
|
||||
virArchToString(caps->guests[i]->arch.id));
|
||||
virBufferAsprintf(&xml, " <wordsize>%d</wordsize>\n",
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
virBufferAsprintf(&buf, "<wordsize>%d</wordsize>\n",
|
||||
caps->guests[i]->arch.wordsize);
|
||||
if (caps->guests[i]->arch.defaultInfo.emulator)
|
||||
virBufferAsprintf(&xml, " <emulator>%s</emulator>\n",
|
||||
virBufferAsprintf(&buf, "<emulator>%s</emulator>\n",
|
||||
caps->guests[i]->arch.defaultInfo.emulator);
|
||||
if (caps->guests[i]->arch.defaultInfo.loader)
|
||||
virBufferAsprintf(&xml, " <loader>%s</loader>\n",
|
||||
virBufferAsprintf(&buf, "<loader>%s</loader>\n",
|
||||
caps->guests[i]->arch.defaultInfo.loader);
|
||||
|
||||
for (j = 0; j < caps->guests[i]->arch.defaultInfo.nmachines; j++) {
|
||||
virCapsGuestMachinePtr machine = caps->guests[i]->arch.defaultInfo.machines[j];
|
||||
virBufferAddLit(&xml, " <machine");
|
||||
virBufferAddLit(&buf, "<machine");
|
||||
if (machine->canonical)
|
||||
virBufferAsprintf(&xml, " canonical='%s'", machine->canonical);
|
||||
virBufferAsprintf(&buf, " canonical='%s'", machine->canonical);
|
||||
if (machine->maxCpus > 0)
|
||||
virBufferAsprintf(&xml, " maxCpus='%d'", machine->maxCpus);
|
||||
virBufferAsprintf(&xml, ">%s</machine>\n", machine->name);
|
||||
virBufferAsprintf(&buf, " maxCpus='%d'", machine->maxCpus);
|
||||
virBufferAsprintf(&buf, ">%s</machine>\n", machine->name);
|
||||
}
|
||||
|
||||
for (j = 0; j < caps->guests[i]->arch.ndomains; j++) {
|
||||
virBufferAsprintf(&xml, " <domain type='%s'>\n",
|
||||
virBufferAsprintf(&buf, "<domain type='%s'>\n",
|
||||
caps->guests[i]->arch.domains[j]->type);
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
if (caps->guests[i]->arch.domains[j]->info.emulator)
|
||||
virBufferAsprintf(&xml, " <emulator>%s</emulator>\n",
|
||||
virBufferAsprintf(&buf, "<emulator>%s</emulator>\n",
|
||||
caps->guests[i]->arch.domains[j]->info.emulator);
|
||||
if (caps->guests[i]->arch.domains[j]->info.loader)
|
||||
virBufferAsprintf(&xml, " <loader>%s</loader>\n",
|
||||
virBufferAsprintf(&buf, "<loader>%s</loader>\n",
|
||||
caps->guests[i]->arch.domains[j]->info.loader);
|
||||
|
||||
for (k = 0; k < caps->guests[i]->arch.domains[j]->info.nmachines; k++) {
|
||||
virCapsGuestMachinePtr machine = caps->guests[i]->arch.domains[j]->info.machines[k];
|
||||
virBufferAddLit(&xml, " <machine");
|
||||
virBufferAddLit(&buf, "<machine");
|
||||
if (machine->canonical)
|
||||
virBufferAsprintf(&xml, " canonical='%s'", machine->canonical);
|
||||
virBufferAsprintf(&buf, " canonical='%s'", machine->canonical);
|
||||
if (machine->maxCpus > 0)
|
||||
virBufferAsprintf(&xml, " maxCpus='%d'", machine->maxCpus);
|
||||
virBufferAsprintf(&xml, ">%s</machine>\n", machine->name);
|
||||
virBufferAsprintf(&buf, " maxCpus='%d'", machine->maxCpus);
|
||||
virBufferAsprintf(&buf, ">%s</machine>\n", machine->name);
|
||||
}
|
||||
virBufferAddLit(&xml, " </domain>\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</domain>\n");
|
||||
}
|
||||
|
||||
virBufferAddLit(&xml, " </arch>\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</arch>\n");
|
||||
|
||||
if (caps->guests[i]->nfeatures) {
|
||||
virBufferAddLit(&xml, " <features>\n");
|
||||
virBufferAddLit(&buf, "<features>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
|
||||
for (j = 0; j < caps->guests[i]->nfeatures; j++) {
|
||||
if (STREQ(caps->guests[i]->features[j]->name, "pae") ||
|
||||
@ -948,30 +970,31 @@ virCapabilitiesFormatXML(virCapsPtr caps)
|
||||
STREQ(caps->guests[i]->features[j]->name, "ia64_be") ||
|
||||
STREQ(caps->guests[i]->features[j]->name, "cpuselection") ||
|
||||
STREQ(caps->guests[i]->features[j]->name, "deviceboot")) {
|
||||
virBufferAsprintf(&xml, " <%s/>\n",
|
||||
virBufferAsprintf(&buf, "<%s/>\n",
|
||||
caps->guests[i]->features[j]->name);
|
||||
} else {
|
||||
virBufferAsprintf(&xml, " <%s default='%s' toggle='%s'/>\n",
|
||||
virBufferAsprintf(&buf, "<%s default='%s' toggle='%s'/>\n",
|
||||
caps->guests[i]->features[j]->name,
|
||||
caps->guests[i]->features[j]->defaultOn ? "on" : "off",
|
||||
caps->guests[i]->features[j]->toggle ? "yes" : "no");
|
||||
}
|
||||
}
|
||||
|
||||
virBufferAddLit(&xml, " </features>\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</features>\n");
|
||||
}
|
||||
|
||||
virBufferAddLit(&xml, " </guest>\n\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</guest>\n\n");
|
||||
}
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</capabilities>\n");
|
||||
|
||||
virBufferAddLit(&xml, "</capabilities>\n");
|
||||
|
||||
if (virBufferError(&xml)) {
|
||||
virBufferFreeAndReset(&xml);
|
||||
if (virBufferError(&buf)) {
|
||||
virBufferFreeAndReset(&buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return virBufferContentAndReset(&xml);
|
||||
return virBufferContentAndReset(&buf);
|
||||
}
|
||||
|
||||
/* get the maximum ID of cpus in the host */
|
||||
|
Loading…
Reference in New Issue
Block a user