Blob Blame History Raw
From 22bf0d340df32aac9efb1c8a0fbd8843485a13a3 Mon Sep 17 00:00:00 2001
Message-Id: <22bf0d340df32aac9efb1c8a0fbd8843485a13a3@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 26 Feb 2014 14:54:44 +0100
Subject: [PATCH] conf: Clean up virDomainDiskSourceDefFormatInternal

https://bugzilla.redhat.com/show_bug.cgi?id=1032370

Avoid if statements when used with virBufferEscapeString which
automaticaly omits the whole string. Also add some line breaks to
visualy separate the code.

(cherry picked from commit 03ad83cb5a32d62a71075716139356a4fcc9972b)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/domain_conf.c | 48 ++++++++++++++++++++----------------------------
 1 file changed, 20 insertions(+), 28 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7032b2b..bba6201 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14485,53 +14485,49 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
         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);
+            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");
@@ -14539,25 +14535,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");
 
@@ -14568,8 +14560,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");
@@ -14583,6 +14574,7 @@ virDomainDiskSourceDefFormatInternal(virBufferPtr buf,
                 virBufferAddLit(buf, "/>\n");
             }
             break;
+
         default:
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unexpected disk type %s"),
-- 
1.9.0