提交 03ad83cb 编写于 作者: P Peter Krempa

conf: Clean up virDomainDiskSourceDefFormatInternal

Avoid if statements when used with virBufferEscapeString which
automaticaly omits the whole string. Also add some line breaks to
visualy separate the code.
上级 d6b4c2cc
...@@ -14375,53 +14375,49 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, ...@@ -14375,53 +14375,49 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
switch (type) { switch (type) {
case VIR_DOMAIN_DISK_TYPE_FILE: case VIR_DOMAIN_DISK_TYPE_FILE:
virBufferAddLit(buf, " <source"); virBufferAddLit(buf, " <source");
if (src) virBufferEscapeString(buf, " file='%s'", src);
virBufferEscapeString(buf, " file='%s'", src); virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
if (startupPolicy)
virBufferEscapeString(buf, " startupPolicy='%s'",
startupPolicy);
if (nseclabels) { if (nseclabels) {
virBufferAddLit(buf, ">\n"); virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 8); virBufferAdjustIndent(buf, 8);
for (n = 0; n < nseclabels; n++) for (n = 0; n < nseclabels; n++)
virSecurityDeviceLabelDefFormat(buf, seclabels[n], virSecurityDeviceLabelDefFormat(buf, seclabels[n], flags);
flags);
virBufferAdjustIndent(buf, -8); virBufferAdjustIndent(buf, -8);
virBufferAddLit(buf, " </source>\n"); virBufferAddLit(buf, " </source>\n");
} else { } else {
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
} }
break; break;
case VIR_DOMAIN_DISK_TYPE_BLOCK: case VIR_DOMAIN_DISK_TYPE_BLOCK:
virBufferAddLit(buf, " <source"); virBufferAddLit(buf, " <source");
virBufferEscapeString(buf, " dev='%s'", src); virBufferEscapeString(buf, " dev='%s'", src);
if (startupPolicy) virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
virBufferEscapeString(buf, " startupPolicy='%s'",
startupPolicy);
if (nseclabels) { if (nseclabels) {
virBufferAddLit(buf, ">\n"); virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 8); virBufferAdjustIndent(buf, 8);
for (n = 0; n < nseclabels; n++) for (n = 0; n < nseclabels; n++)
virSecurityDeviceLabelDefFormat(buf, seclabels[n], virSecurityDeviceLabelDefFormat(buf, seclabels[n], flags);
flags);
virBufferAdjustIndent(buf, -8); virBufferAdjustIndent(buf, -8);
virBufferAddLit(buf, " </source>\n"); virBufferAddLit(buf, " </source>\n");
} else { } else {
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
} }
break; break;
case VIR_DOMAIN_DISK_TYPE_DIR: case VIR_DOMAIN_DISK_TYPE_DIR:
virBufferEscapeString(buf, " <source dir='%s'", src); virBufferAddLit(buf, " <source");
if (startupPolicy) virBufferEscapeString(buf, " dir='%s'", src);
virBufferEscapeString(buf, " startupPolicy='%s'", virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
startupPolicy);
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
break; break;
case VIR_DOMAIN_DISK_TYPE_NETWORK: case VIR_DOMAIN_DISK_TYPE_NETWORK:
virBufferAsprintf(buf, " <source protocol='%s'", virBufferAsprintf(buf, " <source protocol='%s'",
virDomainDiskProtocolTypeToString(protocol)); virDomainDiskProtocolTypeToString(protocol));
if (src) virBufferEscapeString(buf, " name='%s'", src);
virBufferEscapeString(buf, " name='%s'", src);
if (nhosts == 0) { if (nhosts == 0) {
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
...@@ -14429,25 +14425,21 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, ...@@ -14429,25 +14425,21 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
virBufferAddLit(buf, ">\n"); virBufferAddLit(buf, ">\n");
for (n = 0; n < nhosts; n++) { for (n = 0; n < nhosts; n++) {
virBufferAddLit(buf, " <host"); virBufferAddLit(buf, " <host");
if (hosts[n].name) virBufferEscapeString(buf, " name='%s'", hosts[n].name);
virBufferEscapeString(buf, " name='%s'", hosts[n].name); virBufferEscapeString(buf, " port='%s'", hosts[n].port);
if (hosts[n].port)
virBufferEscapeString(buf, " port='%s'",
hosts[n].port);
if (hosts[n].transport) if (hosts[n].transport)
virBufferAsprintf(buf, " transport='%s'", virBufferAsprintf(buf, " transport='%s'",
virDomainDiskProtocolTransportTypeToString(hosts[n].transport)); 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, "/>\n");
} }
virBufferAddLit(buf, " </source>\n"); virBufferAddLit(buf, " </source>\n");
} }
break; break;
case VIR_DOMAIN_DISK_TYPE_VOLUME: case VIR_DOMAIN_DISK_TYPE_VOLUME:
virBufferAddLit(buf, " <source"); virBufferAddLit(buf, " <source");
...@@ -14458,8 +14450,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, ...@@ -14458,8 +14450,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
virBufferAsprintf(buf, " mode='%s'", virBufferAsprintf(buf, " mode='%s'",
virDomainDiskSourcePoolModeTypeToString(srcpool->mode)); virDomainDiskSourcePoolModeTypeToString(srcpool->mode));
} }
if (startupPolicy) virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
virBufferEscapeString(buf, " startupPolicy='%s'", startupPolicy);
if (nseclabels) { if (nseclabels) {
virBufferAddLit(buf, ">\n"); virBufferAddLit(buf, ">\n");
...@@ -14473,6 +14464,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf, ...@@ -14473,6 +14464,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
} }
break; break;
default: default:
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected disk type %s"), _("unexpected disk type %s"),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册