From 5f845437720e4545f3160fb24991a1a31dd26e97 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Thu, 6 Mar 2014 16:57:47 +0200 Subject: [PATCH] conf: eliminate hardcoded indent in volume/pool xml Again completely mechanical, but a lot of lines. --- src/conf/storage_conf.c | 174 +++++++++++++++++------------ src/conf/storage_encryption_conf.c | 6 +- 2 files changed, 105 insertions(+), 75 deletions(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 39fb416b5a..230dc65be5 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1,7 +1,7 @@ /* * storage_conf.c: config handling for storage driver * - * Copyright (C) 2006-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 @@ -1068,10 +1068,12 @@ virStoragePoolSourceFormat(virBufferPtr buf, size_t i, j; char uuid[VIR_UUID_STRING_BUFLEN]; - virBufferAddLit(buf, " \n"); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + if ((options->flags & VIR_STORAGE_POOL_SOURCE_HOST) && src->nhost) { for (i = 0; i < src->nhost; i++) { - virBufferEscapeString(buf, " hosts[i].name); if (src->hosts[i].port) virBufferAsprintf(buf, " port='%d'", src->hosts[i].port); @@ -1083,28 +1085,30 @@ virStoragePoolSourceFormat(virBufferPtr buf, src->ndevice) { for (i = 0; i < src->ndevice; i++) { if (src->devices[i].nfreeExtent) { - virBufferEscapeString(buf, " \n", + virBufferEscapeString(buf, "\n", src->devices[i].path); + virBufferAdjustIndent(buf, 2); for (j = 0; j < src->devices[i].nfreeExtent; j++) { - virBufferAsprintf(buf, " \n", + virBufferAsprintf(buf, "\n", src->devices[i].freeExtents[j].start, src->devices[i].freeExtents[j].end); } - virBufferAddLit(buf, " \n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } else { - virBufferEscapeString(buf, " \n", + virBufferEscapeString(buf, "\n", src->devices[i].path); } } } if (options->flags & VIR_STORAGE_POOL_SOURCE_DIR) - virBufferEscapeString(buf, " \n", src->dir); + virBufferEscapeString(buf, "\n", src->dir); if ((options->flags & VIR_STORAGE_POOL_SOURCE_ADAPTER)) { if (src->adapter.type == VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST || src->adapter.type == VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) - virBufferAsprintf(buf, " adapter.type)); if (src->adapter.type == VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) { @@ -1120,14 +1124,16 @@ virStoragePoolSourceFormat(virBufferPtr buf, } if (options->flags & VIR_STORAGE_POOL_SOURCE_NAME) - virBufferEscapeString(buf, " %s\n", src->name); + virBufferEscapeString(buf, "%s\n", src->name); if ((options->flags & VIR_STORAGE_POOL_SOURCE_INITIATOR_IQN) && src->initiator.iqn) { - virBufferAddLit(buf, " \n"); - virBufferEscapeString(buf, " \n", + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferEscapeString(buf, "\n", src->initiator.iqn); - virBufferAddLit(buf, " \n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } if (options->formatToString) { @@ -1138,19 +1144,20 @@ virStoragePoolSourceFormat(virBufferPtr buf, src->format); return -1; } - virBufferAsprintf(buf, " \n", format); + virBufferAsprintf(buf, "\n", format); } if (src->authType == VIR_STORAGE_POOL_AUTH_CHAP || src->authType == VIR_STORAGE_POOL_AUTH_CEPHX) { - virBufferAsprintf(buf, " authType)); virBufferEscapeString(buf, "username='%s'>\n", (src->authType == VIR_STORAGE_POOL_AUTH_CHAP ? src->auth.chap.username : src->auth.cephx.username)); + virBufferAdjustIndent(buf, 2); - virBufferAddLit(buf, " auth.cephx.secret.uuidUsable) { virUUIDFormat(src->auth.cephx.secret.uuid, uuid); virBufferAsprintf(buf, " uuid='%s'", uuid); @@ -1161,14 +1168,15 @@ virStoragePoolSourceFormat(virBufferPtr buf, } virBufferAddLit(buf, "/>\n"); - virBufferAddLit(buf, " \n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } - virBufferEscapeString(buf, " \n", src->vendor); - virBufferEscapeString(buf, " \n", src->product); - - virBufferAddLit(buf, " \n"); + virBufferEscapeString(buf, "\n", src->vendor); + virBufferEscapeString(buf, "\n", src->product); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); return 0; } @@ -1192,16 +1200,17 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def) goto cleanup; } virBufferAsprintf(&buf, "\n", type); - virBufferEscapeString(&buf, " %s\n", def->name); + virBufferAdjustIndent(&buf, 2); + virBufferEscapeString(&buf, "%s\n", def->name); virUUIDFormat(def->uuid, uuid); - virBufferAsprintf(&buf, " %s\n", uuid); + virBufferAsprintf(&buf, "%s\n", uuid); - virBufferAsprintf(&buf, " %llu\n", + virBufferAsprintf(&buf, "%llu\n", def->capacity); - virBufferAsprintf(&buf, " %llu\n", + virBufferAsprintf(&buf, "%llu\n", def->allocation); - virBufferAsprintf(&buf, " %llu\n", + virBufferAsprintf(&buf, "%llu\n", def->available); if (virStoragePoolSourceFormat(&buf, options, &def->source) < 0) @@ -1212,24 +1221,29 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def) if (def->type != VIR_STORAGE_POOL_RBD && def->type != VIR_STORAGE_POOL_SHEEPDOG && def->type != VIR_STORAGE_POOL_GLUSTER) { - virBufferAddLit(&buf, " \n"); + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); - virBufferEscapeString(&buf, " %s\n", def->target.path); + virBufferEscapeString(&buf, "%s\n", def->target.path); - virBufferAddLit(&buf, " \n"); - virBufferAsprintf(&buf, " 0%o\n", + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); + virBufferAsprintf(&buf, "0%o\n", def->target.perms.mode); - virBufferAsprintf(&buf, " %d\n", + virBufferAsprintf(&buf, "%d\n", (int) def->target.perms.uid); - virBufferAsprintf(&buf, " %d\n", + virBufferAsprintf(&buf, "%d\n", (int) def->target.perms.gid); - virBufferEscapeString(&buf, " \n", + virBufferEscapeString(&buf, "\n", def->target.perms.label); - virBufferAddLit(&buf, " \n"); - virBufferAddLit(&buf, " \n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); } + virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); if (virBufferError(&buf)) @@ -1495,7 +1509,7 @@ virStorageVolTimestampFormat(virBufferPtr buf, const char *name, { if (ts->tv_nsec < 0) return; - virBufferAsprintf(buf, " <%s>%llu", name, + virBufferAsprintf(buf, "<%s>%llu", name, (unsigned long long) ts->tv_sec); if (ts->tv_nsec) virBufferAsprintf(buf, ".%09ld", ts->tv_nsec); @@ -1508,9 +1522,10 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options, virStorageVolTargetPtr def, const char *type) { - virBufferAsprintf(buf, " <%s>\n", type); + virBufferAsprintf(buf, "<%s>\n", type); + virBufferAdjustIndent(buf, 2); - virBufferEscapeString(buf, " %s\n", def->path); + virBufferEscapeString(buf, "%s\n", def->path); if (options->formatToString) { const char *format = (options->formatToString)(def->format); @@ -1520,63 +1535,69 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options, def->format); return -1; } - virBufferAsprintf(buf, " \n", format); + virBufferAsprintf(buf, "\n", format); } - virBufferAddLit(buf, " \n"); - virBufferAsprintf(buf, " 0%o\n", + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + virBufferAsprintf(buf, "0%o\n", def->perms.mode); - virBufferAsprintf(buf, " %u\n", + virBufferAsprintf(buf, "%u\n", (unsigned int) def->perms.uid); - virBufferAsprintf(buf, " %u\n", + virBufferAsprintf(buf, "%u\n", (unsigned int) def->perms.gid); - virBufferEscapeString(buf, " \n", + virBufferEscapeString(buf, "\n", def->perms.label); - virBufferAddLit(buf, " \n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); if (def->timestamps) { - virBufferAddLit(buf, " \n"); + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); virStorageVolTimestampFormat(buf, "atime", &def->timestamps->atime); virStorageVolTimestampFormat(buf, "mtime", &def->timestamps->mtime); virStorageVolTimestampFormat(buf, "ctime", &def->timestamps->ctime); virStorageVolTimestampFormat(buf, "btime", &def->timestamps->btime); - virBufferAddLit(buf, " \n"); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); } - if (def->encryption) { - virBufferAdjustIndent(buf, 4); - if (virStorageEncryptionFormat(buf, def->encryption) < 0) + if (def->encryption && + virStorageEncryptionFormat(buf, def->encryption) < 0) return -1; - virBufferAdjustIndent(buf, -4); - } - virBufferEscapeString(buf, " %s\n", def->compat); + virBufferEscapeString(buf, "%s\n", def->compat); if (options->featureToString && def->features) { size_t i; bool b; bool empty = virBitmapIsAllClear(def->features); - if (empty) - virBufferAddLit(buf, " \n"); - else - virBufferAddLit(buf, " \n"); + if (empty) { + virBufferAddLit(buf, "\n"); + } else { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + } for (i = 0; i < VIR_STORAGE_FILE_FEATURE_LAST; i++) { ignore_value(virBitmapGetBit(def->features, i, &b)); if (b) - virBufferAsprintf(buf, " <%s/>\n", + virBufferAsprintf(buf, "<%s/>\n", options->featureToString(i)); } - if (!empty) - virBufferAddLit(buf, " \n"); + if (!empty) { + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } } - virBufferAsprintf(buf, " \n", type); - + virBufferAdjustIndent(buf, -2); + virBufferAsprintf(buf, "\n", type); return 0; } @@ -1593,9 +1614,12 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool, virBufferAsprintf(&buf, "\n", virStorageVolTypeToString(def->type)); - virBufferEscapeString(&buf, " %s\n", def->name); - virBufferEscapeString(&buf, " %s\n", def->key); - virBufferAddLit(&buf, " \n"); + virBufferAdjustIndent(&buf, 2); + + virBufferEscapeString(&buf, "%s\n", def->name); + virBufferEscapeString(&buf, "%s\n", def->key); + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); if (def->source.nextent) { size_t i; @@ -1604,26 +1628,29 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool, if (thispath == NULL || STRNEQ(thispath, def->source.extents[i].path)) { if (thispath != NULL) - virBufferAddLit(&buf, " \n"); + virBufferAddLit(&buf, "\n"); - virBufferEscapeString(&buf, " \n", + virBufferEscapeString(&buf, "\n", def->source.extents[i].path); } - virBufferAsprintf(&buf, - " \n", + virBufferAdjustIndent(&buf, 2); + virBufferAsprintf(&buf, "\n", def->source.extents[i].start, def->source.extents[i].end); + virBufferAdjustIndent(&buf, -2); thispath = def->source.extents[i].path; } if (thispath != NULL) - virBufferAddLit(&buf, " \n"); + virBufferAddLit(&buf, "\n"); } - virBufferAddLit(&buf, " \n"); - virBufferAsprintf(&buf, " %llu\n", + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); + + virBufferAsprintf(&buf, "%llu\n", def->capacity); - virBufferAsprintf(&buf, " %llu\n", + virBufferAsprintf(&buf, "%llu\n", def->allocation); if (virStorageVolTargetDefFormat(options, &buf, @@ -1635,6 +1662,7 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool, &def->backingStore, "backingStore") < 0) goto cleanup; + virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); if (virBufferError(&buf)) diff --git a/src/conf/storage_encryption_conf.c b/src/conf/storage_encryption_conf.c index c2fafe3bff..798541c57a 100644 --- a/src/conf/storage_encryption_conf.c +++ b/src/conf/storage_encryption_conf.c @@ -1,7 +1,7 @@ /* * storage_encryption_conf.c: volume encryption information * - * Copyright (C) 2009-2011 Red Hat, Inc. + * Copyright (C) 2009-2014 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -218,7 +218,7 @@ virStorageEncryptionSecretFormat(virBufferPtr buf, } virUUIDFormat(secret->uuid, uuidstr); - virBufferAsprintf(buf, " \n", + virBufferAsprintf(buf, "\n", type, uuidstr); return 0; } @@ -237,12 +237,14 @@ virStorageEncryptionFormat(virBufferPtr buf, return -1; } virBufferAsprintf(buf, "\n", format); + virBufferAdjustIndent(buf, 2); for (i = 0; i < enc->nsecrets; i++) { if (virStorageEncryptionSecretFormat(buf, enc->secrets[i]) < 0) return -1; } + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); return 0; -- GitLab