Focusing on guest disk devices. * src/conf/domain_conf.c (virDomainDiskDefFormat) (virDomainControllerDefFormat, virDomainLeaseDefFormat) (virDomainFSDefFormat): Add parameter. (virDomainDefFormatInternal): Adjust caller. * src/conf/storage_encryption_conf.c (virStorageEncryptionFormat): Simplify. --- src/conf/domain_conf.c | 126 ++++++++++++++++++++---------------- src/conf/storage_encryption_conf.c | 4 +- 2 files changed, 73 insertions(+), 57 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index be32598..a9d274b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9064,16 +9064,19 @@ virDomainLifecycleDefFormat(virBufferPtr buf, static int virDomainLeaseDefFormat(virBufferPtr buf, - virDomainLeaseDefPtr def) + virDomainLeaseDefPtr def, + int indent) { - virBufferAddLit(buf, " <lease>\n"); - virBufferEscapeString(buf, " <lockspace>%s</lockspace>\n", def->lockspace); - virBufferEscapeString(buf, " <key>%s</key>\n", def->key); - virBufferEscapeString(buf, " <target path='%s'", def->path); + virBufferIndentAddLit(buf, indent, "<lease>\n"); + virBufferIndentEscapeString(buf, indent + 2, "<lockspace>%s</lockspace>\n", + def->lockspace); + virBufferIndentEscapeString(buf, indent + 2, "<key>%s</key>\n", def->key); + virBufferIndentEscapeString(buf, indent + 2, "<target path='%s'", + def->path); if (def->offset) virBufferAsprintf(buf, " offset='%llu'", def->offset); virBufferAddLit(buf, "/>\n"); - virBufferAddLit(buf, " </lease>\n"); + virBufferIndentAddLit(buf, indent, "</lease>\n"); return 0; } @@ -9081,6 +9084,7 @@ virDomainLeaseDefFormat(virBufferPtr buf, static int virDomainDiskDefFormat(virBufferPtr buf, virDomainDiskDefPtr def, + int indent, unsigned int flags) { const char *type = virDomainDiskTypeToString(def->type); @@ -9119,7 +9123,7 @@ virDomainDiskDefFormat(virBufferPtr buf, } virBufferAsprintf(buf, - " <disk type='%s' device='%s'", + "%*s<disk type='%s' device='%s'", indent, "", type, device); if (def->snapshot && !(def->snapshot == VIR_DOMAIN_DISK_SNAPSHOT_NO && def->readonly)) @@ -9129,7 +9133,7 @@ virDomainDiskDefFormat(virBufferPtr buf, if (def->driverName || def->driverType || def->cachemode || def->ioeventfd || def->event_idx) { - virBufferAsprintf(buf, " <driver"); + virBufferIndentAddLit(buf, indent + 2, "<driver"); if (def->driverName) virBufferAsprintf(buf, " name='%s'", def->driverName); if (def->driverType) @@ -9144,42 +9148,47 @@ virDomainDiskDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " ioeventfd='%s'", ioeventfd); if (def->event_idx) virBufferAsprintf(buf, " event_idx='%s'", event_idx); - virBufferAsprintf(buf, "/>\n"); + virBufferAddLit(buf, "/>\n"); } if (def->src || def->nhosts > 0) { switch (def->type) { case VIR_DOMAIN_DISK_TYPE_FILE: - virBufferEscapeString(buf, " <source file='%s'/>\n", - def->src); + virBufferIndentEscapeString(buf, indent + 2, + "<source file='%s'/>\n", + def->src); break; case VIR_DOMAIN_DISK_TYPE_BLOCK: - virBufferEscapeString(buf, " <source dev='%s'/>\n", - def->src); + virBufferIndentEscapeString(buf, indent + 2, + "<source dev='%s'/>\n", + def->src); break; case VIR_DOMAIN_DISK_TYPE_DIR: - virBufferEscapeString(buf, " <source dir='%s'/>\n", - def->src); + virBufferIndentEscapeString(buf, indent + 2, + "<source dir='%s'/>\n", + def->src); break; case VIR_DOMAIN_DISK_TYPE_NETWORK: - virBufferAsprintf(buf, " <source protocol='%s'", + virBufferAsprintf(buf, "%*s<source protocol='%s'", + indent + 2, "", virDomainDiskProtocolTypeToString(def->protocol)); if (def->src) { virBufferEscapeString(buf, " name='%s'", def->src); } if (def->nhosts == 0) { - virBufferAsprintf(buf, "/>\n"); + virBufferAddLit(buf, "/>\n"); } else { int i; - virBufferAsprintf(buf, ">\n"); + virBufferAddLit(buf, ">\n"); for (i = 0; i < def->nhosts; i++) { - virBufferEscapeString(buf, " <host name='%s'", - def->hosts[i].name); + virBufferIndentEscapeString(buf, indent + 4, + "<host name='%s'", + def->hosts[i].name); virBufferEscapeString(buf, " port='%s'/>\n", def->hosts[i].port); } - virBufferAsprintf(buf, " </source>\n"); + virBufferIndentAddLit(buf, indent + 2, "</source>\n"); } break; default: @@ -9190,28 +9199,28 @@ virDomainDiskDefFormat(virBufferPtr buf, } } - virBufferAsprintf(buf, " <target dev='%s' bus='%s'/>\n", - def->dst, bus); + virBufferAsprintf(buf, "%*s<target dev='%s' bus='%s'/>\n", + indent + 2, "", def->dst, bus); if (def->bootIndex) - virBufferAsprintf(buf, " <boot order='%d'/>\n", def->bootIndex); + virBufferAsprintf(buf, "%*s<boot order='%d'/>\n", indent + 2, "", + def->bootIndex); if (def->readonly) - virBufferAddLit(buf, " <readonly/>\n"); + virBufferIndentAddLit(buf, indent + 2, "<readonly/>\n"); if (def->shared) - virBufferAddLit(buf, " <shareable/>\n"); + virBufferIndentAddLit(buf, indent + 2, "<shareable/>\n"); if (def->transient) - virBufferAddLit(buf, " <transient/>\n"); - if (def->serial) - virBufferEscapeString(buf, " <serial>%s</serial>\n", - def->serial); + virBufferIndentAddLit(buf, indent + 2, "<transient/>\n"); + virBufferIndentEscapeString(buf, indent + 2, "<serial>%s</serial>\n", + def->serial); if (def->encryption != NULL && - virStorageEncryptionFormat(buf, def->encryption, 6) < 0) + virStorageEncryptionFormat(buf, def->encryption, indent + 2) < 0) return -1; - if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0) + if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0) return -1; - virBufferAddLit(buf, " </disk>\n"); + virBufferIndentAddLit(buf, indent, "</disk>\n"); return 0; } @@ -9231,6 +9240,7 @@ virDomainControllerModelTypeToString(virDomainControllerDefPtr def, static int virDomainControllerDefFormat(virBufferPtr buf, virDomainControllerDefPtr def, + int indent, unsigned int flags) { const char *type = virDomainControllerTypeToString(def->type); @@ -9253,7 +9263,7 @@ virDomainControllerDefFormat(virBufferPtr buf, } virBufferAsprintf(buf, - " <controller type='%s' index='%d'", + "%*s<controller type='%s' index='%d'", indent, "", type, def->idx); if (model) { @@ -9278,9 +9288,9 @@ virDomainControllerDefFormat(virBufferPtr buf, if (virDomainDeviceInfoIsSet(&def->info, flags)) { virBufferAddLit(buf, ">\n"); - if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0) + if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0) return -1; - virBufferAddLit(buf, " </controller>\n"); + virBufferIndentAddLit(buf, indent, "</controller>\n"); } else { virBufferAddLit(buf, "/>\n"); } @@ -9291,6 +9301,7 @@ virDomainControllerDefFormat(virBufferPtr buf, static int virDomainFSDefFormat(virBufferPtr buf, virDomainFSDefPtr def, + int indent, unsigned int flags) { const char *type = virDomainFSTypeToString(def->type); @@ -9310,42 +9321,46 @@ virDomainFSDefFormat(virBufferPtr buf, virBufferAsprintf(buf, - " <filesystem type='%s' accessmode='%s'>\n", - type, accessmode); + "%*s<filesystem type='%s' accessmode='%s'>\n", + indent, "", type, accessmode); if (def->src) { switch (def->type) { case VIR_DOMAIN_FS_TYPE_MOUNT: - virBufferEscapeString(buf, " <source dir='%s'/>\n", - def->src); + virBufferIndentEscapeString(buf, indent + 2, + "<source dir='%s'/>\n", + def->src); break; case VIR_DOMAIN_FS_TYPE_BLOCK: - virBufferEscapeString(buf, " <source dev='%s'/>\n", - def->src); + virBufferIndentEscapeString(buf, indent + 2, + "<source dev='%s'/>\n", + def->src); break; case VIR_DOMAIN_FS_TYPE_FILE: - virBufferEscapeString(buf, " <source file='%s'/>\n", - def->src); + virBufferIndentEscapeString(buf, indent + 2, + "<source file='%s'/>\n", + def->src); break; case VIR_DOMAIN_FS_TYPE_TEMPLATE: - virBufferEscapeString(buf, " <source name='%s'/>\n", - def->src); + virBufferIndentEscapeString(buf, indent + 2, + "<source name='%s'/>\n", + def->src); } } - virBufferEscapeString(buf, " <target dir='%s'/>\n", - def->dst); + virBufferIndentEscapeString(buf, indent + 2, "<target dir='%s'/>\n", + def->dst); if (def->readonly) - virBufferAddLit(buf, " <readonly/>\n"); + virBufferIndentAddLit(buf, indent + 2, "<readonly/>\n"); - if (virDomainDeviceInfoFormat(buf, &def->info, 6, flags) < 0) + if (virDomainDeviceInfoFormat(buf, &def->info, indent + 2, flags) < 0) return -1; - virBufferAddLit(buf, " </filesystem>\n"); + virBufferIndentAddLit(buf, indent, "</filesystem>\n"); return 0; } @@ -10771,19 +10786,20 @@ virDomainDefFormatInternal(virDomainDefPtr def, def->emulator); for (n = 0 ; n < def->ndisks ; n++) - if (virDomainDiskDefFormat(buf, def->disks[n], flags) < 0) /* XXX indent */ + if (virDomainDiskDefFormat(buf, def->disks[n], indent, flags) < 0) goto cleanup; for (n = 0 ; n < def->ncontrollers ; n++) - if (virDomainControllerDefFormat(buf, def->controllers[n], flags) < 0) /* XXX indent */ + if (virDomainControllerDefFormat(buf, def->controllers[n], indent, + flags) < 0) goto cleanup; for (n = 0 ; n < def->nleases ; n++) - if (virDomainLeaseDefFormat(buf, def->leases[n]) < 0) /* XXX indent */ + if (virDomainLeaseDefFormat(buf, def->leases[n], indent) < 0) goto cleanup; for (n = 0 ; n < def->nfss ; n++) - if (virDomainFSDefFormat(buf, def->fss[n], flags) < 0) /* XXX indent */ + if (virDomainFSDefFormat(buf, def->fss[n], indent, flags) < 0) goto cleanup; diff --git a/src/conf/storage_encryption_conf.c b/src/conf/storage_encryption_conf.c index 73e16ed..7d77893 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-2010 Red Hat, Inc. + * Copyright (C) 2009-2011 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 @@ -253,7 +253,7 @@ virStorageEncryptionFormat(virBufferPtr buf, return -1; } - virBufferAsprintf(buf, "%*s</encryption>\n", indent, ""); + virBufferIndentAddLit(buf, indent, "</encryption>\n"); return 0; } -- 1.7.4.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list