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:
Laine Stump 2014-03-06 16:50:15 +02:00
parent d3679928b1
commit 75f0b66c3a

View File

@ -1,7 +1,7 @@
/* /*
* capabilities.c: hypervisor capabilities * 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 * 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
@ -745,7 +745,7 @@ virCapabilitiesDefaultGuestEmulator(virCapsPtr caps,
} }
static int static int
virCapabilitiesFormatNUMATopology(virBufferPtr xml, virCapabilitiesFormatNUMATopology(virBufferPtr buf,
size_t ncells, size_t ncells,
virCapsHostNUMACellPtr *cells) virCapsHostNUMACellPtr *cells)
{ {
@ -753,21 +753,23 @@ virCapabilitiesFormatNUMATopology(virBufferPtr xml,
size_t j; size_t j;
char *siblings; char *siblings;
virBufferAddLit(xml, " <topology>\n"); virBufferAddLit(buf, "<topology>\n");
virBufferAsprintf(xml, " <cells num='%zu'>\n", ncells); virBufferAdjustIndent(buf, 2);
virBufferAsprintf(buf, "<cells num='%zu'>\n", ncells);
virBufferAdjustIndent(buf, 2);
for (i = 0; i < ncells; i++) { 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 */ /* Print out the numacell memory total if it is available */
if (cells[i]->mem) if (cells[i]->mem)
virBufferAsprintf(xml, virBufferAsprintf(buf, "<memory unit='KiB'>%llu</memory>\n",
" <memory unit='KiB'>%llu</memory>\n",
cells[i]->mem); 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++) { for (j = 0; j < cells[i]->ncpus; j++) {
virBufferAsprintf(xml, " <cpu id='%d'", virBufferAsprintf(buf, "<cpu id='%d'", cells[i]->cpus[j].id);
cells[i]->cpus[j].id);
if (cells[i]->cpus[j].siblings) { if (cells[i]->cpus[j].siblings) {
if (!(siblings = virBitmapFormat(cells[i]->cpus[j].siblings))) { if (!(siblings = virBitmapFormat(cells[i]->cpus[j].siblings))) {
@ -775,22 +777,24 @@ virCapabilitiesFormatNUMATopology(virBufferPtr xml,
return -1; return -1;
} }
virBufferAsprintf(xml, virBufferAsprintf(buf,
" socket_id='%d' core_id='%d' siblings='%s'", " socket_id='%d' core_id='%d' siblings='%s'",
cells[i]->cpus[j].socket_id, cells[i]->cpus[j].socket_id,
cells[i]->cpus[j].core_id, cells[i]->cpus[j].core_id,
siblings); siblings);
VIR_FREE(siblings); VIR_FREE(siblings);
} }
virBufferAddLit(xml, "/>\n"); virBufferAddLit(buf, "/>\n");
} }
virBufferAdjustIndent(buf, -2);
virBufferAddLit(xml, " </cpus>\n"); virBufferAddLit(buf, "</cpus>\n");
virBufferAddLit(xml, " </cell>\n"); virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</cell>\n");
} }
virBufferAddLit(xml, " </cells>\n"); virBufferAdjustIndent(buf, -2);
virBufferAddLit(xml, " </topology>\n"); virBufferAddLit(buf, "</cells>\n");
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</topology>\n");
return 0; return 0;
} }
@ -805,142 +809,160 @@ virCapabilitiesFormatNUMATopology(virBufferPtr xml,
char * char *
virCapabilitiesFormatXML(virCapsPtr caps) virCapabilitiesFormatXML(virCapsPtr caps)
{ {
virBuffer xml = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
size_t i, j, k; size_t i, j, k;
char host_uuid[VIR_UUID_STRING_BUFLEN]; char host_uuid[VIR_UUID_STRING_BUFLEN];
virBufferAddLit(&xml, "<capabilities>\n\n"); virBufferAddLit(&buf, "<capabilities>\n\n");
virBufferAddLit(&xml, " <host>\n"); virBufferAdjustIndent(&buf, 2);
virBufferAddLit(&buf, "<host>\n");
virBufferAdjustIndent(&buf, 2);
if (virUUIDIsValid(caps->host.host_uuid)) { if (virUUIDIsValid(caps->host.host_uuid)) {
virUUIDFormat(caps->host.host_uuid, 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"); virBufferAddLit(&buf, "<cpu>\n");
if (caps->host.arch) virBufferAdjustIndent(&buf, 2);
virBufferAsprintf(&xml, " <arch>%s</arch>\n",
virArchToString(caps->host.arch));
if (caps->host.arch)
virBufferAsprintf(&buf, "<arch>%s</arch>\n",
virArchToString(caps->host.arch));
if (caps->host.nfeatures) { if (caps->host.nfeatures) {
virBufferAddLit(&xml, " <features>\n"); virBufferAddLit(&buf, "<features>\n");
virBufferAdjustIndent(&buf, 2);
for (i = 0; i < caps->host.nfeatures; i++) { for (i = 0; i < caps->host.nfeatures; i++) {
virBufferAsprintf(&xml, " <%s/>\n", virBufferAsprintf(&buf, "<%s/>\n",
caps->host.features[i]); caps->host.features[i]);
} }
virBufferAddLit(&xml, " </features>\n"); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</features>\n");
} }
virCPUDefFormatBuf(&buf, caps->host.cpu, 0);
virBufferAdjustIndent(&xml, 6); virBufferAdjustIndent(&buf, -2);
virCPUDefFormatBuf(&xml, caps->host.cpu, 0); virBufferAddLit(&buf, "</cpu>\n");
virBufferAdjustIndent(&xml, -6);
virBufferAddLit(&xml, " </cpu>\n");
/* The PM query was successful. */ /* The PM query was successful. */
if (caps->host.powerMgmt) { if (caps->host.powerMgmt) {
/* The host supports some PM features. */ /* The host supports some PM features. */
unsigned int pm = caps->host.powerMgmt; unsigned int pm = caps->host.powerMgmt;
virBufferAddLit(&xml, " <power_management>\n"); virBufferAddLit(&buf, "<power_management>\n");
virBufferAdjustIndent(&buf, 2);
while (pm) { while (pm) {
int bit = ffs(pm) - 1; int bit = ffs(pm) - 1;
virBufferAsprintf(&xml, " <%s/>\n", virBufferAsprintf(&buf, "<%s/>\n",
virCapsHostPMTargetTypeToString(bit)); virCapsHostPMTargetTypeToString(bit));
pm &= ~(1U << bit); pm &= ~(1U << bit);
} }
virBufferAddLit(&xml, " </power_management>\n"); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</power_management>\n");
} else { } else {
/* The host does not support any PM feature. */ /* The host does not support any PM feature. */
virBufferAddLit(&xml, " <power_management/>\n"); virBufferAddLit(&buf, "<power_management/>\n");
} }
if (caps->host.offlineMigrate) { if (caps->host.offlineMigrate) {
virBufferAddLit(&xml, " <migration_features>\n"); virBufferAddLit(&buf, "<migration_features>\n");
virBufferAdjustIndent(&buf, 2);
if (caps->host.liveMigrate) if (caps->host.liveMigrate)
virBufferAddLit(&xml, " <live/>\n"); virBufferAddLit(&buf, "<live/>\n");
if (caps->host.nmigrateTrans) { 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++) { 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]); 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 && if (caps->host.nnumaCell &&
virCapabilitiesFormatNUMATopology(&xml, caps->host.nnumaCell, virCapabilitiesFormatNUMATopology(&buf, caps->host.nnumaCell,
caps->host.numaCell) < 0) caps->host.numaCell) < 0)
return NULL; return NULL;
for (i = 0; i < caps->host.nsecModels; i++) { for (i = 0; i < caps->host.nsecModels; i++) {
virBufferAddLit(&xml, " <secmodel>\n"); virBufferAddLit(&buf, "<secmodel>\n");
virBufferAsprintf(&xml, " <model>%s</model>\n", virBufferAdjustIndent(&buf, 2);
virBufferAsprintf(&buf, "<model>%s</model>\n",
caps->host.secModels[i].model); caps->host.secModels[i].model);
virBufferAsprintf(&xml, " <doi>%s</doi>\n", virBufferAsprintf(&buf, "<doi>%s</doi>\n",
caps->host.secModels[i].doi); caps->host.secModels[i].doi);
for (j = 0; j < caps->host.secModels[i].nlabels; j++) { 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].type,
caps->host.secModels[i].labels[j].label); 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++) { for (i = 0; i < caps->nguests; i++) {
virBufferAddLit(&xml, " <guest>\n"); virBufferAddLit(&buf, "<guest>\n");
virBufferAsprintf(&xml, " <os_type>%s</os_type>\n", virBufferAdjustIndent(&buf, 2);
virBufferAsprintf(&buf, "<os_type>%s</os_type>\n",
caps->guests[i]->ostype); caps->guests[i]->ostype);
if (caps->guests[i]->arch.id) if (caps->guests[i]->arch.id)
virBufferAsprintf(&xml, " <arch name='%s'>\n", virBufferAsprintf(&buf, "<arch name='%s'>\n",
virArchToString(caps->guests[i]->arch.id)); 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); caps->guests[i]->arch.wordsize);
if (caps->guests[i]->arch.defaultInfo.emulator) 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); caps->guests[i]->arch.defaultInfo.emulator);
if (caps->guests[i]->arch.defaultInfo.loader) 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); caps->guests[i]->arch.defaultInfo.loader);
for (j = 0; j < caps->guests[i]->arch.defaultInfo.nmachines; j++) { for (j = 0; j < caps->guests[i]->arch.defaultInfo.nmachines; j++) {
virCapsGuestMachinePtr machine = caps->guests[i]->arch.defaultInfo.machines[j]; virCapsGuestMachinePtr machine = caps->guests[i]->arch.defaultInfo.machines[j];
virBufferAddLit(&xml, " <machine"); virBufferAddLit(&buf, "<machine");
if (machine->canonical) if (machine->canonical)
virBufferAsprintf(&xml, " canonical='%s'", machine->canonical); virBufferAsprintf(&buf, " canonical='%s'", machine->canonical);
if (machine->maxCpus > 0) if (machine->maxCpus > 0)
virBufferAsprintf(&xml, " maxCpus='%d'", machine->maxCpus); virBufferAsprintf(&buf, " maxCpus='%d'", machine->maxCpus);
virBufferAsprintf(&xml, ">%s</machine>\n", machine->name); virBufferAsprintf(&buf, ">%s</machine>\n", machine->name);
} }
for (j = 0; j < caps->guests[i]->arch.ndomains; j++) { 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); caps->guests[i]->arch.domains[j]->type);
virBufferAdjustIndent(&buf, 2);
if (caps->guests[i]->arch.domains[j]->info.emulator) 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); caps->guests[i]->arch.domains[j]->info.emulator);
if (caps->guests[i]->arch.domains[j]->info.loader) 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); caps->guests[i]->arch.domains[j]->info.loader);
for (k = 0; k < caps->guests[i]->arch.domains[j]->info.nmachines; k++) { for (k = 0; k < caps->guests[i]->arch.domains[j]->info.nmachines; k++) {
virCapsGuestMachinePtr machine = caps->guests[i]->arch.domains[j]->info.machines[k]; virCapsGuestMachinePtr machine = caps->guests[i]->arch.domains[j]->info.machines[k];
virBufferAddLit(&xml, " <machine"); virBufferAddLit(&buf, "<machine");
if (machine->canonical) if (machine->canonical)
virBufferAsprintf(&xml, " canonical='%s'", machine->canonical); virBufferAsprintf(&buf, " canonical='%s'", machine->canonical);
if (machine->maxCpus > 0) if (machine->maxCpus > 0)
virBufferAsprintf(&xml, " maxCpus='%d'", machine->maxCpus); virBufferAsprintf(&buf, " maxCpus='%d'", machine->maxCpus);
virBufferAsprintf(&xml, ">%s</machine>\n", machine->name); 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) { 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++) { for (j = 0; j < caps->guests[i]->nfeatures; j++) {
if (STREQ(caps->guests[i]->features[j]->name, "pae") || 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, "ia64_be") ||
STREQ(caps->guests[i]->features[j]->name, "cpuselection") || STREQ(caps->guests[i]->features[j]->name, "cpuselection") ||
STREQ(caps->guests[i]->features[j]->name, "deviceboot")) { STREQ(caps->guests[i]->features[j]->name, "deviceboot")) {
virBufferAsprintf(&xml, " <%s/>\n", virBufferAsprintf(&buf, "<%s/>\n",
caps->guests[i]->features[j]->name); caps->guests[i]->features[j]->name);
} else { } 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]->name,
caps->guests[i]->features[j]->defaultOn ? "on" : "off", caps->guests[i]->features[j]->defaultOn ? "on" : "off",
caps->guests[i]->features[j]->toggle ? "yes" : "no"); caps->guests[i]->features[j]->toggle ? "yes" : "no");
} }
} }
virBufferAddLit(&xml, " </features>\n"); virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</features>\n");
} }
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&xml, " </guest>\n\n"); virBufferAddLit(&buf, "</guest>\n\n");
} }
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</capabilities>\n");
virBufferAddLit(&xml, "</capabilities>\n"); if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
if (virBufferError(&xml)) {
virBufferFreeAndReset(&xml);
return NULL; return NULL;
} }
return virBufferContentAndReset(&xml); return virBufferContentAndReset(&buf);
} }
/* get the maximum ID of cpus in the host */ /* get the maximum ID of cpus in the host */