conf: eliminate hardcoded indent in volume/pool xml

Again completely mechanical, but a lot of lines.
This commit is contained in:
Laine Stump 2014-03-06 16:57:47 +02:00
parent f728155f69
commit 5f84543772
2 changed files with 105 additions and 75 deletions

View File

@ -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
@ -1069,6 +1069,8 @@ virStoragePoolSourceFormat(virBufferPtr buf,
char uuid[VIR_UUID_STRING_BUFLEN];
virBufferAddLit(buf, "<source>\n");
virBufferAdjustIndent(buf, 2);
if ((options->flags & VIR_STORAGE_POOL_SOURCE_HOST) && src->nhost) {
for (i = 0; i < src->nhost; i++) {
virBufferEscapeString(buf, "<host name='%s'",
@ -1085,11 +1087,13 @@ virStoragePoolSourceFormat(virBufferPtr buf,
if (src->devices[i].nfreeExtent) {
virBufferEscapeString(buf, "<device path='%s'>\n",
src->devices[i].path);
virBufferAdjustIndent(buf, 2);
for (j = 0; j < src->devices[i].nfreeExtent; j++) {
virBufferAsprintf(buf, "<freeExtent start='%llu' end='%llu'/>\n",
src->devices[i].freeExtents[j].start,
src->devices[i].freeExtents[j].end);
}
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</device>\n");
} else {
virBufferEscapeString(buf, "<device path='%s'/>\n",
@ -1125,8 +1129,10 @@ virStoragePoolSourceFormat(virBufferPtr buf,
if ((options->flags & VIR_STORAGE_POOL_SOURCE_INITIATOR_IQN) &&
src->initiator.iqn) {
virBufferAddLit(buf, "<initiator>\n");
virBufferAdjustIndent(buf, 2);
virBufferEscapeString(buf, "<iqn name='%s'/>\n",
src->initiator.iqn);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</initiator>\n");
}
@ -1149,6 +1155,7 @@ virStoragePoolSourceFormat(virBufferPtr buf,
(src->authType == VIR_STORAGE_POOL_AUTH_CHAP ?
src->auth.chap.username :
src->auth.cephx.username));
virBufferAdjustIndent(buf, 2);
virBufferAddLit(buf, "<secret");
if (src->auth.cephx.secret.uuidUsable) {
@ -1161,14 +1168,15 @@ virStoragePoolSourceFormat(virBufferPtr buf,
}
virBufferAddLit(buf, "/>\n");
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</auth>\n");
}
virBufferEscapeString(buf, "<vendor name='%s'/>\n", src->vendor);
virBufferEscapeString(buf, "<product name='%s'/>\n", src->product);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</source>\n");
return 0;
}
@ -1192,6 +1200,7 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def)
goto cleanup;
}
virBufferAsprintf(&buf, "<pool type='%s'>\n", type);
virBufferAdjustIndent(&buf, 2);
virBufferEscapeString(&buf, "<name>%s</name>\n", def->name);
virUUIDFormat(def->uuid, uuid);
@ -1213,10 +1222,12 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def)
def->type != VIR_STORAGE_POOL_SHEEPDOG &&
def->type != VIR_STORAGE_POOL_GLUSTER) {
virBufferAddLit(&buf, "<target>\n");
virBufferAdjustIndent(&buf, 2);
virBufferEscapeString(&buf, "<path>%s</path>\n", def->target.path);
virBufferAddLit(&buf, "<permissions>\n");
virBufferAdjustIndent(&buf, 2);
virBufferAsprintf(&buf, "<mode>0%o</mode>\n",
def->target.perms.mode);
virBufferAsprintf(&buf, "<owner>%d</owner>\n",
@ -1227,9 +1238,12 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def)
virBufferEscapeString(&buf, "<label>%s</label>\n",
def->target.perms.label);
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</permissions>\n");
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</target>\n");
}
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</pool>\n");
if (virBufferError(&buf))
@ -1509,6 +1523,7 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
const char *type)
{
virBufferAsprintf(buf, "<%s>\n", type);
virBufferAdjustIndent(buf, 2);
virBufferEscapeString(buf, "<path>%s</path>\n", def->path);
@ -1524,6 +1539,8 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
}
virBufferAddLit(buf, "<permissions>\n");
virBufferAdjustIndent(buf, 2);
virBufferAsprintf(buf, "<mode>0%o</mode>\n",
def->perms.mode);
virBufferAsprintf(buf, "<owner>%u</owner>\n",
@ -1535,23 +1552,23 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
virBufferEscapeString(buf, "<label>%s</label>\n",
def->perms.label);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</permissions>\n");
if (def->timestamps) {
virBufferAddLit(buf, "<timestamps>\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);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</timestamps>\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, "<compat>%s</compat>\n", def->compat);
@ -1560,10 +1577,12 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
bool b;
bool empty = virBitmapIsAllClear(def->features);
if (empty)
if (empty) {
virBufferAddLit(buf, "<features/>\n");
else
} else {
virBufferAddLit(buf, "<features>\n");
virBufferAdjustIndent(buf, 2);
}
for (i = 0; i < VIR_STORAGE_FILE_FEATURE_LAST; i++) {
ignore_value(virBitmapGetBit(def->features, i, &b));
@ -1571,12 +1590,14 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr options,
virBufferAsprintf(buf, "<%s/>\n",
options->featureToString(i));
}
if (!empty)
if (!empty) {
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</features>\n");
}
}
virBufferAdjustIndent(buf, -2);
virBufferAsprintf(buf, "</%s>\n", type);
return 0;
}
@ -1593,9 +1614,12 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
virBufferAsprintf(&buf, "<volume type='%s'>\n",
virStorageVolTypeToString(def->type));
virBufferAdjustIndent(&buf, 2);
virBufferEscapeString(&buf, "<name>%s</name>\n", def->name);
virBufferEscapeString(&buf, "<key>%s</key>\n", def->key);
virBufferAddLit(&buf, "<source>\n");
virBufferAdjustIndent(&buf, 2);
if (def->source.nextent) {
size_t i;
@ -1610,15 +1634,18 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
def->source.extents[i].path);
}
virBufferAsprintf(&buf,
" <extent start='%llu' end='%llu'/>\n",
virBufferAdjustIndent(&buf, 2);
virBufferAsprintf(&buf, "<extent start='%llu' end='%llu'/>\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, "</device>\n");
}
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</source>\n");
virBufferAsprintf(&buf, "<capacity unit='bytes'>%llu</capacity>\n",
@ -1635,6 +1662,7 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
&def->backingStore, "backingStore") < 0)
goto cleanup;
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</volume>\n");
if (virBufferError(&buf))

View File

@ -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
@ -237,12 +237,14 @@ virStorageEncryptionFormat(virBufferPtr buf,
return -1;
}
virBufferAsprintf(buf, "<encryption format='%s'>\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, "</encryption>\n");
return 0;