From 75f0b66c3a15eeb305ba6223b30665383dd2dea5 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Thu, 6 Mar 2014 16:50:15 +0200 Subject: [PATCH] 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. --- src/conf/capabilities.c | 183 ++++++++++++++++++++++------------------ 1 file changed, 103 insertions(+), 80 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index c1c4ab8280..3022b45623 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -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, " \n"); - virBufferAsprintf(xml, " \n", ncells); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferAsprintf(buf, "\n", ncells); + virBufferAdjustIndent(buf, 2); for (i = 0; i < ncells; i++) { - virBufferAsprintf(xml, " \n", cells[i]->num); + virBufferAsprintf(buf, "\n", cells[i]->num); + virBufferAdjustIndent(buf, 2); /* Print out the numacell memory total if it is available */ if (cells[i]->mem) - virBufferAsprintf(xml, - " %llu\n", + virBufferAsprintf(buf, "%llu\n", cells[i]->mem); - virBufferAsprintf(xml, " \n", cells[i]->ncpus); + virBufferAsprintf(buf, "\n", cells[i]->ncpus); + virBufferAdjustIndent(buf, 2); for (j = 0; j < cells[i]->ncpus; j++) { - virBufferAsprintf(xml, " cpus[j].id); + virBufferAsprintf(buf, "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, " \n"); - virBufferAddLit(xml, " \n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } - virBufferAddLit(xml, " \n"); - virBufferAddLit(xml, " \n"); - + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\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, "\n\n"); - virBufferAddLit(&xml, " \n"); + virBufferAddLit(&buf, "\n\n"); + virBufferAdjustIndent(&buf, 2); + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); if (virUUIDIsValid(caps->host.host_uuid)) { virUUIDFormat(caps->host.host_uuid, host_uuid); - virBufferAsprintf(&xml, " %s\n", host_uuid); + virBufferAsprintf(&buf, "%s\n", host_uuid); } - virBufferAddLit(&xml, " \n"); + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); + if (caps->host.arch) - virBufferAsprintf(&xml, " %s\n", + virBufferAsprintf(&buf, "%s\n", virArchToString(caps->host.arch)); - if (caps->host.nfeatures) { - virBufferAddLit(&xml, " \n"); + virBufferAddLit(&buf, "\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, " \n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); } + virCPUDefFormatBuf(&buf, caps->host.cpu, 0); - virBufferAdjustIndent(&xml, 6); - virCPUDefFormatBuf(&xml, caps->host.cpu, 0); - virBufferAdjustIndent(&xml, -6); - - virBufferAddLit(&xml, " \n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); /* The PM query was successful. */ if (caps->host.powerMgmt) { /* The host supports some PM features. */ unsigned int pm = caps->host.powerMgmt; - virBufferAddLit(&xml, " \n"); + virBufferAddLit(&buf, "\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, " \n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); } else { /* The host does not support any PM feature. */ - virBufferAddLit(&xml, " \n"); + virBufferAddLit(&buf, "\n"); } if (caps->host.offlineMigrate) { - virBufferAddLit(&xml, " \n"); + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); if (caps->host.liveMigrate) - virBufferAddLit(&xml, " \n"); + virBufferAddLit(&buf, "\n"); if (caps->host.nmigrateTrans) { - virBufferAddLit(&xml, " \n"); + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); for (i = 0; i < caps->host.nmigrateTrans; i++) { - virBufferAsprintf(&xml, " %s\n", + virBufferAsprintf(&buf, "%s\n", caps->host.migrateTrans[i]); } - virBufferAddLit(&xml, " \n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); } - virBufferAddLit(&xml, " \n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\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, " \n"); - virBufferAsprintf(&xml, " %s\n", + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); + virBufferAsprintf(&buf, "%s\n", caps->host.secModels[i].model); - virBufferAsprintf(&xml, " %s\n", + virBufferAsprintf(&buf, "%s\n", caps->host.secModels[i].doi); for (j = 0; j < caps->host.secModels[i].nlabels; j++) { - virBufferAsprintf(&xml, " %s\n", + virBufferAsprintf(&buf, "%s\n", caps->host.secModels[i].labels[j].type, caps->host.secModels[i].labels[j].label); } - virBufferAddLit(&xml, " \n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); } - virBufferAddLit(&xml, " \n\n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n\n"); for (i = 0; i < caps->nguests; i++) { - virBufferAddLit(&xml, " \n"); - virBufferAsprintf(&xml, " %s\n", + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); + virBufferAsprintf(&buf, "%s\n", caps->guests[i]->ostype); if (caps->guests[i]->arch.id) - virBufferAsprintf(&xml, " \n", + virBufferAsprintf(&buf, "\n", virArchToString(caps->guests[i]->arch.id)); - virBufferAsprintf(&xml, " %d\n", + virBufferAdjustIndent(&buf, 2); + virBufferAsprintf(&buf, "%d\n", caps->guests[i]->arch.wordsize); if (caps->guests[i]->arch.defaultInfo.emulator) - virBufferAsprintf(&xml, " %s\n", + virBufferAsprintf(&buf, "%s\n", caps->guests[i]->arch.defaultInfo.emulator); if (caps->guests[i]->arch.defaultInfo.loader) - virBufferAsprintf(&xml, " %s\n", + virBufferAsprintf(&buf, "%s\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, " 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\n", machine->name); + virBufferAsprintf(&buf, " maxCpus='%d'", machine->maxCpus); + virBufferAsprintf(&buf, ">%s\n", machine->name); } for (j = 0; j < caps->guests[i]->arch.ndomains; j++) { - virBufferAsprintf(&xml, " \n", + virBufferAsprintf(&buf, "\n", caps->guests[i]->arch.domains[j]->type); + virBufferAdjustIndent(&buf, 2); if (caps->guests[i]->arch.domains[j]->info.emulator) - virBufferAsprintf(&xml, " %s\n", + virBufferAsprintf(&buf, "%s\n", caps->guests[i]->arch.domains[j]->info.emulator); if (caps->guests[i]->arch.domains[j]->info.loader) - virBufferAsprintf(&xml, " %s\n", + virBufferAsprintf(&buf, "%s\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, " 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\n", machine->name); + virBufferAsprintf(&buf, " maxCpus='%d'", machine->maxCpus); + virBufferAsprintf(&buf, ">%s\n", machine->name); } - virBufferAddLit(&xml, " \n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); } - virBufferAddLit(&xml, " \n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); if (caps->guests[i]->nfeatures) { - virBufferAddLit(&xml, " \n"); + virBufferAddLit(&buf, "\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, " \n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); } - - virBufferAddLit(&xml, " \n\n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n\n"); } + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); - virBufferAddLit(&xml, "\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 */ -- 2.39.5