mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
conf: eliminate hardcoded indent in volume/pool xml
Again completely mechanical, but a lot of lines.
This commit is contained in:
parent
f728155f69
commit
5f84543772
@ -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, " <source>\n");
|
||||
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'",
|
||||
virBufferEscapeString(buf, "<host name='%s'",
|
||||
src->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, " <device path='%s'>\n",
|
||||
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",
|
||||
virBufferAsprintf(buf, "<freeExtent start='%llu' end='%llu'/>\n",
|
||||
src->devices[i].freeExtents[j].start,
|
||||
src->devices[i].freeExtents[j].end);
|
||||
}
|
||||
virBufferAddLit(buf, " </device>\n");
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</device>\n");
|
||||
} else {
|
||||
virBufferEscapeString(buf, " <device path='%s'/>\n",
|
||||
virBufferEscapeString(buf, "<device path='%s'/>\n",
|
||||
src->devices[i].path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (options->flags & VIR_STORAGE_POOL_SOURCE_DIR)
|
||||
virBufferEscapeString(buf, " <dir path='%s'/>\n", src->dir);
|
||||
virBufferEscapeString(buf, "<dir path='%s'/>\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='%s'",
|
||||
virBufferAsprintf(buf, "<adapter type='%s'",
|
||||
virStoragePoolSourceAdapterTypeTypeToString(src->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, " <name>%s</name>\n", src->name);
|
||||
virBufferEscapeString(buf, "<name>%s</name>\n", src->name);
|
||||
|
||||
if ((options->flags & VIR_STORAGE_POOL_SOURCE_INITIATOR_IQN) &&
|
||||
src->initiator.iqn) {
|
||||
virBufferAddLit(buf, " <initiator>\n");
|
||||
virBufferEscapeString(buf, " <iqn name='%s'/>\n",
|
||||
virBufferAddLit(buf, "<initiator>\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
virBufferEscapeString(buf, "<iqn name='%s'/>\n",
|
||||
src->initiator.iqn);
|
||||
virBufferAddLit(buf, " </initiator>\n");
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</initiator>\n");
|
||||
}
|
||||
|
||||
if (options->formatToString) {
|
||||
@ -1138,19 +1144,20 @@ virStoragePoolSourceFormat(virBufferPtr buf,
|
||||
src->format);
|
||||
return -1;
|
||||
}
|
||||
virBufferAsprintf(buf, " <format type='%s'/>\n", format);
|
||||
virBufferAsprintf(buf, "<format type='%s'/>\n", format);
|
||||
}
|
||||
|
||||
if (src->authType == VIR_STORAGE_POOL_AUTH_CHAP ||
|
||||
src->authType == VIR_STORAGE_POOL_AUTH_CEPHX) {
|
||||
virBufferAsprintf(buf, " <auth type='%s' ",
|
||||
virBufferAsprintf(buf, "<auth type='%s' ",
|
||||
virStoragePoolAuthTypeTypeToString(src->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, " <secret");
|
||||
virBufferAddLit(buf, "<secret");
|
||||
if (src->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, " </auth>\n");
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</auth>\n");
|
||||
}
|
||||
|
||||
virBufferEscapeString(buf, " <vendor name='%s'/>\n", src->vendor);
|
||||
virBufferEscapeString(buf, " <product name='%s'/>\n", src->product);
|
||||
|
||||
virBufferAddLit(buf, " </source>\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,16 +1200,17 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def)
|
||||
goto cleanup;
|
||||
}
|
||||
virBufferAsprintf(&buf, "<pool type='%s'>\n", type);
|
||||
virBufferEscapeString(&buf, " <name>%s</name>\n", def->name);
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
virBufferEscapeString(&buf, "<name>%s</name>\n", def->name);
|
||||
|
||||
virUUIDFormat(def->uuid, uuid);
|
||||
virBufferAsprintf(&buf, " <uuid>%s</uuid>\n", uuid);
|
||||
virBufferAsprintf(&buf, "<uuid>%s</uuid>\n", uuid);
|
||||
|
||||
virBufferAsprintf(&buf, " <capacity unit='bytes'>%llu</capacity>\n",
|
||||
virBufferAsprintf(&buf, "<capacity unit='bytes'>%llu</capacity>\n",
|
||||
def->capacity);
|
||||
virBufferAsprintf(&buf, " <allocation unit='bytes'>%llu</allocation>\n",
|
||||
virBufferAsprintf(&buf, "<allocation unit='bytes'>%llu</allocation>\n",
|
||||
def->allocation);
|
||||
virBufferAsprintf(&buf, " <available unit='bytes'>%llu</available>\n",
|
||||
virBufferAsprintf(&buf, "<available unit='bytes'>%llu</available>\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, " <target>\n");
|
||||
virBufferAddLit(&buf, "<target>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
|
||||
virBufferEscapeString(&buf, " <path>%s</path>\n", def->target.path);
|
||||
virBufferEscapeString(&buf, "<path>%s</path>\n", def->target.path);
|
||||
|
||||
virBufferAddLit(&buf, " <permissions>\n");
|
||||
virBufferAsprintf(&buf, " <mode>0%o</mode>\n",
|
||||
virBufferAddLit(&buf, "<permissions>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
virBufferAsprintf(&buf, "<mode>0%o</mode>\n",
|
||||
def->target.perms.mode);
|
||||
virBufferAsprintf(&buf, " <owner>%d</owner>\n",
|
||||
virBufferAsprintf(&buf, "<owner>%d</owner>\n",
|
||||
(int) def->target.perms.uid);
|
||||
virBufferAsprintf(&buf, " <group>%d</group>\n",
|
||||
virBufferAsprintf(&buf, "<group>%d</group>\n",
|
||||
(int) def->target.perms.gid);
|
||||
|
||||
virBufferEscapeString(&buf, " <label>%s</label>\n",
|
||||
virBufferEscapeString(&buf, "<label>%s</label>\n",
|
||||
def->target.perms.label);
|
||||
|
||||
virBufferAddLit(&buf, " </permissions>\n");
|
||||
virBufferAddLit(&buf, " </target>\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</permissions>\n");
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</target>\n");
|
||||
}
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</pool>\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, " <path>%s</path>\n", def->path);
|
||||
virBufferEscapeString(buf, "<path>%s</path>\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, " <format type='%s'/>\n", format);
|
||||
virBufferAsprintf(buf, "<format type='%s'/>\n", format);
|
||||
}
|
||||
|
||||
virBufferAddLit(buf, " <permissions>\n");
|
||||
virBufferAsprintf(buf, " <mode>0%o</mode>\n",
|
||||
virBufferAddLit(buf, "<permissions>\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
|
||||
virBufferAsprintf(buf, "<mode>0%o</mode>\n",
|
||||
def->perms.mode);
|
||||
virBufferAsprintf(buf, " <owner>%u</owner>\n",
|
||||
virBufferAsprintf(buf, "<owner>%u</owner>\n",
|
||||
(unsigned int) def->perms.uid);
|
||||
virBufferAsprintf(buf, " <group>%u</group>\n",
|
||||
virBufferAsprintf(buf, "<group>%u</group>\n",
|
||||
(unsigned int) def->perms.gid);
|
||||
|
||||
|
||||
virBufferEscapeString(buf, " <label>%s</label>\n",
|
||||
virBufferEscapeString(buf, "<label>%s</label>\n",
|
||||
def->perms.label);
|
||||
|
||||
virBufferAddLit(buf, " </permissions>\n");
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</permissions>\n");
|
||||
|
||||
if (def->timestamps) {
|
||||
virBufferAddLit(buf, " <timestamps>\n");
|
||||
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);
|
||||
virBufferAddLit(buf, " </timestamps>\n");
|
||||
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);
|
||||
virBufferEscapeString(buf, "<compat>%s</compat>\n", def->compat);
|
||||
|
||||
if (options->featureToString && def->features) {
|
||||
size_t i;
|
||||
bool b;
|
||||
bool empty = virBitmapIsAllClear(def->features);
|
||||
|
||||
if (empty)
|
||||
virBufferAddLit(buf, " <features/>\n");
|
||||
else
|
||||
virBufferAddLit(buf, " <features>\n");
|
||||
if (empty) {
|
||||
virBufferAddLit(buf, "<features/>\n");
|
||||
} 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));
|
||||
if (b)
|
||||
virBufferAsprintf(buf, " <%s/>\n",
|
||||
virBufferAsprintf(buf, "<%s/>\n",
|
||||
options->featureToString(i));
|
||||
}
|
||||
if (!empty)
|
||||
virBufferAddLit(buf, " </features>\n");
|
||||
if (!empty) {
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</features>\n");
|
||||
}
|
||||
}
|
||||
|
||||
virBufferAsprintf(buf, " </%s>\n", type);
|
||||
|
||||
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));
|
||||
virBufferEscapeString(&buf, " <name>%s</name>\n", def->name);
|
||||
virBufferEscapeString(&buf, " <key>%s</key>\n", def->key);
|
||||
virBufferAddLit(&buf, " <source>\n");
|
||||
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;
|
||||
@ -1604,26 +1628,29 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
|
||||
if (thispath == NULL ||
|
||||
STRNEQ(thispath, def->source.extents[i].path)) {
|
||||
if (thispath != NULL)
|
||||
virBufferAddLit(&buf, " </device>\n");
|
||||
virBufferAddLit(&buf, "</device>\n");
|
||||
|
||||
virBufferEscapeString(&buf, " <device path='%s'>\n",
|
||||
virBufferEscapeString(&buf, "<device path='%s'>\n",
|
||||
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");
|
||||
virBufferAddLit(&buf, "</device>\n");
|
||||
}
|
||||
virBufferAddLit(&buf, " </source>\n");
|
||||
|
||||
virBufferAsprintf(&buf, " <capacity unit='bytes'>%llu</capacity>\n",
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</source>\n");
|
||||
|
||||
virBufferAsprintf(&buf, "<capacity unit='bytes'>%llu</capacity>\n",
|
||||
def->capacity);
|
||||
virBufferAsprintf(&buf, " <allocation unit='bytes'>%llu</allocation>\n",
|
||||
virBufferAsprintf(&buf, "<allocation unit='bytes'>%llu</allocation>\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, "</volume>\n");
|
||||
|
||||
if (virBufferError(&buf))
|
||||
|
@ -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, " <secret type='%s' uuid='%s'/>\n",
|
||||
virBufferAsprintf(buf, "<secret type='%s' uuid='%s'/>\n",
|
||||
type, uuidstr);
|
||||
return 0;
|
||||
}
|
||||
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user