Avoid if statements when used with virBufferEscapeString which automaticaly omits the whole string. Also add some line breaks to visualy separate the code. --- src/conf/domain_conf.c | 50 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a6d7600..03663e4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14373,54 +14373,50 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, if (src || nhosts > 0 || srcpool || startupPolicy) { switch (type) { case VIR_DOMAIN_DISK_TYPE_FILE: - virBufferAddLit(buf," <source"); - if (src) - virBufferEscapeString(buf, " file='%s'", src); - if (startupPolicy) - virBufferEscapeString(buf, " startupPolicy='%s'", - startupPolicy); + virBufferAddLit(buf, " <source"); + virBufferEscapeString(buf, " file='%s'", src); + virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); + if (nseclabels) { virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 8); for (n = 0; n < nseclabels; n++) - virSecurityDeviceLabelDefFormat(buf, seclabels[n], - flags); + virSecurityDeviceLabelDefFormat(buf, seclabels[n], flags); virBufferAdjustIndent(buf, -8); virBufferAddLit(buf, " </source>\n"); } else { virBufferAddLit(buf, "/>\n"); } break; + case VIR_DOMAIN_DISK_TYPE_BLOCK: virBufferAddLit(buf, " <source"); virBufferEscapeString(buf, " dev='%s'", src); - if (startupPolicy) - virBufferEscapeString(buf, " startupPolicy='%s'", - startupPolicy); + virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); + if (nseclabels) { virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 8); for (n = 0; n < nseclabels; n++) - virSecurityDeviceLabelDefFormat(buf, seclabels[n], - flags); + virSecurityDeviceLabelDefFormat(buf, seclabels[n], flags); virBufferAdjustIndent(buf, -8); virBufferAddLit(buf, " </source>\n"); } else { virBufferAddLit(buf, "/>\n"); } break; + case VIR_DOMAIN_DISK_TYPE_DIR: - virBufferEscapeString(buf, " <source dir='%s'", src); - if (startupPolicy) - virBufferEscapeString(buf, " startupPolicy='%s'", - startupPolicy); + virBufferAddLit(buf, " <source"); + virBufferEscapeString(buf, " dir='%s'", src); + virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); virBufferAddLit(buf, "/>\n"); break; + case VIR_DOMAIN_DISK_TYPE_NETWORK: virBufferAsprintf(buf, " <source protocol='%s'", virDomainDiskProtocolTypeToString(protocol)); - if (src) - virBufferEscapeString(buf, " name='%s'", src); + virBufferEscapeString(buf, " name='%s'", src); if (nhosts == 0) { virBufferAddLit(buf, "/>\n"); @@ -14428,25 +14424,21 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, virBufferAddLit(buf, ">\n"); for (n = 0; n < nhosts; n++) { virBufferAddLit(buf, " <host"); - if (hosts[n].name) - virBufferEscapeString(buf, " name='%s'", hosts[n].name); - - if (hosts[n].port) - virBufferEscapeString(buf, " port='%s'", - hosts[n].port); + virBufferEscapeString(buf, " name='%s'", hosts[n].name); + virBufferEscapeString(buf, " port='%s'", hosts[n].port); if (hosts[n].transport) virBufferAsprintf(buf, " transport='%s'", virDomainDiskProtocolTransportTypeToString(hosts[n].transport)); - if (hosts[n].socket) - virBufferEscapeString(buf, " socket='%s'", hosts[n].socket); + virBufferEscapeString(buf, " socket='%s'", hosts[n].socket); virBufferAddLit(buf, "/>\n"); } virBufferAddLit(buf, " </source>\n"); } break; + case VIR_DOMAIN_DISK_TYPE_VOLUME: virBufferAddLit(buf, " <source"); @@ -14457,8 +14449,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, virBufferAsprintf(buf, " mode='%s'", virDomainDiskSourcePoolModeTypeToString(srcpool->mode)); } - if (startupPolicy) - virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); + virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy); if (nseclabels) { virBufferAddLit(buf, ">\n"); @@ -14472,6 +14463,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } break; + default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected disk type %s"), -- 1.8.4.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list